@n8n/n8n-nodes-langchain 1.121.1 → 1.122.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/nodes/Guardrails/Guardrails.node.js +29 -40
- package/dist/nodes/Guardrails/Guardrails.node.js.map +1 -1
- package/dist/nodes/Guardrails/actions/execute.js +68 -0
- package/dist/nodes/Guardrails/actions/execute.js.map +1 -0
- package/dist/nodes/Guardrails/actions/process.js +10 -7
- package/dist/nodes/Guardrails/actions/process.js.map +1 -1
- package/dist/nodes/Guardrails/description.js +326 -365
- package/dist/nodes/Guardrails/description.js.map +1 -1
- package/dist/nodes/Guardrails/helpers/configureNodeInputs.js +37 -3
- package/dist/nodes/Guardrails/helpers/configureNodeInputs.js.map +1 -1
- package/dist/nodes/Guardrails/helpers/model.js.map +1 -1
- package/dist/nodes/Guardrails/v1/GuardrailsV1.node.js +59 -0
- package/dist/nodes/Guardrails/v1/GuardrailsV1.node.js.map +1 -0
- package/dist/nodes/Guardrails/v2/GuardrailsV2.node.js +59 -0
- package/dist/nodes/Guardrails/v2/GuardrailsV2.node.js.map +1 -0
- package/dist/nodes/ToolExecutor/ToolExecutor.node.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js +3 -85
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/SqlAgent/execute.js +2 -2
- package/dist/nodes/agents/Agent/agents/SqlAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/buildExecutionContext.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/createAgentSequence.js +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/createAgentSequence.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/finalizeResult.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/prepareItemContext.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/runAgent.js +8 -16
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/runAgent.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/utils.js.map +1 -1
- package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js +2 -2
- package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js.map +1 -1
- package/dist/nodes/chains/ChainRetrievalQA/processItem.js +2 -2
- package/dist/nodes/chains/ChainRetrievalQA/processItem.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js +1 -1
- package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/V2/processItem.js +1 -1
- package/dist/nodes/chains/ChainSummarization/V2/processItem.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/helpers.js.map +1 -1
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js +1 -1
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js.map +1 -1
- package/dist/nodes/chains/InformationExtractor/processItem.js.map +1 -1
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js +1 -1
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js.map +1 -1
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js +1 -1
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js.map +1 -1
- package/dist/nodes/chains/TextClassifier/processItem.js.map +1 -1
- package/dist/nodes/code/Code.node.js +66 -2
- package/dist/nodes/code/Code.node.js.map +1 -1
- package/dist/nodes/llms/LMOllama/LmOllama.node.js +1 -1
- package/dist/nodes/llms/LMOllama/LmOllama.node.js.map +1 -1
- package/dist/nodes/mcp/McpClientTool/utils.js +1 -1
- package/dist/nodes/mcp/McpClientTool/utils.js.map +1 -1
- package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js +1 -1
- package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js.map +1 -1
- package/dist/nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.js +1 -1
- package/dist/nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.js.map +1 -1
- package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js +1 -1
- package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js.map +1 -1
- package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js +1 -1
- package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js.map +1 -1
- package/dist/nodes/memory/MemoryXata/MemoryXata.node.js +1 -1
- package/dist/nodes/memory/MemoryXata/MemoryXata.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js +2 -2
- package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js +1 -1
- package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js +1 -1
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js.map +1 -1
- package/dist/nodes/tools/ToolThink/ToolThink.node.js +1 -1
- package/dist/nodes/tools/ToolThink/ToolThink.node.js.map +1 -1
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js +2 -2
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +5 -21
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/Chat.node.js +2 -2
- package/dist/nodes/trigger/ChatTrigger/Chat.node.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js +1 -1
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.js +65 -17
- package/dist/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreQdrant/qdrant.svg +23 -19
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryCalculator.js.map +1 -1
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryVectorStoreManager.js +1 -1
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryVectorStoreManager.js.map +1 -1
- package/dist/nodes/vector_store/shared/MemoryManager/StoreCleanupService.js.map +1 -1
- package/dist/nodes/vector_store/shared/MemoryManager/types.js.map +1 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js +18 -16
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/image/edit.operation.js +6 -1
- package/dist/nodes/vendors/GoogleGemini/actions/image/edit.operation.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/image/generate.operation.js +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/image/generate.operation.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/methods/listSearch.js +23 -8
- package/dist/nodes/vendors/GoogleGemini/methods/listSearch.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/helpers/utils.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/v1/actions/assistant/message.operation.js +2 -2
- package/dist/nodes/vendors/OpenAi/v1/actions/assistant/message.operation.js.map +1 -1
- package/dist/types/nodes.json +7 -6
- package/dist/utils/N8nBinaryLoader.js +2 -2
- package/dist/utils/N8nBinaryLoader.js.map +1 -1
- package/dist/utils/N8nJsonLoader.js +2 -2
- package/dist/utils/N8nJsonLoader.js.map +1 -1
- package/dist/utils/N8nTool.js +1 -1
- package/dist/utils/N8nTool.js.map +1 -1
- package/dist/utils/agent-execution/buildSteps.js +12 -8
- package/dist/utils/agent-execution/buildSteps.js.map +1 -1
- package/dist/utils/agent-execution/createEngineRequests.js +19 -1
- package/dist/utils/agent-execution/createEngineRequests.js.map +1 -1
- package/dist/utils/agent-execution/index.js +4 -4
- package/dist/utils/agent-execution/index.js.map +1 -1
- package/dist/utils/agent-execution/memoryManagement.js +15 -14
- package/dist/utils/agent-execution/memoryManagement.js.map +1 -1
- package/dist/utils/agent-execution/processEventStream.js +1 -47
- package/dist/utils/agent-execution/processEventStream.js.map +1 -1
- package/dist/utils/agent-execution/types.js.map +1 -1
- package/dist/utils/fromAIToolFactory.js +61 -0
- package/dist/utils/fromAIToolFactory.js.map +1 -0
- package/dist/utils/helpers.js +1 -1
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/logWrapper.js.map +1 -1
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js +1 -1
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js.map +1 -1
- package/package.json +31 -30
|
@@ -21,8 +21,8 @@ __export(OpenAiAssistant_node_exports, {
|
|
|
21
21
|
OpenAiAssistant: () => OpenAiAssistant
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(OpenAiAssistant_node_exports);
|
|
24
|
-
var import_agents = require("langchain/agents");
|
|
25
|
-
var import_openai_assistant = require("langchain/experimental/openai_assistant");
|
|
24
|
+
var import_agents = require("@langchain/classic/agents");
|
|
25
|
+
var import_openai_assistant = require("@langchain/classic/experimental/openai_assistant");
|
|
26
26
|
var import_n8n_workflow = require("n8n-workflow");
|
|
27
27
|
var import_openai = require("openai");
|
|
28
28
|
var import_helpers = require("../../../utils/helpers");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/agents/OpenAiAssistant/OpenAiAssistant.node.ts"],"sourcesContent":["import { AgentExecutor } from 'langchain/agents';\nimport type { OpenAIToolType } from 'langchain/dist/experimental/openai_assistant/schema';\nimport { OpenAIAssistantRunnable } from 'langchain/experimental/openai_assistant';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\nimport { OpenAI as OpenAIClient } from 'openai';\n\nimport { getConnectedTools } from '@utils/helpers';\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { formatToOpenAIAssistantTool } from './utils';\n\nexport class OpenAiAssistant implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'OpenAI Assistant',\n\t\tname: 'openAiAssistant',\n\t\thidden: true,\n\t\ticon: 'fa:robot',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Utilizes Assistant API from Open AI.',\n\t\tsubtitle: 'Open AI Assistant',\n\t\tdefaults: {\n\t\t\tname: 'OpenAI Assistant',\n\t\t\tcolor: '#404040',\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: ['Agents', '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.openaiassistant/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [\n\t\t\t{ type: NodeConnectionTypes.Main },\n\t\t\t{ type: NodeConnectionTypes.AiTool, displayName: 'Tools' },\n\t\t],\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'openAiApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\trequestDefaults: {\n\t\t\tignoreHttpStatusErrors: true,\n\t\t\tbaseURL:\n\t\t\t\t'={{ $parameter.options?.baseURL?.split(\"/\").slice(0,-1).join(\"/\") || \"https://api.openai.com\" }}',\n\t\t},\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Operation',\n\t\t\t\tname: 'mode',\n\t\t\t\ttype: 'options',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'existing',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Use New Assistant',\n\t\t\t\t\t\tvalue: 'new',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Use Existing Assistant',\n\t\t\t\t\t\tvalue: 'existing',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Name',\n\t\t\t\tname: 'name',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/mode': ['new'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Instructions',\n\t\t\t\tname: 'instructions',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'How the Assistant and model should behave or respond',\n\t\t\t\tdefault: '',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 5,\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/mode': ['new'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tname: 'model',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription:\n\t\t\t\t\t'The model which will be used to power the assistant. <a href=\"https://beta.openai.com/docs/models/overview\">Learn more</a>. The Retrieval tool requires gpt-3.5-turbo-1106 and gpt-4-1106-preview models.',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/mode': ['new'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptions: {\n\t\t\t\t\t\trouting: {\n\t\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t\t\t\turl: '={{ $parameter.options?.baseURL?.split(\"/\").slice(-1).pop() || \"v1\" }}/models',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\t\tpostReceive: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'rootProperty',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tproperty: 'data',\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'filter',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tpass: \"={{ $responseItem.id.startsWith('gpt-') && !$responseItem.id.includes('instruct') }}\",\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'setKeyValue',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tname: '={{$responseItem.id}}',\n\t\t\t\t\t\t\t\t\t\t\tvalue: '={{$responseItem.id}}',\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'sort',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tkey: 'name',\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\trouting: {\n\t\t\t\t\tsend: {\n\t\t\t\t\t\ttype: 'body',\n\t\t\t\t\t\tproperty: 'model',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tdefault: 'gpt-3.5-turbo-1106',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Assistant',\n\t\t\t\tname: 'assistantId',\n\t\t\t\ttype: 'options',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/mode': ['existing'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tdescription:\n\t\t\t\t\t'The assistant to use. <a href=\"https://beta.openai.com/docs/assistants/overview\">Learn more</a>.',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptions: {\n\t\t\t\t\t\trouting: {\n\t\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t\t'OpenAI-Beta': 'assistants=v1',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\turl: '={{ $parameter.options?.baseURL?.split(\"/\").slice(-1).pop() || \"v1\" }}/assistants',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\t\tpostReceive: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'rootProperty',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tproperty: 'data',\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'setKeyValue',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tname: '={{$responseItem.name}}',\n\t\t\t\t\t\t\t\t\t\t\tvalue: '={{$responseItem.id}}',\n\n\t\t\t\t\t\t\t\t\t\t\tdescription: '={{$responseItem.model}}',\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'sort',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tkey: 'name',\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\trouting: {\n\t\t\t\t\tsend: {\n\t\t\t\t\t\ttype: 'body',\n\t\t\t\t\t\tproperty: 'assistant',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Text',\n\t\t\t\tname: 'text',\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],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Text',\n\t\t\t\tname: 'text',\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.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: 'OpenAI Tools',\n\t\t\t\tname: 'nativeTools',\n\t\t\t\ttype: 'multiOptions',\n\t\t\t\tdefault: [],\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Code Interpreter',\n\t\t\t\t\t\tvalue: 'code_interpreter',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Knowledge Retrieval',\n\t\t\t\t\t\tvalue: 'retrieval',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Connect your own custom tools to this node on the canvas',\n\t\t\t\tname: 'noticeTools',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t'Upload files for retrieval using the <a href=\"https://platform.openai.com/playground\" target=\"_blank\">OpenAI website<a/>',\n\t\t\t\tname: 'noticeTools',\n\t\t\t\ttype: 'notice',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tnoticeTheme: 'info',\n\t\t\t\t},\n\t\t\t\tdisplayOptions: { show: { '/nativeTools': ['retrieval'] } },\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Base URL',\n\t\t\t\t\t\tname: 'baseURL',\n\t\t\t\t\t\tdefault: 'https://api.openai.com/v1',\n\t\t\t\t\t\tdescription: 'Override the default base URL for the API',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Max Retries',\n\t\t\t\t\t\tname: 'maxRetries',\n\t\t\t\t\t\tdefault: 2,\n\t\t\t\t\t\tdescription: 'Maximum number of retries to attempt',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Timeout',\n\t\t\t\t\t\tname: 'timeout',\n\t\t\t\t\t\tdefault: 10000,\n\t\t\t\t\t\tdescription: 'Maximum amount of time a request is allowed to take in milliseconds',\n\t\t\t\t\t\ttype: 'number',\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\tconst nodeVersion = this.getNode().typeVersion;\n\t\tconst tools = await getConnectedTools(this, nodeVersion > 1, false);\n\t\tconst credentials = await this.getCredentials('openAiApi');\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 input = this.getNodeParameter('text', itemIndex) as string;\n\t\t\t\tconst assistantId = this.getNodeParameter('assistantId', itemIndex, '') as string;\n\t\t\t\tconst nativeTools = this.getNodeParameter('nativeTools', itemIndex, []) as Array<\n\t\t\t\t\t'code_interpreter' | 'retrieval'\n\t\t\t\t>;\n\n\t\t\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\t\t\tbaseURL?: string;\n\t\t\t\t\tmaxRetries: number;\n\t\t\t\t\ttimeout: number;\n\t\t\t\t};\n\n\t\t\t\tif (input === undefined) {\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), 'The ‘text‘ parameter is empty.');\n\t\t\t\t}\n\n\t\t\t\tconst client = new OpenAIClient({\n\t\t\t\t\tapiKey: credentials.apiKey as string,\n\t\t\t\t\tmaxRetries: options.maxRetries ?? 2,\n\t\t\t\t\ttimeout: options.timeout ?? 10000,\n\t\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\t});\n\t\t\t\tlet agent;\n\t\t\t\tconst nativeToolsParsed: OpenAIToolType = nativeTools.map((tool) => ({ type: tool }));\n\t\t\t\tconst transformedConnectedTools = tools?.map(formatToOpenAIAssistantTool) ?? [];\n\t\t\t\tconst newTools = [...transformedConnectedTools, ...nativeToolsParsed];\n\n\t\t\t\t// Existing agent, update tools with currently assigned\n\t\t\t\tif (assistantId) {\n\t\t\t\t\tagent = new OpenAIAssistantRunnable({ assistantId, client, asAgent: true });\n\n\t\t\t\t\tawait client.beta.assistants.update(assistantId, {\n\t\t\t\t\t\ttools: newTools,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tconst name = this.getNodeParameter('name', itemIndex, '') as string;\n\t\t\t\t\tconst instructions = this.getNodeParameter('instructions', itemIndex, '') as string;\n\t\t\t\t\tconst model = this.getNodeParameter('model', itemIndex, 'gpt-3.5-turbo-1106') as string;\n\n\t\t\t\t\tagent = await OpenAIAssistantRunnable.createAssistant({\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tinstructions,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\ttools: newTools,\n\t\t\t\t\t\tasAgent: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst agentExecutor = AgentExecutor.fromAgentAndTools({\n\t\t\t\t\tagent,\n\t\t\t\t\ttools,\n\t\t\t\t});\n\n\t\t\t\tconst response = await agentExecutor.withConfig(getTracingConfig(this)).invoke({\n\t\t\t\t\tcontent: input,\n\t\t\t\t\tsignal: this.getExecutionCancelSignal(),\n\t\t\t\t\ttimeout: options.timeout ?? 10000,\n\t\t\t\t});\n\n\t\t\t\treturnData.push({ json: response });\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;AAAA,oBAA8B;AAE9B,8BAAwC;AACxC,0BAAwD;AAOxD,oBAAuC;AAEvC,qBAAkC;AAClC,qBAAiC;AAEjC,mBAA4C;AAErC,MAAM,gBAAqC;AAAA,EAA3C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,GAAG;AAAA,MAChB,aAAa;AAAA,MACb,UAAU;AAAA,MACV,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,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AEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":["OpenAIClient"]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/agents/OpenAiAssistant/OpenAiAssistant.node.ts"],"sourcesContent":["import { AgentExecutor } from '@langchain/classic/agents';\nimport type { OpenAIToolType } from '@langchain/classic/dist/experimental/openai_assistant/schema';\nimport { OpenAIAssistantRunnable } from '@langchain/classic/experimental/openai_assistant';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\nimport { OpenAI as OpenAIClient } from 'openai';\n\nimport { getConnectedTools } from '@utils/helpers';\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { formatToOpenAIAssistantTool } from './utils';\n\nexport class OpenAiAssistant implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'OpenAI Assistant',\n\t\tname: 'openAiAssistant',\n\t\thidden: true,\n\t\ticon: 'fa:robot',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Utilizes Assistant API from Open AI.',\n\t\tsubtitle: 'Open AI Assistant',\n\t\tdefaults: {\n\t\t\tname: 'OpenAI Assistant',\n\t\t\tcolor: '#404040',\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: ['Agents', '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.openaiassistant/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [\n\t\t\t{ type: NodeConnectionTypes.Main },\n\t\t\t{ type: NodeConnectionTypes.AiTool, displayName: 'Tools' },\n\t\t],\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'openAiApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\trequestDefaults: {\n\t\t\tignoreHttpStatusErrors: true,\n\t\t\tbaseURL:\n\t\t\t\t'={{ $parameter.options?.baseURL?.split(\"/\").slice(0,-1).join(\"/\") || \"https://api.openai.com\" }}',\n\t\t},\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Operation',\n\t\t\t\tname: 'mode',\n\t\t\t\ttype: 'options',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'existing',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Use New Assistant',\n\t\t\t\t\t\tvalue: 'new',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Use Existing Assistant',\n\t\t\t\t\t\tvalue: 'existing',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Name',\n\t\t\t\tname: 'name',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/mode': ['new'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Instructions',\n\t\t\t\tname: 'instructions',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'How the Assistant and model should behave or respond',\n\t\t\t\tdefault: '',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 5,\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/mode': ['new'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tname: 'model',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription:\n\t\t\t\t\t'The model which will be used to power the assistant. <a href=\"https://beta.openai.com/docs/models/overview\">Learn more</a>. The Retrieval tool requires gpt-3.5-turbo-1106 and gpt-4-1106-preview models.',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/mode': ['new'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptions: {\n\t\t\t\t\t\trouting: {\n\t\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t\t\t\turl: '={{ $parameter.options?.baseURL?.split(\"/\").slice(-1).pop() || \"v1\" }}/models',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\t\tpostReceive: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'rootProperty',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tproperty: 'data',\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'filter',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tpass: \"={{ $responseItem.id.startsWith('gpt-') && !$responseItem.id.includes('instruct') }}\",\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'setKeyValue',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tname: '={{$responseItem.id}}',\n\t\t\t\t\t\t\t\t\t\t\tvalue: '={{$responseItem.id}}',\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'sort',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tkey: 'name',\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\trouting: {\n\t\t\t\t\tsend: {\n\t\t\t\t\t\ttype: 'body',\n\t\t\t\t\t\tproperty: 'model',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tdefault: 'gpt-3.5-turbo-1106',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Assistant',\n\t\t\t\tname: 'assistantId',\n\t\t\t\ttype: 'options',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/mode': ['existing'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tdescription:\n\t\t\t\t\t'The assistant to use. <a href=\"https://beta.openai.com/docs/assistants/overview\">Learn more</a>.',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tloadOptions: {\n\t\t\t\t\t\trouting: {\n\t\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t\t'OpenAI-Beta': 'assistants=v1',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\turl: '={{ $parameter.options?.baseURL?.split(\"/\").slice(-1).pop() || \"v1\" }}/assistants',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\t\tpostReceive: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'rootProperty',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tproperty: 'data',\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'setKeyValue',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tname: '={{$responseItem.name}}',\n\t\t\t\t\t\t\t\t\t\t\tvalue: '={{$responseItem.id}}',\n\n\t\t\t\t\t\t\t\t\t\t\tdescription: '={{$responseItem.model}}',\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\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'sort',\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tkey: 'name',\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\trouting: {\n\t\t\t\t\tsend: {\n\t\t\t\t\t\ttype: 'body',\n\t\t\t\t\t\tproperty: 'assistant',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Text',\n\t\t\t\tname: 'text',\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],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Text',\n\t\t\t\tname: 'text',\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.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: 'OpenAI Tools',\n\t\t\t\tname: 'nativeTools',\n\t\t\t\ttype: 'multiOptions',\n\t\t\t\tdefault: [],\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Code Interpreter',\n\t\t\t\t\t\tvalue: 'code_interpreter',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Knowledge Retrieval',\n\t\t\t\t\t\tvalue: 'retrieval',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Connect your own custom tools to this node on the canvas',\n\t\t\t\tname: 'noticeTools',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t'Upload files for retrieval using the <a href=\"https://platform.openai.com/playground\" target=\"_blank\">OpenAI website<a/>',\n\t\t\t\tname: 'noticeTools',\n\t\t\t\ttype: 'notice',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tnoticeTheme: 'info',\n\t\t\t\t},\n\t\t\t\tdisplayOptions: { show: { '/nativeTools': ['retrieval'] } },\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Base URL',\n\t\t\t\t\t\tname: 'baseURL',\n\t\t\t\t\t\tdefault: 'https://api.openai.com/v1',\n\t\t\t\t\t\tdescription: 'Override the default base URL for the API',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Max Retries',\n\t\t\t\t\t\tname: 'maxRetries',\n\t\t\t\t\t\tdefault: 2,\n\t\t\t\t\t\tdescription: 'Maximum number of retries to attempt',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Timeout',\n\t\t\t\t\t\tname: 'timeout',\n\t\t\t\t\t\tdefault: 10000,\n\t\t\t\t\t\tdescription: 'Maximum amount of time a request is allowed to take in milliseconds',\n\t\t\t\t\t\ttype: 'number',\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\tconst nodeVersion = this.getNode().typeVersion;\n\t\tconst tools = await getConnectedTools(this, nodeVersion > 1, false);\n\t\tconst credentials = await this.getCredentials('openAiApi');\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 input = this.getNodeParameter('text', itemIndex) as string;\n\t\t\t\tconst assistantId = this.getNodeParameter('assistantId', itemIndex, '') as string;\n\t\t\t\tconst nativeTools = this.getNodeParameter('nativeTools', itemIndex, []) as Array<\n\t\t\t\t\t'code_interpreter' | 'retrieval'\n\t\t\t\t>;\n\n\t\t\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\t\t\tbaseURL?: string;\n\t\t\t\t\tmaxRetries: number;\n\t\t\t\t\ttimeout: number;\n\t\t\t\t};\n\n\t\t\t\tif (input === undefined) {\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), 'The ‘text‘ parameter is empty.');\n\t\t\t\t}\n\n\t\t\t\tconst client = new OpenAIClient({\n\t\t\t\t\tapiKey: credentials.apiKey as string,\n\t\t\t\t\tmaxRetries: options.maxRetries ?? 2,\n\t\t\t\t\ttimeout: options.timeout ?? 10000,\n\t\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\t});\n\t\t\t\tlet agent;\n\t\t\t\tconst nativeToolsParsed: OpenAIToolType = nativeTools.map((tool) => ({ type: tool }));\n\t\t\t\tconst transformedConnectedTools = tools?.map(formatToOpenAIAssistantTool) ?? [];\n\t\t\t\tconst newTools = [...transformedConnectedTools, ...nativeToolsParsed];\n\n\t\t\t\t// Existing agent, update tools with currently assigned\n\t\t\t\tif (assistantId) {\n\t\t\t\t\tagent = new OpenAIAssistantRunnable({ assistantId, client, asAgent: true });\n\n\t\t\t\t\tawait client.beta.assistants.update(assistantId, {\n\t\t\t\t\t\ttools: newTools,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tconst name = this.getNodeParameter('name', itemIndex, '') as string;\n\t\t\t\t\tconst instructions = this.getNodeParameter('instructions', itemIndex, '') as string;\n\t\t\t\t\tconst model = this.getNodeParameter('model', itemIndex, 'gpt-3.5-turbo-1106') as string;\n\n\t\t\t\t\tagent = await OpenAIAssistantRunnable.createAssistant({\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tinstructions,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\ttools: newTools,\n\t\t\t\t\t\tasAgent: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst agentExecutor = AgentExecutor.fromAgentAndTools({\n\t\t\t\t\tagent,\n\t\t\t\t\ttools,\n\t\t\t\t});\n\n\t\t\t\tconst response = await agentExecutor.withConfig(getTracingConfig(this)).invoke({\n\t\t\t\t\tcontent: input,\n\t\t\t\t\tsignal: this.getExecutionCancelSignal(),\n\t\t\t\t\ttimeout: options.timeout ?? 10000,\n\t\t\t\t});\n\n\t\t\t\treturnData.push({ json: response });\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":";;;;;;;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WAAW,oBAAoB;AAE5E,kBAAQ,MAAM,gDAAwB,gBAAgB;AAAA,YACrD;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,OAAO;AAAA,YACP,SAAS;AAAA,UACV,CAAC;AAAA,QACF;AAEA,cAAM,gBAAgB,4BAAc,kBAAkB;AAAA,UACrD;AAAA,UACA;AAAA,QACD,CAAC;AAED,cAAM,WAAW,MAAM,cAAc,eAAW,iCAAiB,IAAI,CAAC,EAAE,OAAO;AAAA,UAC9E,SAAS;AAAA,UACT,QAAQ,KAAK,yBAAyB;AAAA,UACtC,SAAS,QAAQ,WAAW;AAAA,QAC7B,CAAC;AAED,mBAAW,KAAK,EAAE,MAAM,SAAS,CAAC;AAAA,MACnC,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":["OpenAIClient"]}
|
|
@@ -22,8 +22,8 @@ __export(processItem_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(processItem_exports);
|
|
24
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");
|
|
25
|
+
var import_combine_documents = require("@langchain/classic/chains/combine_documents");
|
|
26
|
+
var import_retrieval = require("@langchain/classic/chains/retrieval");
|
|
27
27
|
var import_n8n_workflow = require("n8n-workflow");
|
|
28
28
|
var import_helpers = require("../../../utils/helpers");
|
|
29
29
|
var import_tracing = require("../../../utils/tracing");
|
|
@@ -1 +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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+
{"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/classic/chains/combine_documents';\nimport { createRetrievalChain } from '@langchain/classic/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,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AE,OAAO,MAAM,GAAG,EAAE,QAAQ,IAAI,yBAAyB,EAAE,CAAC;AACtE;","names":[]}
|
|
@@ -22,7 +22,7 @@ __export(ChainSummarizationV1_node_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(ChainSummarizationV1_node_exports);
|
|
24
24
|
var import_prompts = require("@langchain/core/prompts");
|
|
25
|
-
var import_chains = require("langchain/chains");
|
|
25
|
+
var import_chains = require("@langchain/classic/chains");
|
|
26
26
|
var import_n8n_workflow = require("n8n-workflow");
|
|
27
27
|
var import_N8nBinaryLoader = require("../../../../utils/N8nBinaryLoader");
|
|
28
28
|
var import_N8nJsonLoader = require("../../../../utils/N8nJsonLoader");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.ts"],"sourcesContent":["import type { Document } from '@langchain/core/documents';\nimport type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { PromptTemplate } from '@langchain/core/prompts';\nimport type { SummarizationChainParams } from 'langchain/chains';\nimport { loadSummarizationChain } from 'langchain/chains';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeTypeBaseDescription,\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n} from 'n8n-workflow';\n\nimport { N8nBinaryLoader } from '@utils/N8nBinaryLoader';\nimport { N8nJsonLoader } from '@utils/N8nJsonLoader';\nimport { getTemplateNoticeField } from '@utils/sharedFields';\n\nimport { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt';\n\nexport class ChainSummarizationV1 implements INodeType {\n\tdescription: INodeTypeDescription;\n\n\tconstructor(baseDescription: INodeTypeBaseDescription) {\n\t\tthis.description = {\n\t\t\t...baseDescription,\n\t\t\tversion: 1,\n\t\t\tdefaults: {\n\t\t\t\tname: 'Summarization Chain',\n\t\t\t\tcolor: '#909298',\n\t\t\t},\n\n\t\t\tinputs: [\n\t\t\t\tNodeConnectionTypes.Main,\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Model',\n\t\t\t\t\tmaxConnections: 1,\n\t\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Document',\n\t\t\t\t\tmaxConnections: 1,\n\t\t\t\t\ttype: NodeConnectionTypes.AiDocument,\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t],\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: 'Type',\n\t\t\t\t\tname: 'type',\n\t\t\t\t\ttype: 'options',\n\t\t\t\t\tdescription: 'The type of summarization to run',\n\t\t\t\t\tdefault: 'map_reduce',\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Map Reduce (Recommended)',\n\t\t\t\t\t\t\tvalue: 'map_reduce',\n\t\t\t\t\t\t\tdescription:\n\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},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Refine',\n\t\t\t\t\t\t\tvalue: 'refine',\n\t\t\t\t\t\t\tdescription:\n\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},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Stuff',\n\t\t\t\t\t\t\tvalue: 'stuff',\n\t\t\t\t\t\t\tdescription: 'Pass all documents (or chunks) at once. Ideal for small datasets.',\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: 'Final Prompt to Combine',\n\t\t\t\t\t\t\tname: 'combineMapPrompt',\n\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\thint: 'The prompt to combine individual summaries',\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'/type': ['map_reduce'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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: 'Individual Summary Prompt',\n\t\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\thint: 'The prompt to summarize an individual document (or chunk)',\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'/type': ['map_reduce'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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: 'Prompt',\n\t\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\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'/type': ['stuff'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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: 'Subsequent (Refine) Prompt',\n\t\t\t\t\t\t\tname: 'refinePrompt',\n\t\t\t\t\t\t\ttype: 'string',\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'/type': ['refine'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdefault: REFINE_PROMPT_TEMPLATE,\n\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\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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: 'Initial Prompt',\n\t\t\t\t\t\t\tname: 'refineQuestionPrompt',\n\t\t\t\t\t\t\ttype: 'string',\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'/type': ['refine'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\thint: 'The prompt for the first document (or chunk)',\n\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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 Vector Store QA Chain');\n\t\tconst type = this.getNodeParameter('type', 0) as 'map_reduce' | 'stuff' | 'refine';\n\n\t\tconst model = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t0,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst documentInput = (await this.getInputConnectionData(NodeConnectionTypes.AiDocument, 0)) as\n\t\t\t| N8nJsonLoader\n\t\t\t| Array<Document<Record<string, unknown>>>;\n\n\t\tconst options = this.getNodeParameter('options', 0, {}) as {\n\t\t\tprompt?: string;\n\t\t\trefineQuestionPrompt?: string;\n\t\t\trefinePrompt?: string;\n\t\t\tcombineMapPrompt?: string;\n\t\t};\n\n\t\tconst chainArgs: SummarizationChainParams = {\n\t\t\ttype,\n\t\t};\n\n\t\t// Map reduce prompt override\n\t\tif (type === 'map_reduce') {\n\t\t\tconst mapReduceArgs = chainArgs as SummarizationChainParams & {\n\t\t\t\ttype: 'map_reduce';\n\t\t\t};\n\t\t\tif (options.combineMapPrompt) {\n\t\t\t\tmapReduceArgs.combineMapPrompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.combineMapPrompt,\n\t\t\t\t\tinputVariables: ['text'],\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (options.prompt) {\n\t\t\t\tmapReduceArgs.combinePrompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.prompt,\n\t\t\t\t\tinputVariables: ['text'],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Stuff prompt override\n\t\tif (type === 'stuff') {\n\t\t\tconst stuffArgs = chainArgs as SummarizationChainParams & {\n\t\t\t\ttype: 'stuff';\n\t\t\t};\n\t\t\tif (options.prompt) {\n\t\t\t\tstuffArgs.prompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.prompt,\n\t\t\t\t\tinputVariables: ['text'],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Refine prompt override\n\t\tif (type === 'refine') {\n\t\t\tconst refineArgs = chainArgs as SummarizationChainParams & {\n\t\t\t\ttype: 'refine';\n\t\t\t};\n\n\t\t\tif (options.refinePrompt) {\n\t\t\t\trefineArgs.refinePrompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.refinePrompt,\n\t\t\t\t\tinputVariables: ['existing_answer', 'text'],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (options.refineQuestionPrompt) {\n\t\t\t\trefineArgs.questionPrompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.refineQuestionPrompt,\n\t\t\t\t\tinputVariables: ['text'],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst chain = loadSummarizationChain(model, chainArgs);\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\tlet processedDocuments: Document[];\n\t\t\tif (documentInput instanceof N8nJsonLoader || documentInput instanceof N8nBinaryLoader) {\n\t\t\t\tprocessedDocuments = await documentInput.processItem(items[itemIndex], itemIndex);\n\t\t\t} else {\n\t\t\t\tprocessedDocuments = documentInput;\n\t\t\t}\n\n\t\t\tconst response = await chain.call({\n\t\t\t\tinput_documents: processedDocuments,\n\t\t\t});\n\n\t\t\treturnData.push({ json: { response } });\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA+B;AAE/B,oBAAuC;AACvC,0BAOO;AAEP,6BAAgC;AAChC,2BAA8B;AAC9B,0BAAuC;AAEvC,oBAAgE;AAEzD,MAAM,qBAA0C;AAAA,EAGtD,YAAY,iBAA2C;AACtD,SAAK,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,SAAS;AAAA,MACT,UAAU;AAAA,QACT,MAAM;AAAA,QACN,OAAO;AAAA,MACR;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,a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ources":["../../../../../nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.ts"],"sourcesContent":["import type { Document } from '@langchain/core/documents';\nimport type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { PromptTemplate } from '@langchain/core/prompts';\nimport type { SummarizationChainParams } from '@langchain/classic/chains';\nimport { loadSummarizationChain } from '@langchain/classic/chains';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeTypeBaseDescription,\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n} from 'n8n-workflow';\n\nimport { N8nBinaryLoader } from '@utils/N8nBinaryLoader';\nimport { N8nJsonLoader } from '@utils/N8nJsonLoader';\nimport { getTemplateNoticeField } from '@utils/sharedFields';\n\nimport { REFINE_PROMPT_TEMPLATE, DEFAULT_PROMPT_TEMPLATE } from '../prompt';\n\nexport class ChainSummarizationV1 implements INodeType {\n\tdescription: INodeTypeDescription;\n\n\tconstructor(baseDescription: INodeTypeBaseDescription) {\n\t\tthis.description = {\n\t\t\t...baseDescription,\n\t\t\tversion: 1,\n\t\t\tdefaults: {\n\t\t\t\tname: 'Summarization Chain',\n\t\t\t\tcolor: '#909298',\n\t\t\t},\n\n\t\t\tinputs: [\n\t\t\t\tNodeConnectionTypes.Main,\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Model',\n\t\t\t\t\tmaxConnections: 1,\n\t\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Document',\n\t\t\t\t\tmaxConnections: 1,\n\t\t\t\t\ttype: NodeConnectionTypes.AiDocument,\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t],\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: 'Type',\n\t\t\t\t\tname: 'type',\n\t\t\t\t\ttype: 'options',\n\t\t\t\t\tdescription: 'The type of summarization to run',\n\t\t\t\t\tdefault: 'map_reduce',\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Map Reduce (Recommended)',\n\t\t\t\t\t\t\tvalue: 'map_reduce',\n\t\t\t\t\t\t\tdescription:\n\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},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Refine',\n\t\t\t\t\t\t\tvalue: 'refine',\n\t\t\t\t\t\t\tdescription:\n\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},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'Stuff',\n\t\t\t\t\t\t\tvalue: 'stuff',\n\t\t\t\t\t\t\tdescription: 'Pass all documents (or chunks) at once. Ideal for small datasets.',\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: 'Final Prompt to Combine',\n\t\t\t\t\t\t\tname: 'combineMapPrompt',\n\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\thint: 'The prompt to combine individual summaries',\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'/type': ['map_reduce'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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: 'Individual Summary Prompt',\n\t\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\thint: 'The prompt to summarize an individual document (or chunk)',\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'/type': ['map_reduce'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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: 'Prompt',\n\t\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\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'/type': ['stuff'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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: 'Subsequent (Refine) Prompt',\n\t\t\t\t\t\t\tname: 'refinePrompt',\n\t\t\t\t\t\t\ttype: 'string',\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'/type': ['refine'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdefault: REFINE_PROMPT_TEMPLATE,\n\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\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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: 'Initial Prompt',\n\t\t\t\t\t\t\tname: 'refineQuestionPrompt',\n\t\t\t\t\t\t\ttype: 'string',\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'/type': ['refine'],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdefault: DEFAULT_PROMPT_TEMPLATE,\n\t\t\t\t\t\t\thint: 'The prompt for the first document (or chunk)',\n\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\trows: 6,\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 Vector Store QA Chain');\n\t\tconst type = this.getNodeParameter('type', 0) as 'map_reduce' | 'stuff' | 'refine';\n\n\t\tconst model = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t0,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst documentInput = (await this.getInputConnectionData(NodeConnectionTypes.AiDocument, 0)) as\n\t\t\t| N8nJsonLoader\n\t\t\t| Array<Document<Record<string, unknown>>>;\n\n\t\tconst options = this.getNodeParameter('options', 0, {}) as {\n\t\t\tprompt?: string;\n\t\t\trefineQuestionPrompt?: string;\n\t\t\trefinePrompt?: string;\n\t\t\tcombineMapPrompt?: string;\n\t\t};\n\n\t\tconst chainArgs: SummarizationChainParams = {\n\t\t\ttype,\n\t\t};\n\n\t\t// Map reduce prompt override\n\t\tif (type === 'map_reduce') {\n\t\t\tconst mapReduceArgs = chainArgs as SummarizationChainParams & {\n\t\t\t\ttype: 'map_reduce';\n\t\t\t};\n\t\t\tif (options.combineMapPrompt) {\n\t\t\t\tmapReduceArgs.combineMapPrompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.combineMapPrompt,\n\t\t\t\t\tinputVariables: ['text'],\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (options.prompt) {\n\t\t\t\tmapReduceArgs.combinePrompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.prompt,\n\t\t\t\t\tinputVariables: ['text'],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Stuff prompt override\n\t\tif (type === 'stuff') {\n\t\t\tconst stuffArgs = chainArgs as SummarizationChainParams & {\n\t\t\t\ttype: 'stuff';\n\t\t\t};\n\t\t\tif (options.prompt) {\n\t\t\t\tstuffArgs.prompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.prompt,\n\t\t\t\t\tinputVariables: ['text'],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Refine prompt override\n\t\tif (type === 'refine') {\n\t\t\tconst refineArgs = chainArgs as SummarizationChainParams & {\n\t\t\t\ttype: 'refine';\n\t\t\t};\n\n\t\t\tif (options.refinePrompt) {\n\t\t\t\trefineArgs.refinePrompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.refinePrompt,\n\t\t\t\t\tinputVariables: ['existing_answer', 'text'],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (options.refineQuestionPrompt) {\n\t\t\t\trefineArgs.questionPrompt = new PromptTemplate({\n\t\t\t\t\ttemplate: options.refineQuestionPrompt,\n\t\t\t\t\tinputVariables: ['text'],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst chain = loadSummarizationChain(model, chainArgs);\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\tlet processedDocuments: Document[];\n\t\t\tif (documentInput instanceof N8nJsonLoader || documentInput instanceof N8nBinaryLoader) {\n\t\t\t\tprocessedDocuments = await documentInput.processItem(items[itemIndex], itemIndex);\n\t\t\t} else {\n\t\t\t\tprocessedDocuments = documentInput;\n\t\t\t}\n\n\t\t\tconst response = await chain.call({\n\t\t\t\tinput_documents: processedDocuments,\n\t\t\t});\n\n\t\t\treturnData.push({ json: { response } });\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA+B;AAE/B,oBAAuC;AACvC,0BAOO;AAEP,6BAAgC;AAChC,2BAA8B;AAC9B,0BAAuC;AAEvC,oBAAgE;AAEzD,MAAM,qBAA0C;AAAA,EAGtD,YAAY,iBAA2C;AACtD,SAAK,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,SAAS;AAAA,MACT,UAAU;AAAA,QACT,MAAM;AAAA,QACN,OAAO;AAAA,MACR;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,IAAI;AAAA,MAClC,aAAa,CAAC;AAAA,MACd,YAAY;AAAA,YACX,4CAAuB,IAAI;AAAA,QAC3B;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,aAAa;AAAA,UACb,SAAS;AAAA,UACT,SAAS;AAAA,YACR;AAAA,cACC,MAAM;AAAA,cACN,OAAO;AAAA,cACP,aACC;AAAA,YACF;AAAA,YACA;AAAA,cACC,MAAM;AAAA,cACN,OAAO;AAAA,cACP,aACC;AAAA,YACF;AAAA,YACA;AAAA,cACC,MA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QAAQ;AAAA,UAClB,gBAAgB,CAAC,mBAAmB,MAAM;AAAA,QAC3C,CAAC;AAAA,MACF;AAEA,UAAI,QAAQ,sBAAsB;AACjC,mBAAW,iBAAiB,IAAI,8BAAe;AAAA,UAC9C,UAAU,QAAQ;AAAA,UAClB,gBAAgB,CAAC,MAAM;AAAA,QACxB,CAAC;AAAA,MACF;AAAA,IACD;AAEA,UAAM,YAAQ,sCAAuB,OAAO,SAAS;AAErD,UAAM,QAAQ,KAAK,aAAa;AAChC,UAAM,aAAmC,CAAC;AAE1C,aAAS,YAAY,GAAG,YAAY,MAAM,QAAQ,aAAa;AAC9D,UAAI;AACJ,UAAI,yBAAyB,sCAAiB,yBAAyB,wCAAiB;AACvF,6BAAqB,MAAM,cAAc,YAAY,MAAM,SAAS,GAAG,SAAS;AAAA,MACjF,OAAO;AACN,6BAAqB;AAAA,MACtB;AAEA,YAAM,WAAW,MAAM,MAAM,KAAK;AAAA,QACjC,iBAAiB;AAAA,MAClB,CAAC;AAED,iBAAW,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAAA,IACvC;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
@@ -22,7 +22,7 @@ __export(processItem_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(processItem_exports);
|
|
24
24
|
var import_textsplitters = require("@langchain/textsplitters");
|
|
25
|
-
var import_chains = require("langchain/chains");
|
|
25
|
+
var import_chains = require("@langchain/classic/chains");
|
|
26
26
|
var import_n8n_workflow = require("n8n-workflow");
|
|
27
27
|
var import_N8nBinaryLoader = require("../../../../utils/N8nBinaryLoader");
|
|
28
28
|
var import_N8nJsonLoader = require("../../../../utils/N8nJsonLoader");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../nodes/chains/ChainSummarization/V2/processItem.ts"],"sourcesContent":["import type { Document } from '@langchain/core/documents';\nimport type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { ChainValues } from '@langchain/core/utils/types';\nimport { RecursiveCharacterTextSplitter, type TextSplitter } from '@langchain/textsplitters';\nimport { loadSummarizationChain } from 'langchain/chains';\nimport { type IExecuteFunctions, type INodeExecutionData, NodeConnectionTypes } from 'n8n-workflow';\n\nimport { N8nBinaryLoader } from '@utils/N8nBinaryLoader';\nimport { N8nJsonLoader } from '@utils/N8nJsonLoader';\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { getChainPromptsArgs } from '../helpers';\n\nexport async function processItem(\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n\titem: INodeExecutionData,\n\toperationMode: string,\n\tchunkingMode: 'simple' | 'advanced' | 'none',\n): Promise<ChainValues | undefined> {\n\tconst model = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t0,\n\t)) as BaseLanguageModel;\n\n\tconst summarizationMethodAndPrompts = ctx.getNodeParameter(\n\t\t'options.summarizationMethodAndPrompts.values',\n\t\titemIndex,\n\t\t{},\n\t) as {\n\t\tprompt?: string;\n\t\trefineQuestionPrompt?: string;\n\t\trefinePrompt?: string;\n\t\tsummarizationMethod: 'map_reduce' | 'stuff' | 'refine';\n\t\tcombineMapPrompt?: string;\n\t};\n\n\tconst chainArgs = getChainPromptsArgs(\n\t\tsummarizationMethodAndPrompts.summarizationMethod ?? 'map_reduce',\n\t\tsummarizationMethodAndPrompts,\n\t);\n\n\tconst chain = loadSummarizationChain(model, chainArgs);\n\n\tlet processedDocuments: Document[];\n\n\t// Use dedicated document loader input to load documents\n\tif (operationMode === 'documentLoader') {\n\t\tconst documentInput = (await ctx.getInputConnectionData(NodeConnectionTypes.AiDocument, 0)) as\n\t\t\t| N8nJsonLoader\n\t\t\t| Array<Document<Record<string, unknown>>>;\n\n\t\tconst isN8nLoader =\n\t\t\tdocumentInput instanceof N8nJsonLoader || documentInput instanceof N8nBinaryLoader;\n\n\t\tprocessedDocuments = isN8nLoader\n\t\t\t? await documentInput.processItem(item, itemIndex)\n\t\t\t: documentInput;\n\n\t\treturn await chain.withConfig(getTracingConfig(ctx)).invoke({\n\t\t\tinput_documents: processedDocuments,\n\t\t});\n\t} else if (['nodeInputJson', 'nodeInputBinary'].includes(operationMode)) {\n\t\t// Take the input and use binary or json loader\n\t\tlet textSplitter: TextSplitter | undefined;\n\n\t\tswitch (chunkingMode) {\n\t\t\t// In simple mode we use recursive character splitter with default settings\n\t\t\tcase 'simple':\n\t\t\t\tconst chunkSize = ctx.getNodeParameter('chunkSize', itemIndex, 1000) as number;\n\t\t\t\tconst chunkOverlap = ctx.getNodeParameter('chunkOverlap', itemIndex, 200) as number;\n\n\t\t\t\ttextSplitter = new RecursiveCharacterTextSplitter({ chunkOverlap, chunkSize });\n\t\t\t\tbreak;\n\n\t\t\t// In advanced mode user can connect text splitter node so we just retrieve it\n\t\t\tcase 'advanced':\n\t\t\t\ttextSplitter = (await ctx.getInputConnectionData(NodeConnectionTypes.AiTextSplitter, 0)) as\n\t\t\t\t\t| TextSplitter\n\t\t\t\t\t| undefined;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tlet processor: N8nJsonLoader | N8nBinaryLoader;\n\t\tif (operationMode === 'nodeInputBinary') {\n\t\t\tconst binaryDataKey = ctx.getNodeParameter(\n\t\t\t\t'options.binaryDataKey',\n\t\t\t\titemIndex,\n\t\t\t\t'data',\n\t\t\t) as string;\n\t\t\tprocessor = new N8nBinaryLoader(ctx, 'options.', binaryDataKey, textSplitter);\n\t\t} else {\n\t\t\tprocessor = new N8nJsonLoader(ctx, 'options.', textSplitter);\n\t\t}\n\n\t\tconst processedItem = await processor.processItem(item, itemIndex);\n\t\treturn await chain.invoke(\n\t\t\t{\n\t\t\t\tinput_documents: processedItem,\n\t\t\t},\n\t\t\t{ signal: ctx.getExecutionCancelSignal() },\n\t\t);\n\t}\n\treturn undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AA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AACA,kBAAY,IAAI,uCAAgB,KAAK,YAAY,eAAe,YAAY;AAAA,IAC7E,OAAO;AACN,kBAAY,IAAI,mCAAc,KAAK,YAAY,YAAY;AAAA,IAC5D;AAEA,UAAM,gBAAgB,MAAM,UAAU,YAAY,MAAM,SAAS;AACjE,WAAO,MAAM,MAAM;AAAA,MAClB;AAAA,QACC,iBAAiB;AAAA,MAClB;AAAA,MACA,EAAE,QAAQ,IAAI,yBAAyB,EAAE;AAAA,IAC1C;AAAA,EACD;AACA,SAAO;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainSummarization/V2/processItem.ts"],"sourcesContent":["import type { Document } from '@langchain/core/documents';\nimport type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { ChainValues } from '@langchain/core/utils/types';\nimport { RecursiveCharacterTextSplitter, type TextSplitter } from '@langchain/textsplitters';\nimport { loadSummarizationChain } from '@langchain/classic/chains';\nimport { type IExecuteFunctions, type INodeExecutionData, NodeConnectionTypes } from 'n8n-workflow';\n\nimport { N8nBinaryLoader } from '@utils/N8nBinaryLoader';\nimport { N8nJsonLoader } from '@utils/N8nJsonLoader';\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { getChainPromptsArgs } from '../helpers';\n\nexport async function processItem(\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n\titem: INodeExecutionData,\n\toperationMode: string,\n\tchunkingMode: 'simple' | 'advanced' | 'none',\n): Promise<ChainValues | undefined> {\n\tconst model = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t0,\n\t)) as BaseLanguageModel;\n\n\tconst summarizationMethodAndPrompts = ctx.getNodeParameter(\n\t\t'options.summarizationMethodAndPrompts.values',\n\t\titemIndex,\n\t\t{},\n\t) as {\n\t\tprompt?: string;\n\t\trefineQuestionPrompt?: string;\n\t\trefinePrompt?: string;\n\t\tsummarizationMethod: 'map_reduce' | 'stuff' | 'refine';\n\t\tcombineMapPrompt?: string;\n\t};\n\n\tconst chainArgs = getChainPromptsArgs(\n\t\tsummarizationMethodAndPrompts.summarizationMethod ?? 'map_reduce',\n\t\tsummarizationMethodAndPrompts,\n\t);\n\n\tconst chain = loadSummarizationChain(model, chainArgs);\n\n\tlet processedDocuments: Document[];\n\n\t// Use dedicated document loader input to load documents\n\tif (operationMode === 'documentLoader') {\n\t\tconst documentInput = (await ctx.getInputConnectionData(NodeConnectionTypes.AiDocument, 0)) as\n\t\t\t| N8nJsonLoader\n\t\t\t| Array<Document<Record<string, unknown>>>;\n\n\t\tconst isN8nLoader =\n\t\t\tdocumentInput instanceof N8nJsonLoader || documentInput instanceof N8nBinaryLoader;\n\n\t\tprocessedDocuments = isN8nLoader\n\t\t\t? await documentInput.processItem(item, itemIndex)\n\t\t\t: documentInput;\n\n\t\treturn await chain.withConfig(getTracingConfig(ctx)).invoke({\n\t\t\tinput_documents: processedDocuments,\n\t\t});\n\t} else if (['nodeInputJson', 'nodeInputBinary'].includes(operationMode)) {\n\t\t// Take the input and use binary or json loader\n\t\tlet textSplitter: TextSplitter | undefined;\n\n\t\tswitch (chunkingMode) {\n\t\t\t// In simple mode we use recursive character splitter with default settings\n\t\t\tcase 'simple':\n\t\t\t\tconst chunkSize = ctx.getNodeParameter('chunkSize', itemIndex, 1000) as number;\n\t\t\t\tconst chunkOverlap = ctx.getNodeParameter('chunkOverlap', itemIndex, 200) as number;\n\n\t\t\t\ttextSplitter = new RecursiveCharacterTextSplitter({ chunkOverlap, chunkSize });\n\t\t\t\tbreak;\n\n\t\t\t// In advanced mode user can connect text splitter node so we just retrieve it\n\t\t\tcase 'advanced':\n\t\t\t\ttextSplitter = (await ctx.getInputConnectionData(NodeConnectionTypes.AiTextSplitter, 0)) as\n\t\t\t\t\t| TextSplitter\n\t\t\t\t\t| undefined;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\n\t\tlet processor: N8nJsonLoader | N8nBinaryLoader;\n\t\tif (operationMode === 'nodeInputBinary') {\n\t\t\tconst binaryDataKey = ctx.getNodeParameter(\n\t\t\t\t'options.binaryDataKey',\n\t\t\t\titemIndex,\n\t\t\t\t'data',\n\t\t\t) as string;\n\t\t\tprocessor = new N8nBinaryLoader(ctx, 'options.', binaryDataKey, textSplitter);\n\t\t} else {\n\t\t\tprocessor = new N8nJsonLoader(ctx, 'options.', textSplitter);\n\t\t}\n\n\t\tconst processedItem = await processor.processItem(item, itemIndex);\n\t\treturn await chain.invoke(\n\t\t\t{\n\t\t\t\tinput_documents: processedItem,\n\t\t\t},\n\t\t\t{ signal: ctx.getExecutionCancelSignal() },\n\t\t);\n\t}\n\treturn undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAAkE;AAClE,oBAAuC;AACvC,0BAAqF;AAErF,6BAAgC;AAChC,2BAA8B;AAC9B,qBAAiC;AAEjC,qBAAoC;AAEpC,eAAsB,YACrB,KACA,WACA,MACA,eACA,cACmC;AACnC,QAAM,QAAS,MAAM,IAAI;AAAA,IACxB,wCAAoB;AAAA,IACpB;AAAA,EACD;AAEA,QAAM,gCAAgC,IAAI;AAAA,IACzC;AAAA,IACA;AAAA,IACA,CAAC;AAAA,EACF;AAQA,QAAM,gBAAY;AAAA,IACjB,8BAA8B,uBAAuB;AAAA,IACrD;AAAA,EACD;AAEA,QAAM,YAAQ,sCAAuB,OAAO,SAAS;AAErD,MAAI;AAGJ,MAAI,kBAAkB,kBAAkB;AACvC,UAAM,gBAAiB,MAAM,IAAI,uBAAuB,wCAAoB,YAAY,CAAC;AAIzF,UAAM,cACL,yBAAyB,sCAAiB,yBAAyB;AAEpE,yBAAqB,cAClB,MAAM,cAAc,YAAY,MAAM,SAAS,IAC/C;AAEH,WAAO,MAAM,MAAM,eAAW,iCAAiB,GAAG,CAAC,EAAE,OAAO;AAAA,MAC3D,iBAAiB;AAAA,IAClB,CAAC;AAAA,EACF,WAAW,CAAC,iBAAiB,iBAAiB,EAAE,SAAS,aAAa,GAAG;AAExE,QAAI;AAEJ,YAAQ,cAAc;AAAA;AAAA,MAErB,KAAK;AACJ,cAAM,YAAY,IAAI,iBAAiB,aAAa,WAAW,GAAI;AACnE,cAAM,eAAe,IAAI,iBAAiB,gBAAgB,WAAW,GAAG;AAExE,uBAAe,IAAI,oDAA+B,EAAE,cAAc,UAAU,CAAC;AAC7E;AAAA;AAAA,MAGD,KAAK;AACJ,uBAAgB,MAAM,IAAI,uBAAuB,wCAAoB,gBAAgB,CAAC;AAGtF;AAAA,MACD;AACC;AAAA,IACF;AAEA,QAAI;AACJ,QAAI,kBAAkB,mBAAmB;AACxC,YAAM,gBAAgB,IAAI;AAAA,QACzB;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,kBAAY,IAAI,uCAAgB,KAAK,YAAY,eAAe,YAAY;AAAA,IAC7E,OAAO;AACN,kBAAY,IAAI,mCAAc,KAAK,YAAY,YAAY;AAAA,IAC5D;AAEA,UAAM,gBAAgB,MAAM,UAAU,YAAY,MAAM,SAAS;AACjE,WAAO,MAAM,MAAM;AAAA,MAClB;AAAA,QACC,iBAAiB;AAAA,MAClB;AAAA,MACA,EAAE,QAAQ,IAAI,yBAAyB,EAAE;AAAA,IAC1C;AAAA,EACD;AACA,SAAO;AACR;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/chains/ChainSummarization/helpers.ts"],"sourcesContent":["import { PromptTemplate } from '@langchain/core/prompts';\nimport type { SummarizationChainParams } from 'langchain/chains';\ninterface ChainTypeOptions {\n\tcombineMapPrompt?: string;\n\tprompt?: string;\n\trefinePrompt?: string;\n\trefineQuestionPrompt?: string;\n}\n\nexport function getChainPromptsArgs(\n\ttype: 'stuff' | 'map_reduce' | 'refine',\n\toptions: ChainTypeOptions,\n) {\n\tconst chainArgs: SummarizationChainParams = {\n\t\ttype,\n\t};\n\t// Map reduce prompt override\n\tif (type === 'map_reduce') {\n\t\tconst mapReduceArgs = chainArgs as SummarizationChainParams & {\n\t\t\ttype: 'map_reduce';\n\t\t};\n\t\tif (options.combineMapPrompt) {\n\t\t\tmapReduceArgs.combineMapPrompt = new PromptTemplate({\n\t\t\t\ttemplate: options.combineMapPrompt,\n\t\t\t\tinputVariables: ['text'],\n\t\t\t});\n\t\t}\n\t\tif (options.prompt) {\n\t\t\tmapReduceArgs.combinePrompt = new PromptTemplate({\n\t\t\t\ttemplate: options.prompt,\n\t\t\t\tinputVariables: ['text'],\n\t\t\t});\n\t\t}\n\t}\n\n\t// Stuff prompt override\n\tif (type === 'stuff') {\n\t\tconst stuffArgs = chainArgs as SummarizationChainParams & {\n\t\t\ttype: 'stuff';\n\t\t};\n\t\tif (options.prompt) {\n\t\t\tstuffArgs.prompt = new PromptTemplate({\n\t\t\t\ttemplate: options.prompt,\n\t\t\t\tinputVariables: ['text'],\n\t\t\t});\n\t\t}\n\t}\n\n\t// Refine prompt override\n\tif (type === 'refine') {\n\t\tconst refineArgs = chainArgs as SummarizationChainParams & {\n\t\t\ttype: 'refine';\n\t\t};\n\n\t\tif (options.refinePrompt) {\n\t\t\trefineArgs.refinePrompt = new PromptTemplate({\n\t\t\t\ttemplate: options.refinePrompt,\n\t\t\t\tinputVariables: ['existing_answer', 'text'],\n\t\t\t});\n\t\t}\n\n\t\tif (options.refineQuestionPrompt) {\n\t\t\trefineArgs.questionPrompt = new PromptTemplate({\n\t\t\t\ttemplate: options.refineQuestionPrompt,\n\t\t\t\tinputVariables: ['text'],\n\t\t\t});\n\t\t}\n\t}\n\n\treturn chainArgs;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+B;AASxB,SAAS,oBACf,MACA,SACC;AACD,QAAM,YAAsC;AAAA,IAC3C;AAAA,EACD;AAEA,MAAI,SAAS,cAAc;AAC1B,UAAM,gBAAgB;AAGtB,QAAI,QAAQ,kBAAkB;AAC7B,oBAAc,mBAAmB,IAAI,8BAAe;AAAA,QACnD,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,MAAM;AAAA,MACxB,CAAC;AAAA,IACF;AACA,QAAI,QAAQ,QAAQ;AACnB,oBAAc,gBAAgB,IAAI,8BAAe;AAAA,QAChD,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,MAAM;AAAA,MACxB,CAAC;AAAA,IACF;AAAA,EACD;AAGA,MAAI,SAAS,SAAS;AACrB,UAAM,YAAY;AAGlB,QAAI,QAAQ,QAAQ;AACnB,gBAAU,SAAS,IAAI,8BAAe;AAAA,QACrC,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,MAAM;AAAA,MACxB,CAAC;AAAA,IACF;AAAA,EACD;AAGA,MAAI,SAAS,UAAU;AACtB,UAAM,aAAa;AAInB,QAAI,QAAQ,cAAc;AACzB,iBAAW,eAAe,IAAI,8BAAe;AAAA,QAC5C,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,mBAAmB,MAAM;AAAA,MAC3C,CAAC;AAAA,IACF;AAEA,QAAI,QAAQ,sBAAsB;AACjC,iBAAW,iBAAiB,IAAI,8BAAe;AAAA,QAC9C,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,MAAM;AAAA,MACxB,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainSummarization/helpers.ts"],"sourcesContent":["import { PromptTemplate } from '@langchain/core/prompts';\nimport type { SummarizationChainParams } from '@langchain/classic/chains';\ninterface ChainTypeOptions {\n\tcombineMapPrompt?: string;\n\tprompt?: string;\n\trefinePrompt?: string;\n\trefineQuestionPrompt?: string;\n}\n\nexport function getChainPromptsArgs(\n\ttype: 'stuff' | 'map_reduce' | 'refine',\n\toptions: ChainTypeOptions,\n) {\n\tconst chainArgs: SummarizationChainParams = {\n\t\ttype,\n\t};\n\t// Map reduce prompt override\n\tif (type === 'map_reduce') {\n\t\tconst mapReduceArgs = chainArgs as SummarizationChainParams & {\n\t\t\ttype: 'map_reduce';\n\t\t};\n\t\tif (options.combineMapPrompt) {\n\t\t\tmapReduceArgs.combineMapPrompt = new PromptTemplate({\n\t\t\t\ttemplate: options.combineMapPrompt,\n\t\t\t\tinputVariables: ['text'],\n\t\t\t});\n\t\t}\n\t\tif (options.prompt) {\n\t\t\tmapReduceArgs.combinePrompt = new PromptTemplate({\n\t\t\t\ttemplate: options.prompt,\n\t\t\t\tinputVariables: ['text'],\n\t\t\t});\n\t\t}\n\t}\n\n\t// Stuff prompt override\n\tif (type === 'stuff') {\n\t\tconst stuffArgs = chainArgs as SummarizationChainParams & {\n\t\t\ttype: 'stuff';\n\t\t};\n\t\tif (options.prompt) {\n\t\t\tstuffArgs.prompt = new PromptTemplate({\n\t\t\t\ttemplate: options.prompt,\n\t\t\t\tinputVariables: ['text'],\n\t\t\t});\n\t\t}\n\t}\n\n\t// Refine prompt override\n\tif (type === 'refine') {\n\t\tconst refineArgs = chainArgs as SummarizationChainParams & {\n\t\t\ttype: 'refine';\n\t\t};\n\n\t\tif (options.refinePrompt) {\n\t\t\trefineArgs.refinePrompt = new PromptTemplate({\n\t\t\t\ttemplate: options.refinePrompt,\n\t\t\t\tinputVariables: ['existing_answer', 'text'],\n\t\t\t});\n\t\t}\n\n\t\tif (options.refineQuestionPrompt) {\n\t\t\trefineArgs.questionPrompt = new PromptTemplate({\n\t\t\t\ttemplate: options.refineQuestionPrompt,\n\t\t\t\tinputVariables: ['text'],\n\t\t\t});\n\t\t}\n\t}\n\n\treturn chainArgs;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+B;AASxB,SAAS,oBACf,MACA,SACC;AACD,QAAM,YAAsC;AAAA,IAC3C;AAAA,EACD;AAEA,MAAI,SAAS,cAAc;AAC1B,UAAM,gBAAgB;AAGtB,QAAI,QAAQ,kBAAkB;AAC7B,oBAAc,mBAAmB,IAAI,8BAAe;AAAA,QACnD,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,MAAM;AAAA,MACxB,CAAC;AAAA,IACF;AACA,QAAI,QAAQ,QAAQ;AACnB,oBAAc,gBAAgB,IAAI,8BAAe;AAAA,QAChD,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,MAAM;AAAA,MACxB,CAAC;AAAA,IACF;AAAA,EACD;AAGA,MAAI,SAAS,SAAS;AACrB,UAAM,YAAY;AAGlB,QAAI,QAAQ,QAAQ;AACnB,gBAAU,SAAS,IAAI,8BAAe;AAAA,QACrC,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,MAAM;AAAA,MACxB,CAAC;AAAA,IACF;AAAA,EACD;AAGA,MAAI,SAAS,UAAU;AACtB,UAAM,aAAa;AAInB,QAAI,QAAQ,cAAc;AACzB,iBAAW,eAAe,IAAI,8BAAe;AAAA,QAC5C,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,mBAAmB,MAAM;AAAA,MAC3C,CAAC;AAAA,IACF;AAEA,QAAI,QAAQ,sBAAsB;AACjC,iBAAW,iBAAiB,IAAI,8BAAe;AAAA,QAC9C,UAAU,QAAQ;AAAA,QAClB,gBAAgB,CAAC,MAAM;AAAA,MACxB,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO;AACR;","names":[]}
|
|
@@ -21,7 +21,7 @@ __export(InformationExtractor_node_exports, {
|
|
|
21
21
|
InformationExtractor: () => InformationExtractor
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(InformationExtractor_node_exports);
|
|
24
|
-
var import_output_parsers = require("langchain/output_parsers");
|
|
24
|
+
var import_output_parsers = require("@langchain/classic/output_parsers");
|
|
25
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
26
26
|
var import_descriptions = require("../../../utils/descriptions");
|
|
27
27
|
var import_schemaParsing = require("../../../utils/schemaParsing");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/chains/InformationExtractor/InformationExtractor.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { JSONSchema7 } from 'json-schema';\nimport { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers';\nimport { jsonParse, NodeConnectionTypes, NodeOperationError, sleep } from 'n8n-workflow';\nimport type {\n\tINodeType,\n\tINodeTypeDescription,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodePropertyOptions,\n} from 'n8n-workflow';\nimport type { z } from 'zod';\n\nimport {\n\tbuildJsonSchemaExampleNotice,\n\tinputSchemaField,\n\tjsonSchemaExampleField,\n\tschemaTypeField,\n} from '@utils/descriptions';\nimport { convertJsonSchemaToZod, generateSchemaFromExample } from '@utils/schemaParsing';\nimport { getBatchingOptionFields } from '@utils/sharedFields';\n\nimport { SYSTEM_PROMPT_TEMPLATE } from './constants';\nimport { makeZodSchemaFromAttributes } from './helpers';\nimport { processItem } from './processItem';\nimport type { AttributeDefinition } from './types';\n\nexport class InformationExtractor implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Information Extractor',\n\t\tname: 'informationExtractor',\n\t\ticon: 'fa:project-diagram',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2],\n\t\tdefaultVersion: 1.2,\n\t\tdescription: 'Extract information from text in a structured format',\n\t\tcodex: {\n\t\t\talias: ['NER', 'parse', 'parsing', 'JSON', 'data extraction', 'structured'],\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.information-extractor/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tdefaults: {\n\t\t\tname: 'Information Extractor',\n\t\t},\n\t\tinputs: [\n\t\t\t{ displayName: '', type: NodeConnectionTypes.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],\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Text',\n\t\t\t\tname: 'text',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tdescription: 'The text to extract information from',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...schemaTypeField,\n\t\t\t\tdescription: 'How to specify the schema for the desired output',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'From Attribute Descriptions',\n\t\t\t\t\t\tvalue: 'fromAttributes',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Extract specific attributes from the text based on types and descriptions',\n\t\t\t\t\t} as INodePropertyOptions,\n\t\t\t\t\t...(schemaTypeField.options as INodePropertyOptions[]),\n\t\t\t\t],\n\t\t\t\tdefault: 'fromAttributes',\n\t\t\t},\n\t\t\t{\n\t\t\t\t...jsonSchemaExampleField,\n\t\t\t\tdefault: `{\n\t\"state\": \"California\",\n\t\"cities\": [\"Los Angeles\", \"San Francisco\", \"San Diego\"]\n}`,\n\t\t\t},\n\t\t\tbuildJsonSchemaExampleNotice({\n\t\t\t\tshowExtraProps: {\n\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t},\n\t\t\t}),\n\t\t\t{\n\t\t\t\t...inputSchemaField,\n\t\t\t\tdefault: `{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"state\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"cities\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"string\"\n\t\t\t}\n\t\t}\n\t}\n}`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Attributes',\n\t\t\t\tname: 'attributes',\n\t\t\t\tplaceholder: 'Add Attribute',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tdefault: {},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tschemaType: ['fromAttributes'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'attributes',\n\t\t\t\t\t\tdisplayName: 'Attribute List',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Name',\n\t\t\t\t\t\t\t\tname: 'name',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\tdescription: 'Attribute to extract',\n\t\t\t\t\t\t\t\tplaceholder: 'e.g. company_name',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type',\n\t\t\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\tdescription: 'Data type of the attribute',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'Boolean',\n\t\t\t\t\t\t\t\t\t\tvalue: 'boolean',\n\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\t\tname: 'Date',\n\t\t\t\t\t\t\t\t\t\tvalue: 'date',\n\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\t\tname: 'Number',\n\t\t\t\t\t\t\t\t\t\tvalue: 'number',\n\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\t\tname: 'String',\n\t\t\t\t\t\t\t\t\t\tvalue: 'string',\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\tdefault: 'string',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Description',\n\t\t\t\t\t\t\t\tname: 'description',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\tdescription: 'Describe your attribute',\n\t\t\t\t\t\t\t\tplaceholder: 'Add description for the attribute',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Required',\n\t\t\t\t\t\t\t\tname: 'required',\n\t\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\t\t\tdescription: 'Whether attribute is required',\n\t\t\t\t\t\t\t\trequired: true,\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\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\tdisplayName: 'System Prompt Template',\n\t\t\t\t\t\tname: 'systemPromptTemplate',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: SYSTEM_PROMPT_TEMPLATE,\n\t\t\t\t\t\tdescription: 'String to use directly as the system prompt template',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 6,\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.1 } }],\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\tconst items = this.getInputData();\n\n\t\tconst llm = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t0,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst schemaType = this.getNodeParameter('schemaType', 0, '') as\n\t\t\t| 'fromAttributes'\n\t\t\t| 'fromJson'\n\t\t\t| 'manual';\n\n\t\tlet parser: OutputFixingParser<object>;\n\n\t\tif (schemaType === 'fromAttributes') {\n\t\t\tconst attributes = this.getNodeParameter(\n\t\t\t\t'attributes.attributes',\n\t\t\t\t0,\n\t\t\t\t[],\n\t\t\t) as AttributeDefinition[];\n\n\t\t\tif (attributes.length === 0) {\n\t\t\t\tthrow new NodeOperationError(this.getNode(), 'At least one attribute must be specified');\n\t\t\t}\n\n\t\t\tparser = OutputFixingParser.fromLLM(\n\t\t\t\tllm,\n\t\t\t\tStructuredOutputParser.fromZodSchema(makeZodSchemaFromAttributes(attributes)),\n\t\t\t);\n\t\t} else {\n\t\t\tlet jsonSchema: JSONSchema7;\n\n\t\t\tif (schemaType === 'fromJson') {\n\t\t\t\tconst jsonExample = this.getNodeParameter('jsonSchemaExample', 0, '') as string;\n\t\t\t\t// Enforce all fields to be required in the generated schema if the node version is 1.2 or higher\n\t\t\t\tconst jsonExampleAllFieldsRequired = this.getNode().typeVersion >= 1.2;\n\n\t\t\t\tjsonSchema = generateSchemaFromExample(jsonExample, jsonExampleAllFieldsRequired);\n\t\t\t} else {\n\t\t\t\tconst inputSchema = this.getNodeParameter('inputSchema', 0, '') as string;\n\t\t\t\tjsonSchema = jsonParse<JSONSchema7>(inputSchema);\n\t\t\t}\n\n\t\t\tconst zodSchema = convertJsonSchemaToZod<z.ZodSchema<object>>(jsonSchema);\n\n\t\t\tparser = OutputFixingParser.fromLLM(llm, StructuredOutputParser.fromZodSchema(zodSchema));\n\t\t}\n\n\t\tconst resultData: 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\t\tif (this.getNode().typeVersion >= 1.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, llm, parser);\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 as Error;\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\tresultData.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\treturn;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new NodeOperationError(this.getNode(), error.message);\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\tresultData.push({ json: { output } });\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// Sequential processing\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst output = await processItem(this, itemIndex, llm, parser);\n\t\t\t\t\tresultData.push({ json: { output } });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\tresultData.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 [resultData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,4BAA2D;AAC3D,0BAA0E;AAU1E,0BAKO;AACP,2BAAkE;AAClE,0BAAwC;AAExC,uBAAuC;AACvC,qBAA4C;AAC5C,yBAA4B;AAGrB,MAAM,qBAA0C;AAAA,EAAhD;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,GAAG;AAAA,MACrB,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,OAAO;AAAA,QACN,OAAO,CAAC,OAAO,SAAS,WAAW,QAAQ,mBAAmB,YAAY;AAAA,QAC1E,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,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,QAAQ;AAAA,QACP,EAAE,aAAa,IAAI,MAAM,wCAAoB,KAAK;AAAA,QAClD;AAAA,UACC,aAAa;AAAA,UACb,gBAAg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or/InformationExtractor.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { JSONSchema7 } from 'json-schema';\nimport { OutputFixingParser, StructuredOutputParser } from '@langchain/classic/output_parsers';\nimport { jsonParse, NodeConnectionTypes, NodeOperationError, sleep } from 'n8n-workflow';\nimport type {\n\tINodeType,\n\tINodeTypeDescription,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodePropertyOptions,\n} from 'n8n-workflow';\nimport type { z } from 'zod';\n\nimport {\n\tbuildJsonSchemaExampleNotice,\n\tinputSchemaField,\n\tjsonSchemaExampleField,\n\tschemaTypeField,\n} from '@utils/descriptions';\nimport { convertJsonSchemaToZod, generateSchemaFromExample } from '@utils/schemaParsing';\nimport { getBatchingOptionFields } from '@utils/sharedFields';\n\nimport { SYSTEM_PROMPT_TEMPLATE } from './constants';\nimport { makeZodSchemaFromAttributes } from './helpers';\nimport { processItem } from './processItem';\nimport type { AttributeDefinition } from './types';\n\nexport class InformationExtractor implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Information Extractor',\n\t\tname: 'informationExtractor',\n\t\ticon: 'fa:project-diagram',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2],\n\t\tdefaultVersion: 1.2,\n\t\tdescription: 'Extract information from text in a structured format',\n\t\tcodex: {\n\t\t\talias: ['NER', 'parse', 'parsing', 'JSON', 'data extraction', 'structured'],\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.information-extractor/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tdefaults: {\n\t\t\tname: 'Information Extractor',\n\t\t},\n\t\tinputs: [\n\t\t\t{ displayName: '', type: NodeConnectionTypes.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],\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Text',\n\t\t\t\tname: 'text',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tdescription: 'The text to extract information from',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...schemaTypeField,\n\t\t\t\tdescription: 'How to specify the schema for the desired output',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'From Attribute Descriptions',\n\t\t\t\t\t\tvalue: 'fromAttributes',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Extract specific attributes from the text based on types and descriptions',\n\t\t\t\t\t} as INodePropertyOptions,\n\t\t\t\t\t...(schemaTypeField.options as INodePropertyOptions[]),\n\t\t\t\t],\n\t\t\t\tdefault: 'fromAttributes',\n\t\t\t},\n\t\t\t{\n\t\t\t\t...jsonSchemaExampleField,\n\t\t\t\tdefault: `{\n\t\"state\": \"California\",\n\t\"cities\": [\"Los Angeles\", \"San Francisco\", \"San Diego\"]\n}`,\n\t\t\t},\n\t\t\tbuildJsonSchemaExampleNotice({\n\t\t\t\tshowExtraProps: {\n\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t},\n\t\t\t}),\n\t\t\t{\n\t\t\t\t...inputSchemaField,\n\t\t\t\tdefault: `{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"state\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"cities\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"string\"\n\t\t\t}\n\t\t}\n\t}\n}`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Attributes',\n\t\t\t\tname: 'attributes',\n\t\t\t\tplaceholder: 'Add Attribute',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tdefault: {},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tschemaType: ['fromAttributes'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'attributes',\n\t\t\t\t\t\tdisplayName: 'Attribute List',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Name',\n\t\t\t\t\t\t\t\tname: 'name',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\tdescription: 'Attribute to extract',\n\t\t\t\t\t\t\t\tplaceholder: 'e.g. company_name',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type',\n\t\t\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\tdescription: 'Data type of the attribute',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'Boolean',\n\t\t\t\t\t\t\t\t\t\tvalue: 'boolean',\n\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\t\tname: 'Date',\n\t\t\t\t\t\t\t\t\t\tvalue: 'date',\n\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\t\tname: 'Number',\n\t\t\t\t\t\t\t\t\t\tvalue: 'number',\n\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\t\tname: 'String',\n\t\t\t\t\t\t\t\t\t\tvalue: 'string',\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\tdefault: 'string',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Description',\n\t\t\t\t\t\t\t\tname: 'description',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\tdescription: 'Describe your attribute',\n\t\t\t\t\t\t\t\tplaceholder: 'Add description for the attribute',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Required',\n\t\t\t\t\t\t\t\tname: 'required',\n\t\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\t\t\tdescription: 'Whether attribute is required',\n\t\t\t\t\t\t\t\trequired: true,\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\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\tdisplayName: 'System Prompt Template',\n\t\t\t\t\t\tname: 'systemPromptTemplate',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: SYSTEM_PROMPT_TEMPLATE,\n\t\t\t\t\t\tdescription: 'String to use directly as the system prompt template',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 6,\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.1 } }],\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\tconst items = this.getInputData();\n\n\t\tconst llm = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t0,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst schemaType = this.getNodeParameter('schemaType', 0, '') as\n\t\t\t| 'fromAttributes'\n\t\t\t| 'fromJson'\n\t\t\t| 'manual';\n\n\t\tlet parser: OutputFixingParser<object>;\n\n\t\tif (schemaType === 'fromAttributes') {\n\t\t\tconst attributes = this.getNodeParameter(\n\t\t\t\t'attributes.attributes',\n\t\t\t\t0,\n\t\t\t\t[],\n\t\t\t) as AttributeDefinition[];\n\n\t\t\tif (attributes.length === 0) {\n\t\t\t\tthrow new NodeOperationError(this.getNode(), 'At least one attribute must be specified');\n\t\t\t}\n\n\t\t\tparser = OutputFixingParser.fromLLM(\n\t\t\t\tllm,\n\t\t\t\tStructuredOutputParser.fromZodSchema(makeZodSchemaFromAttributes(attributes)),\n\t\t\t);\n\t\t} else {\n\t\t\tlet jsonSchema: JSONSchema7;\n\n\t\t\tif (schemaType === 'fromJson') {\n\t\t\t\tconst jsonExample = this.getNodeParameter('jsonSchemaExample', 0, '') as string;\n\t\t\t\t// Enforce all fields to be required in the generated schema if the node version is 1.2 or higher\n\t\t\t\tconst jsonExampleAllFieldsRequired = this.getNode().typeVersion >= 1.2;\n\n\t\t\t\tjsonSchema = generateSchemaFromExample(jsonExample, jsonExampleAllFieldsRequired);\n\t\t\t} else {\n\t\t\t\tconst inputSchema = this.getNodeParameter('inputSchema', 0, '') as string;\n\t\t\t\tjsonSchema = jsonParse<JSONSchema7>(inputSchema);\n\t\t\t}\n\n\t\t\tconst zodSchema = convertJsonSchemaToZod<z.ZodSchema<object>>(jsonSchema);\n\n\t\t\tparser = OutputFixingParser.fromLLM(llm, StructuredOutputParser.fromZodSchema(zodSchema));\n\t\t}\n\n\t\tconst resultData: 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\t\tif (this.getNode().typeVersion >= 1.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, llm, parser);\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 as Error;\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\tresultData.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\treturn;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new NodeOperationError(this.getNode(), error.message);\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\tresultData.push({ json: { output } });\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// Sequential processing\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst output = await processItem(this, itemIndex, llm, parser);\n\t\t\t\t\tresultData.push({ json: { output } });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\tresultData.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 [resultData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,4BAA2D;AAC3D,0BAA0E;AAU1E,0BAKO;AACP,2BAAkE;AAClE,0BAAwC;AAExC,uBAAuC;AACvC,qBAA4C;AAC5C,yBAA4B;AAGrB,MAAM,qBAA0C;AAAA,EAAhD;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,GAAG;AAAA,MACrB,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,OAAO;AAAA,QACN,OAAO,CAAC,OAAO,SAAS,WAAW,QAAQ,mBAAmB,YAAY;AAAA,QAC1E,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,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,QAAQ;AAAA,QACP,EAAE,aAAa,IAAI,MAAM,wCAAoB,KAAK;AAAA,QAClD;AAAA,UACC,aAAa;AAAA,UACb,gBAA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":["../../../../nodes/chains/InformationExtractor/processItem.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { HumanMessage } from '@langchain/core/messages';\nimport { ChatPromptTemplate, SystemMessagePromptTemplate } from '@langchain/core/prompts';\nimport type { OutputFixingParser } from 'langchain/output_parsers';\nimport { NodeOperationError, type IExecuteFunctions } from 'n8n-workflow';\n\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { SYSTEM_PROMPT_TEMPLATE } from './constants';\n\nexport async function processItem(\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n\tllm: BaseLanguageModel,\n\tparser: OutputFixingParser<object>,\n) {\n\tconst input = ctx.getNodeParameter('text', itemIndex) as string;\n\tif (!input?.trim()) {\n\t\tthrow new NodeOperationError(ctx.getNode(), `Text for item ${itemIndex} is not defined`, {\n\t\t\titemIndex,\n\t\t});\n\t}\n\tconst inputPrompt = new HumanMessage(input);\n\n\tconst options = ctx.getNodeParameter('options', itemIndex, {}) as {\n\t\tsystemPromptTemplate?: string;\n\t};\n\n\tconst systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(\n\t\t`${options.systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE}\n{format_instructions}`,\n\t);\n\n\tconst messages = [\n\t\tawait systemPromptTemplate.format({\n\t\t\tformat_instructions: parser.getFormatInstructions(),\n\t\t}),\n\t\tinputPrompt,\n\t];\n\tconst prompt = ChatPromptTemplate.fromMessages(messages);\n\tconst chain = prompt.pipe(llm).pipe(parser).withConfig(getTracingConfig(ctx));\n\n\treturn await chain.invoke(messages);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAA6B;AAC7B,qBAAgE;AAEhE,0BAA2D;AAE3D,qBAAiC;AAEjC,uBAAuC;AAEvC,eAAsB,YACrB,KACA,WACA,KACA,QACC;AACD,QAAM,QAAQ,IAAI,iBAAiB,QAAQ,SAAS;AACpD,MAAI,CAAC,OAAO,KAAK,GAAG;AACnB,UAAM,IAAI,uCAAmB,IAAI,QAAQ,GAAG,iBAAiB,SAAS,mBAAmB;AAAA,MACxF;AAAA,IACD,CAAC;AAAA,EACF;AACA,QAAM,cAAc,IAAI,6BAAa,KAAK;AAE1C,QAAM,UAAU,IAAI,iBAAiB,WAAW,WAAW,CAAC,CAAC;AAI7D,QAAM,uBAAuB,2CAA4B;AAAA,IACxD,GAAG,QAAQ,wBAAwB,uCAAsB;AAAA;AAAA,EAE1D;AAEA,QAAM,WAAW;AAAA,IAChB,MAAM,qBAAqB,OAAO;AAAA,MACjC,qBAAqB,OAAO,sBAAsB;AAAA,IACnD,CAAC;AAAA,IACD;AAAA,EACD;AACA,QAAM,SAAS,kCAAmB,aAAa,QAAQ;AACvD,QAAM,QAAQ,OAAO,KAAK,GAAG,EAAE,KAAK,MAAM,EAAE,eAAW,iCAAiB,GAAG,CAAC;AAE5E,SAAO,MAAM,MAAM,OAAO,QAAQ;AACnC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/InformationExtractor/processItem.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { HumanMessage } from '@langchain/core/messages';\nimport { ChatPromptTemplate, SystemMessagePromptTemplate } from '@langchain/core/prompts';\nimport type { OutputFixingParser } from '@langchain/classic/output_parsers';\nimport { NodeOperationError, type IExecuteFunctions } from 'n8n-workflow';\n\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { SYSTEM_PROMPT_TEMPLATE } from './constants';\n\nexport async function processItem(\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n\tllm: BaseLanguageModel,\n\tparser: OutputFixingParser<object>,\n) {\n\tconst input = ctx.getNodeParameter('text', itemIndex) as string;\n\tif (!input?.trim()) {\n\t\tthrow new NodeOperationError(ctx.getNode(), `Text for item ${itemIndex} is not defined`, {\n\t\t\titemIndex,\n\t\t});\n\t}\n\tconst inputPrompt = new HumanMessage(input);\n\n\tconst options = ctx.getNodeParameter('options', itemIndex, {}) as {\n\t\tsystemPromptTemplate?: string;\n\t};\n\n\tconst systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(\n\t\t`${options.systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE}\n{format_instructions}`,\n\t);\n\n\tconst messages = [\n\t\tawait systemPromptTemplate.format({\n\t\t\tformat_instructions: parser.getFormatInstructions(),\n\t\t}),\n\t\tinputPrompt,\n\t];\n\tconst prompt = ChatPromptTemplate.fromMessages(messages);\n\tconst chain = prompt.pipe(llm).pipe(parser).withConfig(getTracingConfig(ctx));\n\n\treturn await chain.invoke(messages);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAA6B;AAC7B,qBAAgE;AAEhE,0BAA2D;AAE3D,qBAAiC;AAEjC,uBAAuC;AAEvC,eAAsB,YACrB,KACA,WACA,KACA,QACC;AACD,QAAM,QAAQ,IAAI,iBAAiB,QAAQ,SAAS;AACpD,MAAI,CAAC,OAAO,KAAK,GAAG;AACnB,UAAM,IAAI,uCAAmB,IAAI,QAAQ,GAAG,iBAAiB,SAAS,mBAAmB;AAAA,MACxF;AAAA,IACD,CAAC;AAAA,EACF;AACA,QAAM,cAAc,IAAI,6BAAa,KAAK;AAE1C,QAAM,UAAU,IAAI,iBAAiB,WAAW,WAAW,CAAC,CAAC;AAI7D,QAAM,uBAAuB,2CAA4B;AAAA,IACxD,GAAG,QAAQ,wBAAwB,uCAAsB;AAAA;AAAA,EAE1D;AAEA,QAAM,WAAW;AAAA,IAChB,MAAM,qBAAqB,OAAO;AAAA,MACjC,qBAAqB,OAAO,sBAAsB;AAAA,IACnD,CAAC;AAAA,IACD;AAAA,EACD;AACA,QAAM,SAAS,kCAAmB,aAAa,QAAQ;AACvD,QAAM,QAAQ,OAAO,KAAK,GAAG,EAAE,KAAK,MAAM,EAAE,eAAW,iCAAiB,GAAG,CAAC;AAE5E,SAAO,MAAM,MAAM,OAAO,QAAQ;AACnC;","names":[]}
|
|
@@ -23,7 +23,7 @@ __export(SentimentAnalysis_node_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(SentimentAnalysis_node_exports);
|
|
24
24
|
var import_messages = require("@langchain/core/messages");
|
|
25
25
|
var import_prompts = require("@langchain/core/prompts");
|
|
26
|
-
var import_output_parsers = require("langchain/output_parsers");
|
|
26
|
+
var import_output_parsers = require("@langchain/classic/output_parsers");
|
|
27
27
|
var import_n8n_workflow = require("n8n-workflow");
|
|
28
28
|
var import_zod = require("zod");
|
|
29
29
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/chains/SentimentAnalysis/SentimentAnalysis.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { HumanMessage } from '@langchain/core/messages';\nimport { SystemMessagePromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';\nimport { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers';\nimport { NodeConnectionTypes, NodeOperationError, sleep } from 'n8n-workflow';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeParameters,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\nimport { z } from 'zod';\n\nimport { getBatchingOptionFields } from '@utils/sharedFields';\nimport { getTracingConfig } from '@utils/tracing';\n\nconst DEFAULT_SYSTEM_PROMPT_TEMPLATE =\n\t'You are highly intelligent and accurate sentiment analyzer. Analyze the sentiment of the provided text. Categorize it into one of the following: {categories}. Use the provided formatting instructions. Only output the JSON.';\n\nconst DEFAULT_CATEGORIES = 'Positive, Neutral, Negative';\nconst configuredOutputs = (parameters: INodeParameters, defaultCategories: string) => {\n\tconst options = (parameters?.options ?? {}) as IDataObject;\n\tconst categories = (options?.categories as string) ?? defaultCategories;\n\tconst categoriesArray = categories.split(',').map((cat) => cat.trim());\n\n\tconst ret = categoriesArray.map((cat) => ({ type: 'main', displayName: cat }));\n\treturn ret;\n};\n\nexport class SentimentAnalysis implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Sentiment Analysis',\n\t\tname: 'sentimentAnalysis',\n\t\ticon: 'fa:balance-scale-left',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Analyze the sentiment of your text',\n\t\tcodex: {\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.sentimentanalysis/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tdefaults: {\n\t\t\tname: 'Sentiment Analysis',\n\t\t},\n\t\tinputs: [\n\t\t\t{ displayName: '', type: NodeConnectionTypes.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],\n\t\toutputs: `={{(${configuredOutputs})($parameter, \"${DEFAULT_CATEGORIES}\")}}`,\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Text to Analyze',\n\t\t\t\tname: 'inputText',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tdescription: 'Use an expression to reference data in previous nodes or enter static text',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t'Sentiment scores are LLM-generated estimates, not statistically rigorous measurements. They may be inconsistent across runs and should be used as rough indicators only.',\n\t\t\t\tname: 'detailedResultsNotice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/options.includeDetailedResults': [true],\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\tdisplayName: 'Sentiment Categories',\n\t\t\t\t\t\tname: 'categories',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: DEFAULT_CATEGORIES,\n\t\t\t\t\t\tdescription: 'A comma-separated list of categories to analyze',\n\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 2,\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\tdisplayName: 'System Prompt Template',\n\t\t\t\t\t\tname: 'systemPromptTemplate',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: DEFAULT_SYSTEM_PROMPT_TEMPLATE,\n\t\t\t\t\t\tdescription: 'String to use directly as the system prompt template',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 6,\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\tdisplayName: 'Include Detailed Results',\n\t\t\t\t\t\tname: 'includeDetailedResults',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to include sentiment strength and confidence scores in the output',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Enable Auto-Fixing',\n\t\t\t\t\t\tname: 'enableAutoFixing',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: true,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to enable auto-fixing (may trigger an additional LLM call if output is broken)',\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.1 } }],\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\tconst items = this.getInputData();\n\n\t\tconst llm = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t0,\n\t\t)) as BaseLanguageModel;\n\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 >= 1.1 && batchSize > 1) {\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\tconst sentimentCategories = this.getNodeParameter(\n\t\t\t\t\t\t'options.categories',\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\tDEFAULT_CATEGORIES,\n\t\t\t\t\t) as string;\n\n\t\t\t\t\tconst categories = sentimentCategories\n\t\t\t\t\t\t.split(',')\n\t\t\t\t\t\t.map((cat) => cat.trim())\n\t\t\t\t\t\t.filter(Boolean);\n\n\t\t\t\t\tif (categories.length === 0) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tresult: null,\n\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\terror: new NodeOperationError(this.getNode(), 'No sentiment categories provided', {\n\t\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Initialize returnData with empty arrays for each category\n\t\t\t\t\tif (returnData.length === 0) {\n\t\t\t\t\t\treturnData.push(...Array.from({ length: categories.length }, () => []));\n\t\t\t\t\t}\n\n\t\t\t\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\t\t\t\tsystemPromptTemplate?: string;\n\t\t\t\t\t\tincludeDetailedResults?: boolean;\n\t\t\t\t\t\tenableAutoFixing?: boolean;\n\t\t\t\t\t};\n\n\t\t\t\t\tconst schema = z.object({\n\t\t\t\t\t\tsentiment: z.enum(categories as [string, ...string[]]),\n\t\t\t\t\t\tstrength: z\n\t\t\t\t\t\t\t.number()\n\t\t\t\t\t\t\t.min(0)\n\t\t\t\t\t\t\t.max(1)\n\t\t\t\t\t\t\t.describe('Strength score for sentiment in relation to the category'),\n\t\t\t\t\t\tconfidence: z.number().min(0).max(1),\n\t\t\t\t\t});\n\n\t\t\t\t\tconst structuredParser = StructuredOutputParser.fromZodSchema(schema);\n\n\t\t\t\t\tconst parser = options.enableAutoFixing\n\t\t\t\t\t\t? OutputFixingParser.fromLLM(llm, structuredParser)\n\t\t\t\t\t\t: structuredParser;\n\n\t\t\t\t\tconst systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(\n\t\t\t\t\t\t`${options.systemPromptTemplate ?? DEFAULT_SYSTEM_PROMPT_TEMPLATE}\n\t\t\t\t{format_instructions}`,\n\t\t\t\t\t);\n\n\t\t\t\t\tconst input = this.getNodeParameter('inputText', itemIndex) as string;\n\t\t\t\t\tconst inputPrompt = new HumanMessage(input);\n\t\t\t\t\tconst messages = [\n\t\t\t\t\t\tawait systemPromptTemplate.format({\n\t\t\t\t\t\t\tcategories: sentimentCategories,\n\t\t\t\t\t\t\tformat_instructions: parser.getFormatInstructions(),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tinputPrompt,\n\t\t\t\t\t];\n\n\t\t\t\t\tconst prompt = ChatPromptTemplate.fromMessages(messages);\n\t\t\t\t\tconst chain = prompt.pipe(llm).pipe(parser).withConfig(getTracingConfig(this));\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = await chain.invoke(messages);\n\t\t\t\t\t\tconst sentimentIndex = categories.findIndex(\n\t\t\t\t\t\t\t(s) => s.toLowerCase() === output.sentiment.toLowerCase(),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (sentimentIndex !== -1) {\n\t\t\t\t\t\t\tconst resultItem = { ...items[itemIndex] };\n\t\t\t\t\t\t\tconst sentimentAnalysis: IDataObject = {\n\t\t\t\t\t\t\t\tcategory: output.sentiment,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tif (options.includeDetailedResults) {\n\t\t\t\t\t\t\t\tsentimentAnalysis.strength = output.strength;\n\t\t\t\t\t\t\t\tsentimentAnalysis.confidence = output.confidence;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresultItem.json = {\n\t\t\t\t\t\t\t\t...resultItem.json,\n\t\t\t\t\t\t\t\tsentimentAnalysis,\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\t\t\tresultItem,\n\t\t\t\t\t\t\t\t\tsentimentIndex,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tresult: {},\n\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tresult: null,\n\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\terror: new NodeOperationError(\n\t\t\t\t\t\t\t\tthis.getNode(),\n\t\t\t\t\t\t\t\t'Error during parsing of LLM output, please check your LLM model and configuration',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\titemIndex,\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\tconst batchResults = await Promise.all(batchPromises);\n\n\t\t\t\tbatchResults.forEach(({ result, itemIndex, error }) => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\tconst executionErrorData = this.helpers.constructExecutionMetaData(\n\t\t\t\t\t\t\t\tthis.helpers.returnJsonArray({ error: error.message }),\n\t\t\t\t\t\t\t\t{ itemData: { item: itemIndex } },\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\treturnData[0].push(...executionErrorData);\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} else if (result.resultItem && result.sentimentIndex !== -1) {\n\t\t\t\t\t\tconst sentimentIndex = result.sentimentIndex;\n\t\t\t\t\t\tconst resultItem = result.resultItem;\n\t\t\t\t\t\treturnData[sentimentIndex].push(resultItem);\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// Sequential Processing\n\t\t\tfor (let i = 0; i < items.length; i++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst sentimentCategories = this.getNodeParameter(\n\t\t\t\t\t\t'options.categories',\n\t\t\t\t\t\ti,\n\t\t\t\t\t\tDEFAULT_CATEGORIES,\n\t\t\t\t\t) as string;\n\n\t\t\t\t\tconst categories = sentimentCategories\n\t\t\t\t\t\t.split(',')\n\t\t\t\t\t\t.map((cat) => cat.trim())\n\t\t\t\t\t\t.filter(Boolean);\n\n\t\t\t\t\tif (categories.length === 0) {\n\t\t\t\t\t\tthrow new NodeOperationError(this.getNode(), 'No sentiment categories provided', {\n\t\t\t\t\t\t\titemIndex: i,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t// Initialize returnData with empty arrays for each category\n\t\t\t\t\tif (returnData.length === 0) {\n\t\t\t\t\t\treturnData.push(...Array.from({ length: categories.length }, () => []));\n\t\t\t\t\t}\n\n\t\t\t\t\tconst options = this.getNodeParameter('options', i, {}) as {\n\t\t\t\t\t\tsystemPromptTemplate?: string;\n\t\t\t\t\t\tincludeDetailedResults?: boolean;\n\t\t\t\t\t\tenableAutoFixing?: boolean;\n\t\t\t\t\t};\n\n\t\t\t\t\tconst schema = z.object({\n\t\t\t\t\t\tsentiment: z.enum(categories as [string, ...string[]]),\n\t\t\t\t\t\tstrength: z\n\t\t\t\t\t\t\t.number()\n\t\t\t\t\t\t\t.min(0)\n\t\t\t\t\t\t\t.max(1)\n\t\t\t\t\t\t\t.describe('Strength score for sentiment in relation to the category'),\n\t\t\t\t\t\tconfidence: z.number().min(0).max(1),\n\t\t\t\t\t});\n\n\t\t\t\t\tconst structuredParser = StructuredOutputParser.fromZodSchema(schema);\n\n\t\t\t\t\tconst parser = options.enableAutoFixing\n\t\t\t\t\t\t? OutputFixingParser.fromLLM(llm, structuredParser)\n\t\t\t\t\t\t: structuredParser;\n\n\t\t\t\t\tconst systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(\n\t\t\t\t\t\t`${options.systemPromptTemplate ?? DEFAULT_SYSTEM_PROMPT_TEMPLATE}\n\t\t\t{format_instructions}`,\n\t\t\t\t\t);\n\n\t\t\t\t\tconst input = this.getNodeParameter('inputText', i) as string;\n\t\t\t\t\tconst inputPrompt = new HumanMessage(input);\n\t\t\t\t\tconst messages = [\n\t\t\t\t\t\tawait systemPromptTemplate.format({\n\t\t\t\t\t\t\tcategories: sentimentCategories,\n\t\t\t\t\t\t\tformat_instructions: parser.getFormatInstructions(),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tinputPrompt,\n\t\t\t\t\t];\n\n\t\t\t\t\tconst prompt = ChatPromptTemplate.fromMessages(messages);\n\t\t\t\t\tconst chain = prompt.pipe(llm).pipe(parser).withConfig(getTracingConfig(this));\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = await chain.invoke(messages);\n\t\t\t\t\t\tconst sentimentIndex = categories.findIndex(\n\t\t\t\t\t\t\t(s) => s.toLowerCase() === output.sentiment.toLowerCase(),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (sentimentIndex !== -1) {\n\t\t\t\t\t\t\tconst resultItem = { ...items[i] };\n\t\t\t\t\t\t\tconst sentimentAnalysis: IDataObject = {\n\t\t\t\t\t\t\t\tcategory: output.sentiment,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tif (options.includeDetailedResults) {\n\t\t\t\t\t\t\t\tsentimentAnalysis.strength = output.strength;\n\t\t\t\t\t\t\t\tsentimentAnalysis.confidence = output.confidence;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresultItem.json = {\n\t\t\t\t\t\t\t\t...resultItem.json,\n\t\t\t\t\t\t\t\tsentimentAnalysis,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\treturnData[sentimentIndex].push(resultItem);\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\t\t\tthis.getNode(),\n\t\t\t\t\t\t\t'Error during parsing of LLM output, please check your LLM model and configuration',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\titemIndex: i,\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} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\tconst executionErrorData = this.helpers.constructExecutionMetaData(\n\t\t\t\t\t\t\tthis.helpers.returnJsonArray({ error: error.message }),\n\t\t\t\t\t\t\t{ itemData: { item: i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iB,WAAW;AAAA,cACjC,CAAC,MAAM,EAAE,YAAY,MAAM,OAAO,UAAU,YAAY;AAAA,YACzD;AAEA,gBAAI,mBAAmB,IAAI;AAC1B,oBAAM,aAAa,EAAE,GAAG,MAAM,CAAC,EAAE;AACjC,oBAAM,oBAAiC;AAAA,gBACtC,UAAU,OAAO;AAAA,cAClB;AACA,kBAAI,QAAQ,wBAAwB;AACnC,kCAAkB,WAAW,OAAO;AACpC,kCAAkB,aAAa,OAAO;AAAA,cACvC;AACA,yBAAW,OAAO;AAAA,gBACjB,GAAG,WAAW;AAAA,gBACd;AAAA,cACD;AACA,yBAAW,cAAc,EAAE,KAAK,UAAU;AAAA,YAC3C;AAAA,UACD,SAAS,OAAO;AACf,kBAAM,IAAI;AAAA,cACT,KAAK,QAAQ;AAAA,cACb;AAAA,cACA;AAAA,gBACC,WAAW;AAAA,cACZ;AAAA,YACD;AAAA,UACD;AAAA,QACD,SAAS,OAAO;AACf,cAAI,KAAK,eAAe,GAAG;AAC1B,kBAAM,qBAAqB,KAAK,QAAQ;AAAA,cACvC,KAAK,QAAQ,gBAAgB,EAAE,OAAO,MAAM,QAAQ,CAAC;AAAA,cACrD,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;AAAA,YACzB;AACA,uBAAW,CAAC,EAAE,KAAK,GAAG,kBAAkB;AACxC;AAAA,UACD;AACA,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/SentimentAnalysis/SentimentAnalysis.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { HumanMessage } from '@langchain/core/messages';\nimport { SystemMessagePromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';\nimport { OutputFixingParser, StructuredOutputParser } from '@langchain/classic/output_parsers';\nimport { NodeConnectionTypes, NodeOperationError, sleep } from 'n8n-workflow';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeParameters,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\nimport { z } from 'zod';\n\nimport { getBatchingOptionFields } from '@utils/sharedFields';\nimport { getTracingConfig } from '@utils/tracing';\n\nconst DEFAULT_SYSTEM_PROMPT_TEMPLATE =\n\t'You are highly intelligent and accurate sentiment analyzer. Analyze the sentiment of the provided text. Categorize it into one of the following: {categories}. Use the provided formatting instructions. Only output the JSON.';\n\nconst DEFAULT_CATEGORIES = 'Positive, Neutral, Negative';\nconst configuredOutputs = (parameters: INodeParameters, defaultCategories: string) => {\n\tconst options = (parameters?.options ?? {}) as IDataObject;\n\tconst categories = (options?.categories as string) ?? defaultCategories;\n\tconst categoriesArray = categories.split(',').map((cat) => cat.trim());\n\n\tconst ret = categoriesArray.map((cat) => ({ type: 'main', displayName: cat }));\n\treturn ret;\n};\n\nexport class SentimentAnalysis implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Sentiment Analysis',\n\t\tname: 'sentimentAnalysis',\n\t\ticon: 'fa:balance-scale-left',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Analyze the sentiment of your text',\n\t\tcodex: {\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.sentimentanalysis/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tdefaults: {\n\t\t\tname: 'Sentiment Analysis',\n\t\t},\n\t\tinputs: [\n\t\t\t{ displayName: '', type: NodeConnectionTypes.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],\n\t\toutputs: `={{(${configuredOutputs})($parameter, \"${DEFAULT_CATEGORIES}\")}}`,\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Text to Analyze',\n\t\t\t\tname: 'inputText',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tdescription: 'Use an expression to reference data in previous nodes or enter static text',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t'Sentiment scores are LLM-generated estimates, not statistically rigorous measurements. They may be inconsistent across runs and should be used as rough indicators only.',\n\t\t\t\tname: 'detailedResultsNotice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'/options.includeDetailedResults': [true],\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\tdisplayName: 'Sentiment Categories',\n\t\t\t\t\t\tname: 'categories',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: DEFAULT_CATEGORIES,\n\t\t\t\t\t\tdescription: 'A comma-separated list of categories to analyze',\n\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 2,\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\tdisplayName: 'System Prompt Template',\n\t\t\t\t\t\tname: 'systemPromptTemplate',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: DEFAULT_SYSTEM_PROMPT_TEMPLATE,\n\t\t\t\t\t\tdescription: 'String to use directly as the system prompt template',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 6,\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\tdisplayName: 'Include Detailed Results',\n\t\t\t\t\t\tname: 'includeDetailedResults',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to include sentiment strength and confidence scores in the output',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Enable Auto-Fixing',\n\t\t\t\t\t\tname: 'enableAutoFixing',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: true,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to enable auto-fixing (may trigger an additional LLM call if output is broken)',\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.1 } }],\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\tconst items = this.getInputData();\n\n\t\tconst llm = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t0,\n\t\t)) as BaseLanguageModel;\n\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 >= 1.1 && batchSize > 1) {\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\tconst sentimentCategories = this.getNodeParameter(\n\t\t\t\t\t\t'options.categories',\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\tDEFAULT_CATEGORIES,\n\t\t\t\t\t) as string;\n\n\t\t\t\t\tconst categories = sentimentCategories\n\t\t\t\t\t\t.split(',')\n\t\t\t\t\t\t.map((cat) => cat.trim())\n\t\t\t\t\t\t.filter(Boolean);\n\n\t\t\t\t\tif (categories.length === 0) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tresult: null,\n\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\terror: new NodeOperationError(this.getNode(), 'No sentiment categories provided', {\n\t\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Initialize returnData with empty arrays for each category\n\t\t\t\t\tif (returnData.length === 0) {\n\t\t\t\t\t\treturnData.push(...Array.from({ length: categories.length }, () => []));\n\t\t\t\t\t}\n\n\t\t\t\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\t\t\t\tsystemPromptTemplate?: string;\n\t\t\t\t\t\tincludeDetailedResults?: boolean;\n\t\t\t\t\t\tenableAutoFixing?: boolean;\n\t\t\t\t\t};\n\n\t\t\t\t\tconst schema = z.object({\n\t\t\t\t\t\tsentiment: z.enum(categories as [string, ...string[]]),\n\t\t\t\t\t\tstrength: z\n\t\t\t\t\t\t\t.number()\n\t\t\t\t\t\t\t.min(0)\n\t\t\t\t\t\t\t.max(1)\n\t\t\t\t\t\t\t.describe('Strength score for sentiment in relation to the category'),\n\t\t\t\t\t\tconfidence: z.number().min(0).max(1),\n\t\t\t\t\t});\n\n\t\t\t\t\tconst structuredParser = StructuredOutputParser.fromZodSchema(schema);\n\n\t\t\t\t\tconst parser = options.enableAutoFixing\n\t\t\t\t\t\t? OutputFixingParser.fromLLM(llm, structuredParser)\n\t\t\t\t\t\t: structuredParser;\n\n\t\t\t\t\tconst systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(\n\t\t\t\t\t\t`${options.systemPromptTemplate ?? DEFAULT_SYSTEM_PROMPT_TEMPLATE}\n\t\t\t\t{format_instructions}`,\n\t\t\t\t\t);\n\n\t\t\t\t\tconst input = this.getNodeParameter('inputText', itemIndex) as string;\n\t\t\t\t\tconst inputPrompt = new HumanMessage(input);\n\t\t\t\t\tconst messages = [\n\t\t\t\t\t\tawait systemPromptTemplate.format({\n\t\t\t\t\t\t\tcategories: sentimentCategories,\n\t\t\t\t\t\t\tformat_instructions: parser.getFormatInstructions(),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tinputPrompt,\n\t\t\t\t\t];\n\n\t\t\t\t\tconst prompt = ChatPromptTemplate.fromMessages(messages);\n\t\t\t\t\tconst chain = prompt.pipe(llm).pipe(parser).withConfig(getTracingConfig(this));\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = await chain.invoke(messages);\n\t\t\t\t\t\tconst sentimentIndex = categories.findIndex(\n\t\t\t\t\t\t\t(s) => s.toLowerCase() === output.sentiment.toLowerCase(),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (sentimentIndex !== -1) {\n\t\t\t\t\t\t\tconst resultItem = { ...items[itemIndex] };\n\t\t\t\t\t\t\tconst sentimentAnalysis: IDataObject = {\n\t\t\t\t\t\t\t\tcategory: output.sentiment,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tif (options.includeDetailedResults) {\n\t\t\t\t\t\t\t\tsentimentAnalysis.strength = output.strength;\n\t\t\t\t\t\t\t\tsentimentAnalysis.confidence = output.confidence;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresultItem.json = {\n\t\t\t\t\t\t\t\t...resultItem.json,\n\t\t\t\t\t\t\t\tsentimentAnalysis,\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tresult: {\n\t\t\t\t\t\t\t\t\tresultItem,\n\t\t\t\t\t\t\t\t\tsentimentIndex,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tresult: {},\n\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tresult: null,\n\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\terror: new NodeOperationError(\n\t\t\t\t\t\t\t\tthis.getNode(),\n\t\t\t\t\t\t\t\t'Error during parsing of LLM output, please check your LLM model and configuration',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\titemIndex,\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\tconst batchResults = await Promise.all(batchPromises);\n\n\t\t\t\tbatchResults.forEach(({ result, itemIndex, error }) => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\tconst executionErrorData = this.helpers.constructExecutionMetaData(\n\t\t\t\t\t\t\t\tthis.helpers.returnJsonArray({ error: error.message }),\n\t\t\t\t\t\t\t\t{ itemData: { item: itemIndex } },\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\treturnData[0].push(...executionErrorData);\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} else if (result.resultItem && result.sentimentIndex !== -1) {\n\t\t\t\t\t\tconst sentimentIndex = result.sentimentIndex;\n\t\t\t\t\t\tconst resultItem = result.resultItem;\n\t\t\t\t\t\treturnData[sentimentIndex].push(resultItem);\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// Sequential Processing\n\t\t\tfor (let i = 0; i < items.length; i++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst sentimentCategories = this.getNodeParameter(\n\t\t\t\t\t\t'options.categories',\n\t\t\t\t\t\ti,\n\t\t\t\t\t\tDEFAULT_CATEGORIES,\n\t\t\t\t\t) as string;\n\n\t\t\t\t\tconst categories = sentimentCategories\n\t\t\t\t\t\t.split(',')\n\t\t\t\t\t\t.map((cat) => cat.trim())\n\t\t\t\t\t\t.filter(Boolean);\n\n\t\t\t\t\tif (categories.length === 0) {\n\t\t\t\t\t\tthrow new NodeOperationError(this.getNode(), 'No sentiment categories provided', {\n\t\t\t\t\t\t\titemIndex: i,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t// Initialize returnData with empty arrays for each category\n\t\t\t\t\tif (returnData.length === 0) {\n\t\t\t\t\t\treturnData.push(...Array.from({ length: categories.length }, () => []));\n\t\t\t\t\t}\n\n\t\t\t\t\tconst options = this.getNodeParameter('options', i, {}) as {\n\t\t\t\t\t\tsystemPromptTemplate?: string;\n\t\t\t\t\t\tincludeDetailedResults?: boolean;\n\t\t\t\t\t\tenableAutoFixing?: boolean;\n\t\t\t\t\t};\n\n\t\t\t\t\tconst schema = z.object({\n\t\t\t\t\t\tsentiment: z.enum(categories as [string, ...string[]]),\n\t\t\t\t\t\tstrength: z\n\t\t\t\t\t\t\t.number()\n\t\t\t\t\t\t\t.min(0)\n\t\t\t\t\t\t\t.max(1)\n\t\t\t\t\t\t\t.describe('Strength score for sentiment in relation to the category'),\n\t\t\t\t\t\tconfidence: z.number().min(0).max(1),\n\t\t\t\t\t});\n\n\t\t\t\t\tconst structuredParser = StructuredOutputParser.fromZodSchema(schema);\n\n\t\t\t\t\tconst parser = options.enableAutoFixing\n\t\t\t\t\t\t? OutputFixingParser.fromLLM(llm, structuredParser)\n\t\t\t\t\t\t: structuredParser;\n\n\t\t\t\t\tconst systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(\n\t\t\t\t\t\t`${options.systemPromptTemplate ?? DEFAULT_SYSTEM_PROMPT_TEMPLATE}\n\t\t\t{format_instructions}`,\n\t\t\t\t\t);\n\n\t\t\t\t\tconst input = this.getNodeParameter('inputText', i) as string;\n\t\t\t\t\tconst inputPrompt = new HumanMessage(input);\n\t\t\t\t\tconst messages = [\n\t\t\t\t\t\tawait systemPromptTemplate.format({\n\t\t\t\t\t\t\tcategories: sentimentCategories,\n\t\t\t\t\t\t\tformat_instructions: parser.getFormatInstructions(),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tinputPrompt,\n\t\t\t\t\t];\n\n\t\t\t\t\tconst prompt = ChatPromptTemplate.fromMessages(messages);\n\t\t\t\t\tconst chain = prompt.pipe(llm).pipe(parser).withConfig(getTracingConfig(this));\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = await chain.invoke(messages);\n\t\t\t\t\t\tconst sentimentIndex = categories.findIndex(\n\t\t\t\t\t\t\t(s) => s.toLowerCase() === output.sentiment.toLowerCase(),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (sentimentIndex !== -1) {\n\t\t\t\t\t\t\tconst resultItem = { ...items[i] };\n\t\t\t\t\t\t\tconst sentimentAnalysis: IDataObject = {\n\t\t\t\t\t\t\t\tcategory: output.sentiment,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tif (options.includeDetailedResults) {\n\t\t\t\t\t\t\t\tsentimentAnalysis.strength = output.strength;\n\t\t\t\t\t\t\t\tsentimentAnalysis.confidence = output.confidence;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresultItem.json = {\n\t\t\t\t\t\t\t\t...resultItem.json,\n\t\t\t\t\t\t\t\tsentimentAnalysis,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\treturnData[sentimentIndex].push(resultItem);\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\t\t\tthis.getNode(),\n\t\t\t\t\t\t\t'Error during parsing of LLM output, please check your LLM model and configuration',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\titemIndex: i,\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} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\tconst executionErrorData = this.helpers.constructExecutionMetaData(\n\t\t\t\t\t\t\tthis.helpers.returnJsonArray({ error: error.message }),\n\t\t\t\t\t\t\t{ itemData: { item: i } },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturnData[0].push(...executionErrorData);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\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;AACA,sBAA6B;AAC7B,qBAAgE;AAChE,4BAA2D;AAC3D,0BAA+D;AAS/D,iBAAkB;AAElB,0BAAwC;AACxC,qBAAiC;AAEjC,MAAM,iCACL;AAED,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB,CAAC,YAA6B,sBAA8B;AACrF,QAAM,UAAW,YAAY,WAAW,CAAC;AACzC,QAAM,aAAc,SAAS,cAAyB;AACtD,QAAM,kBAAkB,WAAW,MAAM,GAAG,EAAE,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC;AAErE,QAAM,MAAM,gBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,QAAQ,aAAa,IAAI,EAAE;AAC7E,SAAO;AACR;AAEO,MAAM,kBAAuC;AAAA,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AO,MAAM,QAAQ,CAAC;AAAA,cACrD,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;AAAA,YACzB;AACA,uBAAW,CAAC,EAAE,KAAK,GAAG,kBAAkB;AACxC;AAAA,UACD;AACA,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;","names":[]}
|
|
@@ -21,7 +21,7 @@ __export(TextClassifier_node_exports, {
|
|
|
21
21
|
TextClassifier: () => TextClassifier
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(TextClassifier_node_exports);
|
|
24
|
-
var import_output_parsers = require("langchain/output_parsers");
|
|
24
|
+
var import_output_parsers = require("@langchain/classic/output_parsers");
|
|
25
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
26
26
|
var import_zod = require("zod");
|
|
27
27
|
var import_sharedFields = require("../../../utils/sharedFields");
|