UNPKG

@n8n/n8n-nodes-langchain

Version:

![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png)

130 lines 5.13 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepareAdditionalResponsesParams = exports.formatBuiltInTools = void 0; const get_1 = __importDefault(require("lodash/get")); const isObject_1 = __importDefault(require("lodash/isObject")); const n8n_workflow_1 = require("n8n-workflow"); const removeEmptyProperties = (rest) => { return Object.keys(rest) .filter((k) => rest[k] !== '' && rest[k] !== undefined && !((0, isObject_1.default)(rest[k]) && (0, n8n_workflow_1.isObjectEmpty)(rest[k]))) .reduce((a, k) => ({ ...a, [k]: rest[k] }), {}); }; const toArray = (str) => str .split(',') .map((e) => e.trim()) .filter(Boolean); const formatBuiltInTools = (builtInTools) => { const tools = []; if (builtInTools) { const webSearchOptions = (0, get_1.default)(builtInTools, 'webSearch'); if (webSearchOptions) { let allowedDomains; const allowedDomainsRaw = (0, get_1.default)(webSearchOptions, 'allowedDomains', ''); if (allowedDomainsRaw) { allowedDomains = toArray(allowedDomainsRaw); } let userLocation; if (webSearchOptions.country || webSearchOptions.city || webSearchOptions.region) { userLocation = { type: 'approximate', country: webSearchOptions.country, city: webSearchOptions.city, region: webSearchOptions.region, }; } tools.push({ type: 'web_search', search_context_size: (0, get_1.default)(webSearchOptions, 'searchContextSize', 'medium'), user_location: userLocation, ...(allowedDomains && { filters: { allowed_domains: allowedDomains } }), }); } if (builtInTools.codeInterpreter) { tools.push({ type: 'code_interpreter', container: { type: 'auto', }, }); } if (builtInTools.fileSearch) { const vectorStoreIds = (0, get_1.default)(builtInTools.fileSearch, 'vectorStoreIds', '[]'); const filters = (0, get_1.default)(builtInTools.fileSearch, 'filters', '{}'); tools.push({ type: 'file_search', vector_store_ids: (0, n8n_workflow_1.jsonParse)(vectorStoreIds, { errorMessage: 'Failed to parse vector store IDs', }), filters: filters ? (0, n8n_workflow_1.jsonParse)(filters, { errorMessage: 'Failed to parse filters' }) : undefined, max_num_results: (0, get_1.default)(builtInTools.fileSearch, 'maxResults'), }); } } return tools; }; exports.formatBuiltInTools = formatBuiltInTools; const prepareAdditionalResponsesParams = (options) => { const body = { prompt_cache_key: options.promptCacheKey, safety_identifier: options.safetyIdentifier, service_tier: options.serviceTier, top_logprobs: options.topLogprobs, }; if (options.conversationId) { body.conversation = options.conversationId; } if (options.metadata) { body.metadata = (0, n8n_workflow_1.jsonParse)(options.metadata, { errorMessage: 'Failed to parse metadata', }); } if (options.promptConfig) { const prompt = (0, get_1.default)(options, 'promptConfig.promptOptions', {}); body.prompt = removeEmptyProperties({ id: prompt.promptId, version: prompt.version, ...(prompt.variables && { variables: (0, n8n_workflow_1.jsonParse)(prompt.variables, { errorMessage: 'Failed to parse prompt variables', }), }), }); } if (options.textFormat) { const textOptions = (0, get_1.default)(options, 'textFormat.textOptions', {}); const textConfig = { verbosity: textOptions.verbosity, }; if (textOptions.type === 'json_schema') { textConfig.format = { type: textOptions.type, name: textOptions.name, schema: (0, n8n_workflow_1.jsonParse)(textOptions.schema, { errorMessage: 'Failed to parse schema', }), }; } else { textConfig.format = { type: textOptions.type, }; } if (textConfig.format) { textConfig.format = removeEmptyProperties(textConfig.format); } body.text = textConfig; } if (options.reasoningEffort) { body.reasoning = { effort: options.reasoningEffort, }; } return body; }; exports.prepareAdditionalResponsesParams = prepareAdditionalResponsesParams; //# sourceMappingURL=common.js.map