@n8n/n8n-nodes-langchain 1.93.0 → 1.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/credentials/AzureEntraCognitiveServicesOAuth2Api.credentials.js +4 -21
- package/dist/credentials/AzureEntraCognitiveServicesOAuth2Api.credentials.js.map +1 -1
- package/dist/nodes/agents/Agent/Agent.node.js +19 -394
- package/dist/nodes/agents/Agent/Agent.node.js.map +1 -1
- package/dist/nodes/agents/Agent/V1/AgentV1.node.js +427 -0
- package/dist/nodes/agents/Agent/V1/AgentV1.node.js.map +1 -0
- package/dist/nodes/agents/Agent/V2/AgentV2.node.js +162 -0
- package/dist/nodes/agents/Agent/V2/AgentV2.node.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/{description.js → V1/description.js} +2 -34
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/description.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js +119 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/description.js +40 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/description.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js +139 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/{execute.js → common.js} +7 -97
- package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/options.js +62 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/options.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js +69 -51
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js.map +1 -1
- package/dist/nodes/chains/ChainLLM/methods/chainExecutor.js +8 -0
- package/dist/nodes/chains/ChainLLM/methods/chainExecutor.js.map +1 -1
- package/dist/nodes/chains/ChainLLM/methods/config.js +5 -0
- package/dist/nodes/chains/ChainLLM/methods/config.js.map +1 -1
- package/dist/nodes/chains/ChainLLM/methods/processItem.js +66 -0
- package/dist/nodes/chains/ChainLLM/methods/processItem.js.map +1 -0
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js +71 -95
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js.map +1 -1
- package/dist/nodes/chains/ChainRetrievalQA/constants.js +49 -0
- package/dist/nodes/chains/ChainRetrievalQA/constants.js.map +1 -0
- package/dist/nodes/chains/ChainRetrievalQA/processItem.js +91 -0
- package/dist/nodes/chains/ChainRetrievalQA/processItem.js.map +1 -0
- package/dist/nodes/chains/ChainSummarization/ChainSummarization.node.js +3 -2
- package/dist/nodes/chains/ChainSummarization/ChainSummarization.node.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.js +55 -78
- package/dist/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/V2/processItem.js +95 -0
- package/dist/nodes/chains/ChainSummarization/V2/processItem.js.map +1 -0
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js +56 -33
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js.map +1 -1
- package/dist/nodes/chains/InformationExtractor/constants.js +31 -0
- package/dist/nodes/chains/InformationExtractor/constants.js.map +1 -0
- package/dist/nodes/chains/InformationExtractor/processItem.js +50 -0
- package/dist/nodes/chains/InformationExtractor/processItem.js.map +1 -0
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js +198 -71
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js.map +1 -1
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js +83 -54
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js.map +1 -1
- package/dist/nodes/chains/TextClassifier/constants.js +29 -0
- package/dist/nodes/chains/TextClassifier/constants.js.map +1 -0
- package/dist/nodes/chains/TextClassifier/processItem.js +65 -0
- package/dist/nodes/chains/TextClassifier/processItem.js.map +1 -0
- package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js +5 -1
- package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js.map +1 -1
- package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js +4 -1
- package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js.map +1 -1
- package/dist/nodes/llms/LMChatOpenAi/methods/loadModels.js +6 -1
- package/dist/nodes/llms/LMChatOpenAi/methods/loadModels.js.map +1 -1
- package/dist/nodes/llms/LMOpenAi/LmOpenAi.node.js +4 -1
- package/dist/nodes/llms/LMOpenAi/LmOpenAi.node.js.map +1 -1
- package/dist/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.js +4 -0
- package/dist/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.js.map +1 -1
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js +4 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js.map +1 -1
- package/dist/nodes/llms/LmChatAzureOpenAi/credentials/N8nOAuth2TokenCredential.js +16 -2
- package/dist/nodes/llms/LmChatAzureOpenAi/credentials/N8nOAuth2TokenCredential.js.map +1 -1
- package/dist/nodes/llms/LmChatDeepSeek/LmChatDeepSeek.node.js +3 -1
- package/dist/nodes/llms/LmChatDeepSeek/LmChatDeepSeek.node.js.map +1 -1
- package/dist/nodes/llms/LmChatGroq/LmChatGroq.node.js +2 -0
- package/dist/nodes/llms/LmChatGroq/LmChatGroq.node.js.map +1 -1
- package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js +3 -1
- package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js.map +1 -1
- package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js +3 -1
- package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js.map +1 -1
- package/dist/nodes/mcp/McpTrigger/McpTrigger.node.js +2 -2
- package/dist/nodes/mcp/McpTrigger/McpTrigger.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.js +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +2 -1
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/actions/image/generate.operation.js +6 -1
- package/dist/nodes/vendors/OpenAi/actions/image/generate.operation.js.map +1 -1
- package/dist/types/credentials.json +1 -1
- package/dist/types/nodes.json +11 -10
- package/dist/utils/httpProxyAgent.js +33 -0
- package/dist/utils/httpProxyAgent.js.map +1 -0
- package/dist/utils/sharedFields.js +29 -0
- package/dist/utils/sharedFields.js.map +1 -1
- package/package.json +7 -6
- package/dist/nodes/agents/Agent/agents/ToolsAgent/description.js.map +0 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/execute.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport {\n\tChatPromptTemplate,\n\tSystemMessagePromptTemplate,\n\tHumanMessagePromptTemplate,\n\tPromptTemplate,\n} from '@langchain/core/prompts';\nimport type { BaseRetriever } from '@langchain/core/retrievers';\nimport { createStuffDocumentsChain } from 'langchain/chains/combine_documents';\nimport { createRetrievalChain } from 'langchain/chains/retrieval';\nimport { NodeConnectionTypes, NodeOperationError, parseErrorMetadata } from 'n8n-workflow';\nimport {\n\ttype INodeProperties,\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n} from 'n8n-workflow';\n\nimport { promptTypeOptions, textFromPreviousNode } from '@utils/descriptions';\nimport { getPromptInputByType, isChatInstance } from '@utils/helpers';\nimport { getTemplateNoticeField } from '@utils/sharedFields';\nimport { getTracingConfig } from '@utils/tracing';\n\nconst SYSTEM_PROMPT_TEMPLATE = `You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question.\nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\n----------------\nContext: {context}`;\n\n// Due to the refactoring in version 1.5, the variable name {question} needed to be changed to {input} in the prompt template.\nconst LEGACY_INPUT_TEMPLATE_KEY = 'question';\nconst INPUT_TEMPLATE_KEY = 'input';\n\nconst systemPromptOption: INodeProperties = {\n\tdisplayName: 'System Prompt Template',\n\tname: 'systemPromptTemplate',\n\ttype: 'string',\n\tdefault: SYSTEM_PROMPT_TEMPLATE,\n\ttypeOptions: {\n\t\trows: 6,\n\t},\n};\n\nexport class ChainRetrievalQa implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Question and Answer Chain',\n\t\tname: 'chainRetrievalQa',\n\t\ticon: 'fa:link',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5],\n\t\tdescription: 'Answer questions about retrieved documents',\n\t\tdefaults: {\n\t\t\tname: 'Question and Answer Chain',\n\t\t\tcolor: '#909298',\n\t\t},\n\t\tcodex: {\n\t\t\talias: ['LangChain'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainretrievalqa/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [\n\t\t\tNodeConnectionTypes.Main,\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Retriever',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiRetriever,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [],\n\t\tproperties: [\n\t\t\tgetTemplateNoticeField(1960),\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chat_input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chatInput }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.2],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...promptTypeOptions,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\thide: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...textFromPreviousNode,\n\t\t\t\tdisplayOptions: { show: { promptType: ['auto'], '@version': [{ _cnd: { gte: 1.4 } }] } },\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Prompt (User Message)',\n\t\t\t\tname: 'text',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. Hello, how can you help me?',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tpromptType: ['define'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${LEGACY_INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { lt: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Retrieval QA Chain');\n\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\t// Run for each item\n\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\ttry {\n\t\t\t\tconst model = (await this.getInputConnectionData(\n\t\t\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t\t\t0,\n\t\t\t\t)) as BaseLanguageModel;\n\n\t\t\t\tconst retriever = (await this.getInputConnectionData(\n\t\t\t\t\tNodeConnectionTypes.AiRetriever,\n\t\t\t\t\t0,\n\t\t\t\t)) as BaseRetriever;\n\n\t\t\t\tlet query;\n\n\t\t\t\tif (this.getNode().typeVersion <= 1.2) {\n\t\t\t\t\tquery = this.getNodeParameter('query', itemIndex) as string;\n\t\t\t\t} else {\n\t\t\t\t\tquery = getPromptInputByType({\n\t\t\t\t\t\tctx: this,\n\t\t\t\t\t\ti: itemIndex,\n\t\t\t\t\t\tinputKey: 'text',\n\t\t\t\t\t\tpromptTypeKey: 'promptType',\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (query === undefined) {\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), 'The ‘query‘ parameter is empty.');\n\t\t\t\t}\n\n\t\t\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\t\t\tsystemPromptTemplate?: string;\n\t\t\t\t};\n\n\t\t\t\tlet templateText = options.systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE;\n\n\t\t\t\t// Replace legacy input template key for versions 1.4 and below\n\t\t\t\tif (this.getNode().typeVersion < 1.5) {\n\t\t\t\t\ttemplateText = templateText.replace(\n\t\t\t\t\t\t`{${LEGACY_INPUT_TEMPLATE_KEY}}`,\n\t\t\t\t\t\t`{${INPUT_TEMPLATE_KEY}}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Create prompt template based on model type and user configuration\n\t\t\t\tlet promptTemplate;\n\t\t\t\tif (isChatInstance(model)) {\n\t\t\t\t\t// For chat models, create a chat prompt template with system and human messages\n\t\t\t\t\tconst messages = [\n\t\t\t\t\t\tSystemMessagePromptTemplate.fromTemplate(templateText),\n\t\t\t\t\t\tHumanMessagePromptTemplate.fromTemplate('{input}'),\n\t\t\t\t\t];\n\t\t\t\t\tpromptTemplate = ChatPromptTemplate.fromMessages(messages);\n\t\t\t\t} else {\n\t\t\t\t\t// For non-chat models, create a text prompt template with Question/Answer format\n\t\t\t\t\tconst questionSuffix =\n\t\t\t\t\t\toptions.systemPromptTemplate === undefined ? '\\n\\nQuestion: {input}\\nAnswer:' : '';\n\n\t\t\t\t\tpromptTemplate = new PromptTemplate({\n\t\t\t\t\t\ttemplate: templateText + questionSuffix,\n\t\t\t\t\t\tinputVariables: ['context', 'input'],\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Create the document chain that combines the retrieved documents\n\t\t\t\tconst combineDocsChain = await createStuffDocumentsChain({\n\t\t\t\t\tllm: model,\n\t\t\t\t\tprompt: promptTemplate,\n\t\t\t\t});\n\n\t\t\t\t// Create the retrieval chain that handles the retrieval and then passes to the combine docs chain\n\t\t\t\tconst retrievalChain = await createRetrievalChain({\n\t\t\t\t\tcombineDocsChain,\n\t\t\t\t\tretriever,\n\t\t\t\t});\n\n\t\t\t\t// Execute the chain with tracing config\n\t\t\t\tconst tracingConfig = getTracingConfig(this);\n\t\t\t\tconst response = await retrievalChain\n\t\t\t\t\t.withConfig(tracingConfig)\n\t\t\t\t\t.invoke({ input: query }, { signal: this.getExecutionCancelSignal() });\n\n\t\t\t\t// Get the answer from the response\n\t\t\t\tconst answer: string = response.answer;\n\t\t\t\tif (this.getNode().typeVersion >= 1.5) {\n\t\t\t\t\treturnData.push({ json: { response: answer } });\n\t\t\t\t} else {\n\t\t\t\t\t// Legacy format for versions 1.4 and below is { text: string }\n\t\t\t\t\treturnData.push({ json: { response: { text: answer } } });\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\treturnData.push({\n\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAKO;AAEP,+BAA0C;AAC1C,uBAAqC;AACrC,0BAA4E;AAS5E,0BAAwD;AACxD,qBAAqD;AACrD,0BAAuC;AACvC,qBAAiC;AAEjC,MAAM,yBAAyB;AAAA;AAAA;AAAA;AAM/B,MAAM,4BAA4B;AAClC,MAAM,qBAAqB;AAE3B,MAAM,qBAAsC;AAAA,EAC3C,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,IACZ,MAAM;AAAA,EACP;AACD;AAEO,MAAM,iBAAsC;AAAA,EAA5C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,KAAK,KAAK,GAAG;AAAA,MACpC,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,QACN,OAAO;AAAA,MACR;AAAA,MACA,OAAO;AAAA,QACN,OAAO,CAAC,WAAW;AAAA,QACnB,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,UAAU,YAAY;AAAA,QAC5B;AAAA,QACA,WAAW;AAA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AAO,EAAE,OAAO,MAAM,GAAG,EAAE,QAAQ,KAAK,yBAAyB,EAAE,CAAC;AAGtE,cAAM,SAAiB,SAAS;AAChC,YAAI,KAAK,QAAQ,EAAE,eAAe,KAAK;AACtC,qBAAW,KAAK,EAAE,MAAM,EAAE,UAAU,OAAO,EAAE,CAAC;AAAA,QAC/C,OAAO;AAEN,qBAAW,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO,EAAE,EAAE,CAAC;AAAA,QACzD;AAAA,MACD,SAAS,OAAO;AACf,YAAI,KAAK,eAAe,GAAG;AAC1B,gBAAM,eAAW,wCAAmB,KAAK;AACzC,qBAAW,KAAK;AAAA,YACf,MAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,YAC7B,YAAY,EAAE,MAAM,UAAU;AAAA,YAC9B;AAAA,UACD,CAAC;AACD;AAAA,QACD;AAEA,cAAM;AAAA,MACP;AAAA,IACD;AACA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.ts"],"sourcesContent":["import { NodeConnectionTypes, parseErrorMetadata, sleep } from 'n8n-workflow';\nimport {\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n} from 'n8n-workflow';\n\nimport { promptTypeOptions, textFromPreviousNode } from '@utils/descriptions';\nimport { getBatchingOptionFields, getTemplateNoticeField } from '@utils/sharedFields';\n\nimport { INPUT_TEMPLATE_KEY, LEGACY_INPUT_TEMPLATE_KEY, systemPromptOption } from './constants';\nimport { processItem } from './processItem';\n\nexport class ChainRetrievalQa implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Question and Answer Chain',\n\t\tname: 'chainRetrievalQa',\n\t\ticon: 'fa:link',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6],\n\t\tdescription: 'Answer questions about retrieved documents',\n\t\tdefaults: {\n\t\t\tname: 'Question and Answer Chain',\n\t\t\tcolor: '#909298',\n\t\t},\n\t\tcodex: {\n\t\t\talias: ['LangChain'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainretrievalqa/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [\n\t\t\tNodeConnectionTypes.Main,\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Retriever',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiRetriever,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [],\n\t\tproperties: [\n\t\t\tgetTemplateNoticeField(1960),\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chat_input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chatInput }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.2],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...promptTypeOptions,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\thide: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...textFromPreviousNode,\n\t\t\t\tdisplayOptions: { show: { promptType: ['auto'], '@version': [{ _cnd: { gte: 1.4 } }] } },\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Prompt (User Message)',\n\t\t\t\tname: 'text',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. Hello, how can you help me?',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tpromptType: ['define'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${LEGACY_INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { lt: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetBatchingOptionFields({\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.6 } }],\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Retrieval QA Chain');\n\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\t\tconst batchSize = this.getNodeParameter('options.batching.batchSize', 0, 5) as number;\n\t\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t\t'options.batching.delayBetweenBatches',\n\t\t\t0,\n\t\t\t0,\n\t\t) as number;\n\n\t\tif (this.getNode().typeVersion >= 1.6 && batchSize >= 1) {\n\t\t\t// Run in batches\n\t\t\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\t\t\tconst batch = items.slice(i, i + batchSize);\n\t\t\t\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\t\t\t\treturn await processItem(this, i + batchItemIndex);\n\t\t\t\t});\n\n\t\t\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\n\t\t\t\tbatchResults.forEach((response, index) => {\n\t\t\t\t\tif (response.status === 'rejected') {\n\t\t\t\t\t\tconst error = response.reason;\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\t\tpairedItem: { item: index },\n\t\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst output = response.value;\n\t\t\t\t\tconst answer = output.answer as string;\n\t\t\t\t\tif (this.getNode().typeVersion >= 1.5) {\n\t\t\t\t\t\treturnData.push({ json: { response: answer } });\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Legacy format for versions 1.4 and below is { text: string }\n\t\t\t\t\t\treturnData.push({ json: { response: { text: answer } } });\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t// Add delay between batches if not the last batch\n\t\t\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\t\t\tawait sleep(delayBetweenBatches);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Run for each item\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await processItem(this, itemIndex);\n\t\t\t\t\tconst answer = response.answer as string;\n\t\t\t\t\tif (this.getNode().typeVersion >= 1.5) {\n\t\t\t\t\t\treturnData.push({ json: { response: answer } });\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Legacy format for versions 1.4 and below is { text: string }\n\t\t\t\t\t\treturnData.push({ json: { response: { text: answer } } });\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA+D;AAQ/D,0BAAwD;AACxD,0BAAgE;AAEhE,uBAAkF;AAClF,yBAA4B;AAErB,MAAM,iBAAsC;AAAA,EAA5C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAAA,MACzC,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,QACN,OAAO;AAAA,MACR;AAAA,MACA,OAAO;AAAA,QACN,OAAO,CAAC,WAAW;AAAA,QACnB,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,UAAU,YAAY;AAAA,QAC5B;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA;AAAA,MAEA,QAAQ;AAAA,QACP,wCAAoB;AAAA,QACpB;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,UAC1B,UAAU;AAAA,QACX;AAAA,QACA;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,UAC1B,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,SAAS,CAAC,wCAAoB,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,uBAAW,KAAK;AAAA,cACf,MAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,cAC7B,YAAY,EAAE,MAAM,UAAU;AAAA,cAC9B;AAAA,YACD,CAAC;AACD;AAAA,UACD;AAEA,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AACA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
INPUT_TEMPLATE_KEY: () => INPUT_TEMPLATE_KEY,
|
|
22
|
+
LEGACY_INPUT_TEMPLATE_KEY: () => LEGACY_INPUT_TEMPLATE_KEY,
|
|
23
|
+
SYSTEM_PROMPT_TEMPLATE: () => SYSTEM_PROMPT_TEMPLATE,
|
|
24
|
+
systemPromptOption: () => systemPromptOption
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(constants_exports);
|
|
27
|
+
const SYSTEM_PROMPT_TEMPLATE = `You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question.
|
|
28
|
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
|
29
|
+
----------------
|
|
30
|
+
Context: {context}`;
|
|
31
|
+
const LEGACY_INPUT_TEMPLATE_KEY = "question";
|
|
32
|
+
const INPUT_TEMPLATE_KEY = "input";
|
|
33
|
+
const systemPromptOption = {
|
|
34
|
+
displayName: "System Prompt Template",
|
|
35
|
+
name: "systemPromptTemplate",
|
|
36
|
+
type: "string",
|
|
37
|
+
default: SYSTEM_PROMPT_TEMPLATE,
|
|
38
|
+
typeOptions: {
|
|
39
|
+
rows: 6
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
INPUT_TEMPLATE_KEY,
|
|
45
|
+
LEGACY_INPUT_TEMPLATE_KEY,
|
|
46
|
+
SYSTEM_PROMPT_TEMPLATE,
|
|
47
|
+
systemPromptOption
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainRetrievalQA/constants.ts"],"sourcesContent":["import type { INodeProperties } from 'n8n-workflow';\n\nexport const SYSTEM_PROMPT_TEMPLATE = `You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question.\nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\n----------------\nContext: {context}`;\n\n// Due to the refactoring in version 1.5, the variable name {question} needed to be changed to {input} in the prompt template.\nexport const LEGACY_INPUT_TEMPLATE_KEY = 'question';\nexport const INPUT_TEMPLATE_KEY = 'input';\n\nexport const systemPromptOption: INodeProperties = {\n\tdisplayName: 'System Prompt Template',\n\tname: 'systemPromptTemplate',\n\ttype: 'string',\n\tdefault: SYSTEM_PROMPT_TEMPLATE,\n\ttypeOptions: {\n\t\trows: 6,\n\t},\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,yBAAyB;AAAA;AAAA;AAAA;AAM/B,MAAM,4BAA4B;AAClC,MAAM,qBAAqB;AAE3B,MAAM,qBAAsC;AAAA,EAClD,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,IACZ,MAAM;AAAA,EACP;AACD;","names":[]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var processItem_exports = {};
|
|
20
|
+
__export(processItem_exports, {
|
|
21
|
+
processItem: () => processItem
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(processItem_exports);
|
|
24
|
+
var import_prompts = require("@langchain/core/prompts");
|
|
25
|
+
var import_combine_documents = require("langchain/chains/combine_documents");
|
|
26
|
+
var import_retrieval = require("langchain/chains/retrieval");
|
|
27
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
28
|
+
var import_helpers = require("../../../utils/helpers");
|
|
29
|
+
var import_tracing = require("../../../utils/tracing");
|
|
30
|
+
var import_constants = require("./constants");
|
|
31
|
+
const processItem = async (ctx, itemIndex) => {
|
|
32
|
+
const model = await ctx.getInputConnectionData(
|
|
33
|
+
import_n8n_workflow.NodeConnectionTypes.AiLanguageModel,
|
|
34
|
+
0
|
|
35
|
+
);
|
|
36
|
+
const retriever = await ctx.getInputConnectionData(
|
|
37
|
+
import_n8n_workflow.NodeConnectionTypes.AiRetriever,
|
|
38
|
+
0
|
|
39
|
+
);
|
|
40
|
+
let query;
|
|
41
|
+
if (ctx.getNode().typeVersion <= 1.2) {
|
|
42
|
+
query = ctx.getNodeParameter("query", itemIndex);
|
|
43
|
+
} else {
|
|
44
|
+
query = (0, import_helpers.getPromptInputByType)({
|
|
45
|
+
ctx,
|
|
46
|
+
i: itemIndex,
|
|
47
|
+
inputKey: "text",
|
|
48
|
+
promptTypeKey: "promptType"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (query === void 0) {
|
|
52
|
+
throw new import_n8n_workflow.NodeOperationError(ctx.getNode(), "The \u2018query\u2018 parameter is empty.");
|
|
53
|
+
}
|
|
54
|
+
const options = ctx.getNodeParameter("options", itemIndex, {});
|
|
55
|
+
let templateText = options.systemPromptTemplate ?? import_constants.SYSTEM_PROMPT_TEMPLATE;
|
|
56
|
+
if (ctx.getNode().typeVersion < 1.5) {
|
|
57
|
+
templateText = templateText.replace(
|
|
58
|
+
`{${import_constants.LEGACY_INPUT_TEMPLATE_KEY}}`,
|
|
59
|
+
`{${import_constants.INPUT_TEMPLATE_KEY}}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
let promptTemplate;
|
|
63
|
+
if ((0, import_helpers.isChatInstance)(model)) {
|
|
64
|
+
const messages = [
|
|
65
|
+
import_prompts.SystemMessagePromptTemplate.fromTemplate(templateText),
|
|
66
|
+
import_prompts.HumanMessagePromptTemplate.fromTemplate("{input}")
|
|
67
|
+
];
|
|
68
|
+
promptTemplate = import_prompts.ChatPromptTemplate.fromMessages(messages);
|
|
69
|
+
} else {
|
|
70
|
+
const questionSuffix = options.systemPromptTemplate === void 0 ? "\n\nQuestion: {input}\nAnswer:" : "";
|
|
71
|
+
promptTemplate = new import_prompts.PromptTemplate({
|
|
72
|
+
template: templateText + questionSuffix,
|
|
73
|
+
inputVariables: ["context", "input"]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const combineDocsChain = await (0, import_combine_documents.createStuffDocumentsChain)({
|
|
77
|
+
llm: model,
|
|
78
|
+
prompt: promptTemplate
|
|
79
|
+
});
|
|
80
|
+
const retrievalChain = await (0, import_retrieval.createRetrievalChain)({
|
|
81
|
+
combineDocsChain,
|
|
82
|
+
retriever
|
|
83
|
+
});
|
|
84
|
+
const tracingConfig = (0, import_tracing.getTracingConfig)(ctx);
|
|
85
|
+
return await retrievalChain.withConfig(tracingConfig).invoke({ input: query }, { signal: ctx.getExecutionCancelSignal() });
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
processItem
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=processItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainRetrievalQA/processItem.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport {\n\tChatPromptTemplate,\n\tHumanMessagePromptTemplate,\n\tPromptTemplate,\n\tSystemMessagePromptTemplate,\n} from '@langchain/core/prompts';\nimport type { BaseRetriever } from '@langchain/core/retrievers';\nimport { createStuffDocumentsChain } from 'langchain/chains/combine_documents';\nimport { createRetrievalChain } from 'langchain/chains/retrieval';\nimport { type IExecuteFunctions, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\n\nimport { getPromptInputByType, isChatInstance } from '@utils/helpers';\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { INPUT_TEMPLATE_KEY, LEGACY_INPUT_TEMPLATE_KEY, SYSTEM_PROMPT_TEMPLATE } from './constants';\n\nexport const processItem = async (\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n): Promise<Record<string, unknown>> => {\n\tconst model = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t0,\n\t)) as BaseLanguageModel;\n\n\tconst retriever = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiRetriever,\n\t\t0,\n\t)) as BaseRetriever;\n\n\tlet query;\n\n\tif (ctx.getNode().typeVersion <= 1.2) {\n\t\tquery = ctx.getNodeParameter('query', itemIndex) as string;\n\t} else {\n\t\tquery = getPromptInputByType({\n\t\t\tctx,\n\t\t\ti: itemIndex,\n\t\t\tinputKey: 'text',\n\t\t\tpromptTypeKey: 'promptType',\n\t\t});\n\t}\n\n\tif (query === undefined) {\n\t\tthrow new NodeOperationError(ctx.getNode(), 'The ‘query‘ parameter is empty.');\n\t}\n\n\tconst options = ctx.getNodeParameter('options', itemIndex, {}) as {\n\t\tsystemPromptTemplate?: string;\n\t};\n\n\tlet templateText = options.systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE;\n\n\t// Replace legacy input template key for versions 1.4 and below\n\tif (ctx.getNode().typeVersion < 1.5) {\n\t\ttemplateText = templateText.replace(\n\t\t\t`{${LEGACY_INPUT_TEMPLATE_KEY}}`,\n\t\t\t`{${INPUT_TEMPLATE_KEY}}`,\n\t\t);\n\t}\n\n\t// Create prompt template based on model type and user configuration\n\tlet promptTemplate;\n\tif (isChatInstance(model)) {\n\t\t// For chat models, create a chat prompt template with system and human messages\n\t\tconst messages = [\n\t\t\tSystemMessagePromptTemplate.fromTemplate(templateText),\n\t\t\tHumanMessagePromptTemplate.fromTemplate('{input}'),\n\t\t];\n\t\tpromptTemplate = ChatPromptTemplate.fromMessages(messages);\n\t} else {\n\t\t// For non-chat models, create a text prompt template with Question/Answer format\n\t\tconst questionSuffix =\n\t\t\toptions.systemPromptTemplate === undefined ? '\\n\\nQuestion: {input}\\nAnswer:' : '';\n\n\t\tpromptTemplate = new PromptTemplate({\n\t\t\ttemplate: templateText + questionSuffix,\n\t\t\tinputVariables: ['context', 'input'],\n\t\t});\n\t}\n\n\t// Create the document chain that combines the retrieved documents\n\tconst combineDocsChain = await createStuffDocumentsChain({\n\t\tllm: model,\n\t\tprompt: promptTemplate,\n\t});\n\n\t// Create the retrieval chain that handles the retrieval and then passes to the combine docs chain\n\tconst retrievalChain = await createRetrievalChain({\n\t\tcombineDocsChain,\n\t\tretriever,\n\t});\n\n\t// Execute the chain with tracing config\n\tconst tracingConfig = getTracingConfig(ctx);\n\treturn await retrievalChain\n\t\t.withConfig(tracingConfig)\n\t\t.invoke({ input: query }, { signal: ctx.getExecutionCancelSignal() });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAKO;AAEP,+BAA0C;AAC1C,uBAAqC;AACrC,0BAAgF;AAEhF,qBAAqD;AACrD,qBAAiC;AAEjC,uBAAsF;AAE/E,MAAM,cAAc,OAC1B,KACA,cACsC;AACtC,QAAM,QAAS,MAAM,IAAI;AAAA,IACxB,wCAAoB;AAAA,IACpB;AAAA,EACD;AAEA,QAAM,YAAa,MAAM,IAAI;AAAA,IAC5B,wCAAoB;AAAA,IACpB;AAAA,EACD;AAEA,MAAI;AAEJ,MAAI,IAAI,QAAQ,EAAE,eAAe,KAAK;AACrC,YAAQ,IAAI,iBAAiB,SAAS,SAAS;AAAA,EAChD,OAAO;AACN,gBAAQ,qCAAqB;AAAA,MAC5B;AAAA,MACA,GAAG;AAAA,MACH,UAAU;AAAA,MACV,eAAe;AAAA,IAChB,CAAC;AAAA,EACF;AAEA,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,uCAAmB,IAAI,QAAQ,GAAG,2CAAiC;AAAA,EAC9E;AAEA,QAAM,UAAU,IAAI,iBAAiB,WAAW,WAAW,CAAC,CAAC;AAI7D,MAAI,eAAe,QAAQ,wBAAwB;AAGnD,MAAI,IAAI,QAAQ,EAAE,cAAc,KAAK;AACpC,mBAAe,aAAa;AAAA,MAC3B,IAAI,0CAAyB;AAAA,MAC7B,IAAI,mCAAkB;AAAA,IACvB;AAAA,EACD;AAGA,MAAI;AACJ,UAAI,+BAAe,KAAK,GAAG;AAE1B,UAAM,WAAW;AAAA,MAChB,2CAA4B,aAAa,YAAY;AAAA,MACrD,0CAA2B,aAAa,SAAS;AAAA,IAClD;AACA,qBAAiB,kCAAmB,aAAa,QAAQ;AAAA,EAC1D,OAAO;AAEN,UAAM,iBACL,QAAQ,yBAAyB,SAAY,mCAAmC;AAEjF,qBAAiB,IAAI,8BAAe;AAAA,MACnC,UAAU,eAAe;AAAA,MACzB,gBAAgB,CAAC,WAAW,OAAO;AAAA,IACpC,CAAC;AAAA,EACF;AAGA,QAAM,mBAAmB,UAAM,oDAA0B;AAAA,IACxD,KAAK;AAAA,IACL,QAAQ;AAAA,EACT,CAAC;AAGD,QAAM,iBAAiB,UAAM,uCAAqB;AAAA,IACjD;AAAA,IACA;AAAA,EACD,CAAC;AAGD,QAAM,oBAAgB,iCAAiB,GAAG;AAC1C,SAAO,MAAM,eACX,WAAW,aAAa,EACxB,OAAO,EAAE,OAAO,MAAM,GAAG,EAAE,QAAQ,IAAI,yBAAyB,EAAE,CAAC;AACtE;","names":[]}
|
|
@@ -47,11 +47,12 @@ class ChainSummarization extends import_n8n_workflow.VersionedNodeType {
|
|
|
47
47
|
]
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
-
defaultVersion: 2
|
|
50
|
+
defaultVersion: 2.1
|
|
51
51
|
};
|
|
52
52
|
const nodeVersions = {
|
|
53
53
|
1: new import_ChainSummarizationV1.ChainSummarizationV1(baseDescription),
|
|
54
|
-
2: new import_ChainSummarizationV2.ChainSummarizationV2(baseDescription)
|
|
54
|
+
2: new import_ChainSummarizationV2.ChainSummarizationV2(baseDescription),
|
|
55
|
+
2.1: new import_ChainSummarizationV2.ChainSummarizationV2(baseDescription)
|
|
55
56
|
};
|
|
56
57
|
super(nodeVersions, baseDescription);
|
|
57
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/chains/ChainSummarization/ChainSummarization.node.ts"],"sourcesContent":["import type { INodeTypeBaseDescription, IVersionedNodeType } from 'n8n-workflow';\nimport { VersionedNodeType } from 'n8n-workflow';\n\nimport { ChainSummarizationV1 } from './V1/ChainSummarizationV1.node';\nimport { ChainSummarizationV2 } from './V2/ChainSummarizationV2.node';\n\nexport class ChainSummarization extends VersionedNodeType {\n\tconstructor() {\n\t\tconst baseDescription: INodeTypeBaseDescription = {\n\t\t\tdisplayName: 'Summarization Chain',\n\t\t\tname: 'chainSummarization',\n\t\t\ticon: 'fa:link',\n\t\t\ticonColor: 'black',\n\t\t\tgroup: ['transform'],\n\t\t\tdescription: 'Transforms text into a concise summary',\n\t\t\tcodex: {\n\t\t\t\talias: ['LangChain'],\n\t\t\t\tcategories: ['AI'],\n\t\t\t\tsubcategories: {\n\t\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t\t},\n\t\t\t\tresources: {\n\t\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainsummarization/',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t\tdefaultVersion: 2,\n\t\t};\n\n\t\tconst nodeVersions: IVersionedNodeType['nodeVersions'] = {\n\t\t\t1: new ChainSummarizationV1(baseDescription),\n\t\t\t2: new ChainSummarizationV2(baseDescription),\n\t\t};\n\n\t\tsuper(nodeVersions, baseDescription);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAAkC;AAElC,kCAAqC;AACrC,kCAAqC;AAE9B,MAAM,2BAA2B,sCAAkB;AAAA,EACzD,cAAc;AACb,UAAM,kBAA4C;AAAA,MACjD,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,aAAa;AAAA,MACb,OAAO;AAAA,QACN,OAAO,CAAC,WAAW;AAAA,QACnB,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,UAAU,YAAY;AAAA,QAC5B;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,gBAAgB;AAAA,IACjB;AAEA,UAAM,eAAmD;AAAA,MACxD,GAAG,IAAI,iDAAqB,eAAe;AAAA,MAC3C,GAAG,IAAI,iDAAqB,eAAe;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainSummarization/ChainSummarization.node.ts"],"sourcesContent":["import type { INodeTypeBaseDescription, IVersionedNodeType } from 'n8n-workflow';\nimport { VersionedNodeType } from 'n8n-workflow';\n\nimport { ChainSummarizationV1 } from './V1/ChainSummarizationV1.node';\nimport { ChainSummarizationV2 } from './V2/ChainSummarizationV2.node';\n\nexport class ChainSummarization extends VersionedNodeType {\n\tconstructor() {\n\t\tconst baseDescription: INodeTypeBaseDescription = {\n\t\t\tdisplayName: 'Summarization Chain',\n\t\t\tname: 'chainSummarization',\n\t\t\ticon: 'fa:link',\n\t\t\ticonColor: 'black',\n\t\t\tgroup: ['transform'],\n\t\t\tdescription: 'Transforms text into a concise summary',\n\t\t\tcodex: {\n\t\t\t\talias: ['LangChain'],\n\t\t\t\tcategories: ['AI'],\n\t\t\t\tsubcategories: {\n\t\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t\t},\n\t\t\t\tresources: {\n\t\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainsummarization/',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t\tdefaultVersion: 2.1,\n\t\t};\n\n\t\tconst nodeVersions: IVersionedNodeType['nodeVersions'] = {\n\t\t\t1: new ChainSummarizationV1(baseDescription),\n\t\t\t2: new ChainSummarizationV2(baseDescription),\n\t\t\t2.1: new ChainSummarizationV2(baseDescription),\n\t\t};\n\n\t\tsuper(nodeVersions, baseDescription);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAAkC;AAElC,kCAAqC;AACrC,kCAAqC;AAE9B,MAAM,2BAA2B,sCAAkB;AAAA,EACzD,cAAc;AACb,UAAM,kBAA4C;AAAA,MACjD,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,aAAa;AAAA,MACb,OAAO;AAAA,QACN,OAAO,CAAC,WAAW;AAAA,QACnB,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,UAAU,YAAY;AAAA,QAC5B;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,gBAAgB;AAAA,IACjB;AAEA,UAAM,eAAmD;AAAA,MACxD,GAAG,IAAI,iDAAqB,eAAe;AAAA,MAC3C,GAAG,IAAI,iDAAqB,eAAe;AAAA,MAC3C,KAAK,IAAI,iDAAqB,eAAe;AAAA,IAC9C;AAEA,UAAM,cAAc,eAAe;AAAA,EACpC;AACD;","names":[]}
|
|
@@ -21,14 +21,9 @@ __export(ChainSummarizationV2_node_exports, {
|
|
|
21
21
|
ChainSummarizationV2: () => ChainSummarizationV2
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(ChainSummarizationV2_node_exports);
|
|
24
|
-
var import_textsplitters = require("@langchain/textsplitters");
|
|
25
|
-
var import_chains = require("langchain/chains");
|
|
26
24
|
var import_n8n_workflow = require("n8n-workflow");
|
|
27
|
-
var import_N8nBinaryLoader = require("../../../../utils/N8nBinaryLoader");
|
|
28
|
-
var import_N8nJsonLoader = require("../../../../utils/N8nJsonLoader");
|
|
29
25
|
var import_sharedFields = require("../../../../utils/sharedFields");
|
|
30
|
-
var
|
|
31
|
-
var import_helpers = require("../helpers");
|
|
26
|
+
var import_processItem = require("./processItem");
|
|
32
27
|
var import_prompt = require("../prompt");
|
|
33
28
|
function getInputs(parameters) {
|
|
34
29
|
const chunkingMode = parameters?.chunkingMode;
|
|
@@ -66,7 +61,7 @@ class ChainSummarizationV2 {
|
|
|
66
61
|
constructor(baseDescription) {
|
|
67
62
|
this.description = {
|
|
68
63
|
...baseDescription,
|
|
69
|
-
version: [2],
|
|
64
|
+
version: [2, 2.1],
|
|
70
65
|
defaults: {
|
|
71
66
|
name: "Summarization Chain",
|
|
72
67
|
color: "#909298"
|
|
@@ -303,7 +298,12 @@ class ChainSummarizationV2 {
|
|
|
303
298
|
]
|
|
304
299
|
}
|
|
305
300
|
]
|
|
306
|
-
}
|
|
301
|
+
},
|
|
302
|
+
(0, import_sharedFields.getBatchingOptionFields)({
|
|
303
|
+
show: {
|
|
304
|
+
"@version": [{ _cnd: { gte: 2.1 } }]
|
|
305
|
+
}
|
|
306
|
+
})
|
|
307
307
|
]
|
|
308
308
|
}
|
|
309
309
|
]
|
|
@@ -315,81 +315,58 @@ class ChainSummarizationV2 {
|
|
|
315
315
|
const chunkingMode = this.getNodeParameter("chunkingMode", 0, "simple");
|
|
316
316
|
const items = this.getInputData();
|
|
317
317
|
const returnData = [];
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
)
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const response = await chain.withConfig((0, import_tracing.getTracingConfig)(this)).invoke({
|
|
344
|
-
input_documents: processedDocuments
|
|
345
|
-
});
|
|
346
|
-
returnData.push({ json: { response } });
|
|
347
|
-
}
|
|
348
|
-
if (["nodeInputJson", "nodeInputBinary"].includes(operationMode)) {
|
|
349
|
-
let textSplitter;
|
|
350
|
-
switch (chunkingMode) {
|
|
351
|
-
// In simple mode we use recursive character splitter with default settings
|
|
352
|
-
case "simple":
|
|
353
|
-
const chunkSize = this.getNodeParameter("chunkSize", itemIndex, 1e3);
|
|
354
|
-
const chunkOverlap = this.getNodeParameter("chunkOverlap", itemIndex, 200);
|
|
355
|
-
textSplitter = new import_textsplitters.RecursiveCharacterTextSplitter({ chunkOverlap, chunkSize });
|
|
356
|
-
break;
|
|
357
|
-
// In advanced mode user can connect text splitter node so we just retrieve it
|
|
358
|
-
case "advanced":
|
|
359
|
-
textSplitter = await this.getInputConnectionData(
|
|
360
|
-
import_n8n_workflow.NodeConnectionTypes.AiTextSplitter,
|
|
361
|
-
0
|
|
362
|
-
);
|
|
363
|
-
break;
|
|
364
|
-
default:
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
let processor;
|
|
368
|
-
if (operationMode === "nodeInputBinary") {
|
|
369
|
-
const binaryDataKey = this.getNodeParameter(
|
|
370
|
-
"options.binaryDataKey",
|
|
371
|
-
itemIndex,
|
|
372
|
-
"data"
|
|
373
|
-
);
|
|
374
|
-
processor = new import_N8nBinaryLoader.N8nBinaryLoader(this, "options.", binaryDataKey, textSplitter);
|
|
318
|
+
const batchSize = this.getNodeParameter("options.batching.batchSize", 0, 5);
|
|
319
|
+
const delayBetweenBatches = this.getNodeParameter(
|
|
320
|
+
"options.batching.delayBetweenBatches",
|
|
321
|
+
0,
|
|
322
|
+
0
|
|
323
|
+
);
|
|
324
|
+
if (this.getNode().typeVersion >= 2.1 && batchSize > 1) {
|
|
325
|
+
for (let i = 0; i < items.length; i += batchSize) {
|
|
326
|
+
const batch = items.slice(i, i + batchSize);
|
|
327
|
+
const batchPromises = batch.map(async (item, batchItemIndex) => {
|
|
328
|
+
const itemIndex = i + batchItemIndex;
|
|
329
|
+
return await (0, import_processItem.processItem)(this, itemIndex, item, operationMode, chunkingMode);
|
|
330
|
+
});
|
|
331
|
+
const batchResults = await Promise.allSettled(batchPromises);
|
|
332
|
+
batchResults.forEach((response, index) => {
|
|
333
|
+
if (response.status === "rejected") {
|
|
334
|
+
const error = response.reason;
|
|
335
|
+
if (this.continueOnFail()) {
|
|
336
|
+
returnData.push({
|
|
337
|
+
json: { error: error.message },
|
|
338
|
+
pairedItem: { item: i + index }
|
|
339
|
+
});
|
|
340
|
+
} else {
|
|
341
|
+
throw error;
|
|
342
|
+
}
|
|
375
343
|
} else {
|
|
376
|
-
|
|
344
|
+
const output = response.value;
|
|
345
|
+
returnData.push({ json: { output } });
|
|
377
346
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
347
|
+
});
|
|
348
|
+
if (i + batchSize < items.length && delayBetweenBatches > 0) {
|
|
349
|
+
await (0, import_n8n_workflow.sleep)(delayBetweenBatches);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
} else {
|
|
353
|
+
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
|
354
|
+
try {
|
|
355
|
+
const response = await (0, import_processItem.processItem)(
|
|
356
|
+
this,
|
|
357
|
+
itemIndex,
|
|
358
|
+
items[itemIndex],
|
|
359
|
+
operationMode,
|
|
360
|
+
chunkingMode
|
|
384
361
|
);
|
|
385
362
|
returnData.push({ json: { response } });
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (this.continueOnFail()) {
|
|
365
|
+
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
throw error;
|
|
386
369
|
}
|
|
387
|
-
} catch (error) {
|
|
388
|
-
if (this.continueOnFail()) {
|
|
389
|
-
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
|
|
390
|
-
continue;
|
|
391
|
-
}
|
|
392
|
-
throw error;
|
|
393
370
|
}
|
|
394
371
|
}
|
|
395
372
|
return [returnData];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.ts"],"sourcesContent":["import type { Document } from '@langchain/core/documents';\nimport type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { TextSplitter } from '@langchain/textsplitters';\nimport { RecursiveCharacterTextSplitter } from '@langchain/textsplitters';\nimport { loadSummarizationChain } from 'langchain/chains';\nimport type {\n\tINodeTypeBaseDescription,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n\tIDataObject,\n\tINodeInputConfiguration,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes } from 'n8n-workflow';\n\nimport { N8nBinaryLoader } from '@utils/N8nBinaryLoader';\nimport { N8nJsonLoader } from '@utils/N8nJsonLoader';\nimport { getTemplateNoticeField } from '@utils/sharedFields';\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { getChainPromptsArgs } from '../helpers';\nimport { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt';\n\nfunction getInputs(parameters: IDataObject) {\n\tconst chunkingMode = parameters?.chunkingMode;\n\tconst operationMode = parameters?.operationMode;\n\tconst inputs: INodeInputConfiguration[] = [\n\t\t{ displayName: '', type: 'main' },\n\t\t{\n\t\t\tdisplayName: 'Model',\n\t\t\tmaxConnections: 1,\n\t\t\ttype: 'ai_languageModel',\n\t\t\trequired: true,\n\t\t},\n\t];\n\n\tif (operationMode === 'documentLoader') {\n\t\tinputs.push({\n\t\t\tdisplayName: 'Document',\n\t\t\ttype: 'ai_document',\n\t\t\trequired: true,\n\t\t\tmaxConnections: 1,\n\t\t});\n\t\treturn inputs;\n\t}\n\n\tif (chunkingMode === 'advanced') {\n\t\tinputs.push({\n\t\t\tdisplayName: 'Text Splitter',\n\t\t\ttype: 'ai_textSplitter',\n\t\t\trequired: false,\n\t\t\tmaxConnections: 1,\n\t\t});\n\t\treturn inputs;\n\t}\n\treturn inputs;\n}\n\nexport class ChainSummarizationV2 implements INodeType {\n\tdescription: INodeTypeDescription;\n\n\tconstructor(baseDescription: INodeTypeBaseDescription) {\n\t\tthis.description = {\n\t\t\t...baseDescription,\n\t\t\tversion: [2],\n\t\t\tdefaults: {\n\t\t\t\tname: 'Summarization Chain',\n\t\t\t\tcolor: '#909298',\n\t\t\t},\n\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\t\tinputs: `={{ ((parameter) => { ${getInputs.toString()}; return getInputs(parameter) })($parameter) }}`,\n\t\t\toutputs: [NodeConnectionTypes.Main],\n\t\t\tcredentials: [],\n\t\t\tproperties: [\n\t\t\t\tgetTemplateNoticeField(1951),\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Data to Summarize',\n\t\t\t\t\tname: 'operationMode',\n\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\ttype: 'options',\n\t\t\t\t\tdescription: 'How to pass data into the summarization chain',\n\t\t\t\t\tdefault: 'nodeInputJson',\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Use Node Input (JSON)',\n\t\t\t\t\t\t\tvalue: 'nodeInputJson',\n\t\t\t\t\t\t\tdescription: 'Summarize the JSON data coming into this node from the previous one',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Use Node Input (Binary)',\n\t\t\t\t\t\t\tvalue: 'nodeInputBinary',\n\t\t\t\t\t\t\tdescription: 'Summarize the binary data coming into this node from the previous one',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Use Document Loader',\n\t\t\t\t\t\t\tvalue: 'documentLoader',\n\t\t\t\t\t\t\tdescription: 'Use a loader sub-node with more configuration options',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Chunking Strategy',\n\t\t\t\t\tname: 'chunkingMode',\n\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\ttype: 'options',\n\t\t\t\t\tdescription: 'Chunk splitting strategy',\n\t\t\t\t\tdefault: 'simple',\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Simple (Define Below)',\n\t\t\t\t\t\t\tvalue: 'simple',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Advanced',\n\t\t\t\t\t\t\tvalue: 'advanced',\n\t\t\t\t\t\t\tdescription: 'Use a splitter sub-node with more configuration options',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'/operationMode': ['nodeInputJson', 'nodeInputBinary'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Characters Per Chunk',\n\t\t\t\t\tname: 'chunkSize',\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Controls the max size (in terms of number of characters) of the final document chunk',\n\t\t\t\t\ttype: 'number',\n\t\t\t\t\tdefault: 1000,\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'/chunkingMode': ['simple'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Chunk Overlap (Characters)',\n\t\t\t\t\tname: 'chunkOverlap',\n\t\t\t\t\ttype: 'number',\n\t\t\t\t\tdescription: 'Specifies how much characters overlap there should be between chunks',\n\t\t\t\t\tdefault: 200,\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'/chunkingMode': ['simple'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Options',\n\t\t\t\t\tname: 'options',\n\t\t\t\t\ttype: 'collection',\n\t\t\t\t\tdefault: {},\n\t\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdisplayName: 'Input Data Field Name',\n\t\t\t\t\t\t\tname: 'binaryDataKey',\n\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\tdefault: 'data',\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t'The name of the field in the agent or chain’s input that contains the binary file to be processed',\n\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t\t'/operationMode': ['nodeInputBinary'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdisplayName: 'Summarization Method and Prompts',\n\t\t\t\t\t\t\tname: 'summarizationMethodAndPrompts',\n\t\t\t\t\t\t\ttype: 'fixedCollection',\n\t\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t\tvalues: {\n\t\t\t\t\t\t\t\t\tsummarizationMethod: 'map_reduce',\n\t\t\t\t\t\t\t\t\tprompt: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\tcombineMapPrompt: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\t\t\t\ttypeOptions: {},\n\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tname: 'values',\n\t\t\t\t\t\t\t\t\tdisplayName: 'Values',\n\t\t\t\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Summarization Method',\n\t\t\t\t\t\t\t\t\t\t\tname: 'summarizationMethod',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\t\t\t\tdescription: 'The type of summarization to run',\n\t\t\t\t\t\t\t\t\t\t\tdefault: 'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tname: 'Map Reduce (Recommended)',\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: 'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Summarize each document (or chunk) individually, then summarize those summaries',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tname: 'Refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: 'refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Summarize the first document (or chunk). Then update that summary based on the next document (or chunk), and repeat.',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tname: 'Stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: 'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Pass all documents (or chunks) at once. Ideal for small datasets.',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Individual Summary Prompt',\n\t\t\t\t\t\t\t\t\t\t\tname: 'combineMapPrompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\thint: 'The prompt to summarize an individual document (or chunk)',\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Final Prompt to Combine',\n\t\t\t\t\t\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\thint: 'The prompt to combine individual summaries',\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Prompt',\n\t\t\t\t\t\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Subsequent (Refine) Prompt',\n\t\t\t\t\t\t\t\t\t\t\tname: 'refinePrompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tdefault: REFINE_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\thint: 'The prompt to refine the summary based on the next document (or chunk)',\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Initial Prompt',\n\t\t\t\t\t\t\t\t\t\t\tname: 'refineQuestionPrompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\thint: 'The prompt for the first document (or chunk)',\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Summarization Chain V2');\n\t\tconst operationMode = this.getNodeParameter('operationMode', 0, 'nodeInputJson') as\n\t\t\t| 'nodeInputJson'\n\t\t\t| 'nodeInputBinary'\n\t\t\t| 'documentLoader';\n\t\tconst chunkingMode = this.getNodeParameter('chunkingMode', 0, 'simple') as\n\t\t\t| 'simple'\n\t\t\t| 'advanced';\n\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\ttry {\n\t\t\t\tconst model = (await this.getInputConnectionData(\n\t\t\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t\t\t0,\n\t\t\t\t)) as BaseLanguageModel;\n\n\t\t\t\tconst summarizationMethodAndPrompts = this.getNodeParameter(\n\t\t\t\t\t'options.summarizationMethodAndPrompts.values',\n\t\t\t\t\titemIndex,\n\t\t\t\t\t{},\n\t\t\t\t) as {\n\t\t\t\t\tprompt?: string;\n\t\t\t\t\trefineQuestionPrompt?: string;\n\t\t\t\t\trefinePrompt?: string;\n\t\t\t\t\tsummarizationMethod: 'map_reduce' | 'stuff' | 'refine';\n\t\t\t\t\tcombineMapPrompt?: string;\n\t\t\t\t};\n\n\t\t\t\tconst chainArgs = getChainPromptsArgs(\n\t\t\t\t\tsummarizationMethodAndPrompts.summarizationMethod ?? 'map_reduce',\n\t\t\t\t\tsummarizationMethodAndPrompts,\n\t\t\t\t);\n\n\t\t\t\tconst chain = loadSummarizationChain(model, chainArgs);\n\t\t\t\tconst item = items[itemIndex];\n\n\t\t\t\tlet processedDocuments: Document[];\n\n\t\t\t\t// Use dedicated document loader input to load documents\n\t\t\t\tif (operationMode === 'documentLoader') {\n\t\t\t\t\tconst documentInput = (await this.getInputConnectionData(\n\t\t\t\t\t\tNodeConnectionTypes.AiDocument,\n\t\t\t\t\t\t0,\n\t\t\t\t\t)) as N8nJsonLoader | Array<Document<Record<string, unknown>>>;\n\n\t\t\t\t\tconst isN8nLoader =\n\t\t\t\t\t\tdocumentInput instanceof N8nJsonLoader || documentInput instanceof N8nBinaryLoader;\n\n\t\t\t\t\tprocessedDocuments = isN8nLoader\n\t\t\t\t\t\t? await documentInput.processItem(item, itemIndex)\n\t\t\t\t\t\t: documentInput;\n\n\t\t\t\t\tconst response = await chain.withConfig(getTracingConfig(this)).invoke({\n\t\t\t\t\t\tinput_documents: processedDocuments,\n\t\t\t\t\t});\n\n\t\t\t\t\treturnData.push({ json: { response } });\n\t\t\t\t}\n\n\t\t\t\t// Take the input and use binary or json loader\n\t\t\t\tif (['nodeInputJson', 'nodeInputBinary'].includes(operationMode)) {\n\t\t\t\t\tlet textSplitter: TextSplitter | undefined;\n\n\t\t\t\t\tswitch (chunkingMode) {\n\t\t\t\t\t\t// In simple mode we use recursive character splitter with default settings\n\t\t\t\t\t\tcase 'simple':\n\t\t\t\t\t\t\tconst chunkSize = this.getNodeParameter('chunkSize', itemIndex, 1000) as number;\n\t\t\t\t\t\t\tconst chunkOverlap = this.getNodeParameter('chunkOverlap', itemIndex, 200) as number;\n\n\t\t\t\t\t\t\ttextSplitter = new RecursiveCharacterTextSplitter({ chunkOverlap, chunkSize });\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\t// In advanced mode user can connect text splitter node so we just retrieve it\n\t\t\t\t\t\tcase 'advanced':\n\t\t\t\t\t\t\ttextSplitter = (await this.getInputConnectionData(\n\t\t\t\t\t\t\t\tNodeConnectionTypes.AiTextSplitter,\n\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t)) as TextSplitter | undefined;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet processor: N8nJsonLoader | N8nBinaryLoader;\n\t\t\t\t\tif (operationMode === 'nodeInputBinary') {\n\t\t\t\t\t\tconst binaryDataKey = this.getNodeParameter(\n\t\t\t\t\t\t\t'options.binaryDataKey',\n\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\t'data',\n\t\t\t\t\t\t) as string;\n\t\t\t\t\t\tprocessor = new N8nBinaryLoader(this, 'options.', binaryDataKey, textSplitter);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tprocessor = new N8nJsonLoader(this, 'options.', textSplitter);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst processedItem = await processor.processItem(item, itemIndex);\n\t\t\t\t\tconst response = await chain.invoke(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tinput_documents: processedItem,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ signal: this.getExecutionCancelSignal() },\n\t\t\t\t\t);\n\t\t\t\t\treturnData.push({ json: { response } });\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\treturnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAA+C;AAC/C,oBAAuC;AAUvC,0BAAoC;AAEpC,6BAAgC;AAChC,2BAA8B;AAC9B,0BAAuC;AACvC,qBAAiC;AAEjC,qBAAoC;AACpC,oBAAgE;AAEhE,SAAS,UAAU,YAAyB;AAC3C,QAAM,eAAe,YAAY;AACjC,QAAM,gBAAgB,YAAY;AAClC,QAAM,SAAoC;AAAA,IACzC,EAAE,aAAa,IAAI,MAAM,OA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iB;AAAA,YAClB;AAAA,YACA,EAAE,QAAQ,KAAK,yBAAyB,EAAE;AAAA,UAC3C;AACA,qBAAW,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAAA,QACvC;AAAA,MACD,SAAS,OAAO;AACf,YAAI,KAAK,eAAe,GAAG;AAC1B,qBAAW,KAAK,EAAE,MAAM,EAAE,OAAO,MAAM,QAAQ,GAAG,YAAY,EAAE,MAAM,UAAU,EAAE,CAAC;AACnF;AAAA,QACD;AAEA,cAAM;AAAA,MACP;AAAA,IACD;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.ts"],"sourcesContent":["import type {\n\tINodeTypeBaseDescription,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n\tIDataObject,\n\tINodeInputConfiguration,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes, sleep } from 'n8n-workflow';\n\nimport { getBatchingOptionFields, getTemplateNoticeField } from '@utils/sharedFields';\n\nimport { processItem } from './processItem';\nimport { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt';\n\nfunction getInputs(parameters: IDataObject) {\n\tconst chunkingMode = parameters?.chunkingMode;\n\tconst operationMode = parameters?.operationMode;\n\tconst inputs: INodeInputConfiguration[] = [\n\t\t{ displayName: '', type: 'main' },\n\t\t{\n\t\t\tdisplayName: 'Model',\n\t\t\tmaxConnections: 1,\n\t\t\ttype: 'ai_languageModel',\n\t\t\trequired: true,\n\t\t},\n\t];\n\n\tif (operationMode === 'documentLoader') {\n\t\tinputs.push({\n\t\t\tdisplayName: 'Document',\n\t\t\ttype: 'ai_document',\n\t\t\trequired: true,\n\t\t\tmaxConnections: 1,\n\t\t});\n\t\treturn inputs;\n\t}\n\n\tif (chunkingMode === 'advanced') {\n\t\tinputs.push({\n\t\t\tdisplayName: 'Text Splitter',\n\t\t\ttype: 'ai_textSplitter',\n\t\t\trequired: false,\n\t\t\tmaxConnections: 1,\n\t\t});\n\t\treturn inputs;\n\t}\n\treturn inputs;\n}\n\nexport class ChainSummarizationV2 implements INodeType {\n\tdescription: INodeTypeDescription;\n\n\tconstructor(baseDescription: INodeTypeBaseDescription) {\n\t\tthis.description = {\n\t\t\t...baseDescription,\n\t\t\tversion: [2, 2.1],\n\t\t\tdefaults: {\n\t\t\t\tname: 'Summarization Chain',\n\t\t\t\tcolor: '#909298',\n\t\t\t},\n\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\t\tinputs: `={{ ((parameter) => { ${getInputs.toString()}; return getInputs(parameter) })($parameter) }}`,\n\t\t\toutputs: [NodeConnectionTypes.Main],\n\t\t\tcredentials: [],\n\t\t\tproperties: [\n\t\t\t\tgetTemplateNoticeField(1951),\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Data to Summarize',\n\t\t\t\t\tname: 'operationMode',\n\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\ttype: 'options',\n\t\t\t\t\tdescription: 'How to pass data into the summarization chain',\n\t\t\t\t\tdefault: 'nodeInputJson',\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Use Node Input (JSON)',\n\t\t\t\t\t\t\tvalue: 'nodeInputJson',\n\t\t\t\t\t\t\tdescription: 'Summarize the JSON data coming into this node from the previous one',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Use Node Input (Binary)',\n\t\t\t\t\t\t\tvalue: 'nodeInputBinary',\n\t\t\t\t\t\t\tdescription: 'Summarize the binary data coming into this node from the previous one',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Use Document Loader',\n\t\t\t\t\t\t\tvalue: 'documentLoader',\n\t\t\t\t\t\t\tdescription: 'Use a loader sub-node with more configuration options',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Chunking Strategy',\n\t\t\t\t\tname: 'chunkingMode',\n\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\ttype: 'options',\n\t\t\t\t\tdescription: 'Chunk splitting strategy',\n\t\t\t\t\tdefault: 'simple',\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Simple (Define Below)',\n\t\t\t\t\t\t\tvalue: 'simple',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Advanced',\n\t\t\t\t\t\t\tvalue: 'advanced',\n\t\t\t\t\t\t\tdescription: 'Use a splitter sub-node with more configuration options',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'/operationMode': ['nodeInputJson', 'nodeInputBinary'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Characters Per Chunk',\n\t\t\t\t\tname: 'chunkSize',\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Controls the max size (in terms of number of characters) of the final document chunk',\n\t\t\t\t\ttype: 'number',\n\t\t\t\t\tdefault: 1000,\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'/chunkingMode': ['simple'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Chunk Overlap (Characters)',\n\t\t\t\t\tname: 'chunkOverlap',\n\t\t\t\t\ttype: 'number',\n\t\t\t\t\tdescription: 'Specifies how much characters overlap there should be between chunks',\n\t\t\t\t\tdefault: 200,\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'/chunkingMode': ['simple'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Options',\n\t\t\t\t\tname: 'options',\n\t\t\t\t\ttype: 'collection',\n\t\t\t\t\tdefault: {},\n\t\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdisplayName: 'Input Data Field Name',\n\t\t\t\t\t\t\tname: 'binaryDataKey',\n\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\tdefault: 'data',\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t'The name of the field in the agent or chain’s input that contains the binary file to be processed',\n\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t\t'/operationMode': ['nodeInputBinary'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdisplayName: 'Summarization Method and Prompts',\n\t\t\t\t\t\t\tname: 'summarizationMethodAndPrompts',\n\t\t\t\t\t\t\ttype: 'fixedCollection',\n\t\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t\tvalues: {\n\t\t\t\t\t\t\t\t\tsummarizationMethod: 'map_reduce',\n\t\t\t\t\t\t\t\t\tprompt: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\tcombineMapPrompt: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\t\t\t\ttypeOptions: {},\n\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tname: 'values',\n\t\t\t\t\t\t\t\t\tdisplayName: 'Values',\n\t\t\t\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Summarization Method',\n\t\t\t\t\t\t\t\t\t\t\tname: 'summarizationMethod',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\t\t\t\tdescription: 'The type of summarization to run',\n\t\t\t\t\t\t\t\t\t\t\tdefault: 'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tname: 'Map Reduce (Recommended)',\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: 'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Summarize each document (or chunk) individually, then summarize those summaries',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tname: 'Refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: 'refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Summarize the first document (or chunk). Then update that summary based on the next document (or chunk), and repeat.',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tname: 'Stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: 'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Pass all documents (or chunks) at once. Ideal for small datasets.',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Individual Summary Prompt',\n\t\t\t\t\t\t\t\t\t\t\tname: 'combineMapPrompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\thint: 'The prompt to summarize an individual document (or chunk)',\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Final Prompt to Combine',\n\t\t\t\t\t\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\thint: 'The prompt to combine individual summaries',\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Prompt',\n\t\t\t\t\t\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'refine',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Subsequent (Refine) Prompt',\n\t\t\t\t\t\t\t\t\t\t\tname: 'refinePrompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tdefault: REFINE_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\thint: 'The prompt to refine the summary based on the next document (or chunk)',\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tdisplayName: 'Initial Prompt',\n\t\t\t\t\t\t\t\t\t\t\tname: 'refineQuestionPrompt',\n\t\t\t\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t'/options.summarizationMethodAndPrompts.values.summarizationMethod': [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'stuff',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'map_reduce',\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\t\t\t\t\thint: 'The prompt for the first document (or chunk)',\n\t\t\t\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\t\t\t\trows: 9,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tgetBatchingOptionFields({\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 2.1 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Summarization Chain V2');\n\t\tconst operationMode = this.getNodeParameter('operationMode', 0, 'nodeInputJson') as\n\t\t\t| 'nodeInputJson'\n\t\t\t| 'nodeInputBinary'\n\t\t\t| 'documentLoader';\n\t\tconst chunkingMode = this.getNodeParameter('chunkingMode', 0, 'simple') as\n\t\t\t| 'simple'\n\t\t\t| 'advanced';\n\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\tconst batchSize = this.getNodeParameter('options.batching.batchSize', 0, 5) as number;\n\t\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t\t'options.batching.delayBetweenBatches',\n\t\t\t0,\n\t\t\t0,\n\t\t) as number;\n\n\t\tif (this.getNode().typeVersion >= 2.1 && batchSize > 1) {\n\t\t\t// Batch processing\n\t\t\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\t\t\tconst batch = items.slice(i, i + batchSize);\n\t\t\t\tconst batchPromises = batch.map(async (item, batchItemIndex) => {\n\t\t\t\t\tconst itemIndex = i + batchItemIndex;\n\t\t\t\t\treturn await processItem(this, itemIndex, item, operationMode, chunkingMode);\n\t\t\t\t});\n\n\t\t\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\t\t\t\tbatchResults.forEach((response, index) => {\n\t\t\t\t\tif (response.status === 'rejected') {\n\t\t\t\t\t\tconst error = response.reason as Error;\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\t\tpairedItem: { item: i + index },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst output = response.value;\n\t\t\t\t\t\treturnData.push({ json: { output } });\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t// Add delay between batches if not the last batch\n\t\t\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\t\t\tawait sleep(delayBetweenBatches);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await processItem(\n\t\t\t\t\t\tthis,\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\titems[itemIndex],\n\t\t\t\t\t\toperationMode,\n\t\t\t\t\t\tchunkingMode,\n\t\t\t\t\t);\n\t\t\t\t\treturnData.push({ json: { response } });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\treturnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,0BAA2C;AAE3C,0BAAgE;AAEhE,yBAA4B;AAC5B,oBAAgE;AAEhE,SAAS,UAAU,YAAyB;AAC3C,QAAM,eAAe,YAAY;AACjC,QAAM,gBAAgB,YAAY;AAClC,QAAM,SAAoC;AAAA,IACzC,EAAE,aAAa,IAAI,MAAM,OAAO;AAAA,IAChC;AAAA,MACC,aAAa;AAAA,MACb,gBAAgB;AAAA,MAChB,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AAEA,MAAI,kBAAkB,kBAAkB;AACvC,WAAO,KAAK;AAAA,MACX,aAAa;AAAA,MACb,MAAM;AAAA,MACN,UAAU;AAAA,MACV,gBAAgB;AAAA,IACjB,CAAC;AACD,WAAO;AAAA,EACR;AAEA,MAAI,iBAAiB,YAAY;AAChC,WA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;AAED,cAAM,eAAe,MAAM,QAAQ,WAAW,aAAa;AAC3D,qBAAa,QAAQ,CAAC,UAAU,UAAU;AACzC,cAAI,SAAS,WAAW,YAAY;AACnC,kBAAM,QAAQ,SAAS;AACvB,gBAAI,KAAK,eAAe,GAAG;AAC1B,yBAAW,KAAK;AAAA,gBACf,MAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,gBAC7B,YAAY,EAAE,MAAM,IAAI,MAAM;AAAA,cAC/B,CAAC;AAAA,YACF,OAAO;AACN,oBAAM;AAAA,YACP;AAAA,UACD,OAAO;AACN,kBAAM,SAAS,SAAS;AACxB,uBAAW,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAAA,UACrC;AAAA,QACD,CAAC;AAGD,YAAI,IAAI,YAAY,MAAM,UAAU,sBAAsB,GAAG;AAC5D,oBAAM,2BAAM,mBAAmB;AAAA,QAChC;AAAA,MACD;AAAA,IACD,OAAO;AACN,eAAS,YAAY,GAAG,YAAY,MAAM,QAAQ,aAAa;AAC9D,YAAI;AACH,gBAAM,WAAW,UAAM;AAAA,YACtB;AAAA,YACA;AAAA,YACA,MAAM,SAAS;AAAA,YACf;AAAA,YACA;AAAA,UACD;AACA,qBAAW,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAAA,QACvC,SAAS,OAAO;AACf,cAAI,KAAK,eAAe,GAAG;AAC1B,uBAAW,KAAK,EAAE,MAAM,EAAE,OAAO,MAAM,QAAQ,GAAG,YAAY,EAAE,MAAM,UAAU,EAAE,CAAC;AACnF;AAAA,UACD;AAEA,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var processItem_exports = {};
|
|
20
|
+
__export(processItem_exports, {
|
|
21
|
+
processItem: () => processItem
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(processItem_exports);
|
|
24
|
+
var import_textsplitters = require("@langchain/textsplitters");
|
|
25
|
+
var import_chains = require("langchain/chains");
|
|
26
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
27
|
+
var import_N8nBinaryLoader = require("../../../../utils/N8nBinaryLoader");
|
|
28
|
+
var import_N8nJsonLoader = require("../../../../utils/N8nJsonLoader");
|
|
29
|
+
var import_tracing = require("../../../../utils/tracing");
|
|
30
|
+
var import_helpers = require("../helpers");
|
|
31
|
+
async function processItem(ctx, itemIndex, item, operationMode, chunkingMode) {
|
|
32
|
+
const model = await ctx.getInputConnectionData(
|
|
33
|
+
import_n8n_workflow.NodeConnectionTypes.AiLanguageModel,
|
|
34
|
+
0
|
|
35
|
+
);
|
|
36
|
+
const summarizationMethodAndPrompts = ctx.getNodeParameter(
|
|
37
|
+
"options.summarizationMethodAndPrompts.values",
|
|
38
|
+
itemIndex,
|
|
39
|
+
{}
|
|
40
|
+
);
|
|
41
|
+
const chainArgs = (0, import_helpers.getChainPromptsArgs)(
|
|
42
|
+
summarizationMethodAndPrompts.summarizationMethod ?? "map_reduce",
|
|
43
|
+
summarizationMethodAndPrompts
|
|
44
|
+
);
|
|
45
|
+
const chain = (0, import_chains.loadSummarizationChain)(model, chainArgs);
|
|
46
|
+
let processedDocuments;
|
|
47
|
+
if (operationMode === "documentLoader") {
|
|
48
|
+
const documentInput = await ctx.getInputConnectionData(import_n8n_workflow.NodeConnectionTypes.AiDocument, 0);
|
|
49
|
+
const isN8nLoader = documentInput instanceof import_N8nJsonLoader.N8nJsonLoader || documentInput instanceof import_N8nBinaryLoader.N8nBinaryLoader;
|
|
50
|
+
processedDocuments = isN8nLoader ? await documentInput.processItem(item, itemIndex) : documentInput;
|
|
51
|
+
return await chain.withConfig((0, import_tracing.getTracingConfig)(ctx)).invoke({
|
|
52
|
+
input_documents: processedDocuments
|
|
53
|
+
});
|
|
54
|
+
} else if (["nodeInputJson", "nodeInputBinary"].includes(operationMode)) {
|
|
55
|
+
let textSplitter;
|
|
56
|
+
switch (chunkingMode) {
|
|
57
|
+
// In simple mode we use recursive character splitter with default settings
|
|
58
|
+
case "simple":
|
|
59
|
+
const chunkSize = ctx.getNodeParameter("chunkSize", itemIndex, 1e3);
|
|
60
|
+
const chunkOverlap = ctx.getNodeParameter("chunkOverlap", itemIndex, 200);
|
|
61
|
+
textSplitter = new import_textsplitters.RecursiveCharacterTextSplitter({ chunkOverlap, chunkSize });
|
|
62
|
+
break;
|
|
63
|
+
// In advanced mode user can connect text splitter node so we just retrieve it
|
|
64
|
+
case "advanced":
|
|
65
|
+
textSplitter = await ctx.getInputConnectionData(import_n8n_workflow.NodeConnectionTypes.AiTextSplitter, 0);
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
let processor;
|
|
71
|
+
if (operationMode === "nodeInputBinary") {
|
|
72
|
+
const binaryDataKey = ctx.getNodeParameter(
|
|
73
|
+
"options.binaryDataKey",
|
|
74
|
+
itemIndex,
|
|
75
|
+
"data"
|
|
76
|
+
);
|
|
77
|
+
processor = new import_N8nBinaryLoader.N8nBinaryLoader(ctx, "options.", binaryDataKey, textSplitter);
|
|
78
|
+
} else {
|
|
79
|
+
processor = new import_N8nJsonLoader.N8nJsonLoader(ctx, "options.", textSplitter);
|
|
80
|
+
}
|
|
81
|
+
const processedItem = await processor.processItem(item, itemIndex);
|
|
82
|
+
return await chain.invoke(
|
|
83
|
+
{
|
|
84
|
+
input_documents: processedItem
|
|
85
|
+
},
|
|
86
|
+
{ signal: ctx.getExecutionCancelSignal() }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
processItem
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=processItem.js.map
|