@n8n/n8n-nodes-langchain 1.96.1 → 1.97.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/known/credentials.json +2 -1
- package/dist/known/nodes.json +4 -0
- package/dist/nodes/ToolExecutor/ToolExecutor.node.js.map +1 -1
- package/dist/nodes/ToolExecutor/utils/executeTool.js.map +1 -1
- package/dist/nodes/agents/Agent/V2/AgentV2.node.js +2 -1
- package/dist/nodes/agents/Agent/V2/AgentV2.node.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js +12 -2
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js +12 -2
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js.map +1 -1
- package/dist/nodes/agents/OpenAiAssistant/utils.js.map +1 -1
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js +9 -13
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js.map +1 -1
- package/dist/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.js +54 -13
- package/dist/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.js.map +1 -1
- package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js +54 -12
- package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js.map +1 -1
- package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js +2 -2
- package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js.map +1 -1
- package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js +1 -1
- package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js.map +1 -1
- package/dist/nodes/llms/N8nLlmTracing.js +12 -2
- package/dist/nodes/llms/N8nLlmTracing.js.map +1 -1
- package/dist/nodes/mcp/McpClientTool/utils.js +5 -2
- package/dist/nodes/mcp/McpClientTool/utils.js.map +1 -1
- package/dist/nodes/memory/MemoryManager/MemoryManager.node.js +20 -15
- package/dist/nodes/memory/MemoryManager/MemoryManager.node.js.map +1 -1
- package/dist/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.js +1 -1
- package/dist/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.js.map +1 -1
- package/dist/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.js +94 -16
- package/dist/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.js.map +1 -1
- package/dist/nodes/output_parser/OutputParserStructured/prompt.js +44 -0
- package/dist/nodes/output_parser/OutputParserStructured/prompt.js.map +1 -0
- package/dist/nodes/rerankers/RerankerCohere/RerankerCohere.node.js +107 -0
- package/dist/nodes/rerankers/RerankerCohere/RerankerCohere.node.js.map +1 -0
- package/dist/nodes/rerankers/RerankerCohere/cohere.dark.svg +5 -0
- package/dist/nodes/rerankers/RerankerCohere/cohere.svg +5 -0
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js +11 -1
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js.map +1 -1
- package/dist/nodes/tools/ToolCode/ToolCode.node.js +15 -4
- package/dist/nodes/tools/ToolCode/ToolCode.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v1/ToolWorkflowV1.node.js +1 -1
- package/dist/nodes/tools/ToolWorkflow/v1/ToolWorkflowV1.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +4 -3
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js +13 -3
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js +8 -2
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js.map +1 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js +23 -3
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js.map +1 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js +15 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js.map +1 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js +18 -2
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js +16 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js.map +1 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/types.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/helpers/utils.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/methods/listSearch.js +1 -1
- package/dist/nodes/vendors/OpenAi/methods/listSearch.js.map +1 -1
- package/dist/types/credentials.json +1 -1
- package/dist/types/nodes.json +19 -18
- package/dist/utils/descriptions.js +17 -2
- package/dist/utils/descriptions.js.map +1 -1
- package/dist/utils/logWrapper.js +23 -0
- package/dist/utils/logWrapper.js.map +1 -1
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js +5 -1
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js.map +1 -1
- package/dist/utils/schemaParsing.js +29 -5
- package/dist/utils/schemaParsing.js.map +1 -1
- package/package.json +9 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryManager/MemoryManager.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { BaseChatMemory } from '@langchain/community/memory/chat_memory';\nimport { AIMessage, SystemMessage, HumanMessage, type BaseMessage } from '@langchain/core/messages';\nimport { NodeConnectionTypes } from 'n8n-workflow';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\n\ntype MessageRole = 'ai' | 'system' | 'user';\ninterface MessageRecord {\n\ttype: MessageRole;\n\tmessage: string;\n\thideFromUI: boolean;\n}\n\nfunction simplifyMessages(messages: BaseMessage[]) {\n\tconst chunkedMessages = [];\n\tfor (let i = 0; i < messages.length; i += 2) {\n\t\tchunkedMessages.push([messages[i], messages[i + 1]]);\n\t}\n\n\tconst transformedMessages = chunkedMessages.map((exchange) => {\n\t\tconst simplified = {\n\t\t\t[exchange[0]._getType()]: exchange[0].content,\n\t\t};\n\n\t\tif (exchange[1]) {\n\t\t\tsimplified[exchange[1]._getType()] = exchange[1].content;\n\t\t}\n\n\t\treturn simplified;\n\t});\n\treturn transformedMessages;\n}\n\nconst prepareOutputSetup = (ctx: IExecuteFunctions, version: number, memory: BaseChatMemory) => {\n\tif (version === 1) {\n\t\t//legacy behavior of insert and delete for version 1\n\t\treturn async (i: number) => {\n\t\t\tconst messages = await memory.chatHistory.getMessages();\n\n\t\t\tconst serializedMessages = messages?.map((message) => message.toJSON()) ?? [];\n\n\t\t\tconst executionData = ctx.helpers.constructExecutionMetaData(\n\t\t\t\tctx.helpers.returnJsonArray(serializedMessages as unknown as IDataObject[]),\n\t\t\t\t{ itemData: { item: i } },\n\t\t\t);\n\n\t\t\treturn executionData;\n\t\t};\n\t}\n\treturn async (i: number) => {\n\t\treturn [\n\t\t\t{\n\t\t\t\tjson: { success: true },\n\t\t\t\tpairedItem: { item: i },\n\t\t\t},\n\t\t];\n\t};\n};\n\nexport class MemoryManager implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Chat Memory Manager',\n\t\tname: 'memoryManager',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Manage chat messages memory and use it in the workflow',\n\t\tdefaults: {\n\t\t\tname: 'Chat Memory Manager',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Miscellaneous', '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/sub-nodes/n8n-nodes-langchain.memorymanager/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: '',\n\t\t\t\ttype: NodeConnectionTypes.Main,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Memory',\n\t\t\t\ttype: NodeConnectionTypes.AiMemory,\n\t\t\t\trequired: true,\n\t\t\t\tmaxConnections: 1,\n\t\t\t},\n\t\t],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [\n\t\t\t{\n\t\t\t\tdisplayName: '',\n\t\t\t\ttype: NodeConnectionTypes.Main,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Operation Mode',\n\t\t\t\tname: 'mode',\n\t\t\t\ttype: 'options',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'load',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Get Many Messages',\n\t\t\t\t\t\tdescription: 'Retrieve chat messages from connected memory',\n\t\t\t\t\t\tvalue: 'load',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Insert Messages',\n\t\t\t\t\t\tdescription: 'Insert chat messages into connected memory',\n\t\t\t\t\t\tvalue: 'insert',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Delete Messages',\n\t\t\t\t\t\tdescription: 'Delete chat messages from connected memory',\n\t\t\t\t\t\tvalue: 'delete',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Insert Mode',\n\t\t\t\tname: 'insertMode',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'Choose how new messages are inserted into the memory',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'insert',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Insert Messages',\n\t\t\t\t\t\tvalue: 'insert',\n\t\t\t\t\t\tdescription: 'Add messages alongside existing ones',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Override All Messages',\n\t\t\t\t\t\tvalue: 'override',\n\t\t\t\t\t\tdescription: 'Replace the current memory with new messages',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Delete Mode',\n\t\t\t\tname: 'deleteMode',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'How messages are deleted from memory',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'lastN',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Last N',\n\t\t\t\t\t\tvalue: 'lastN',\n\t\t\t\t\t\tdescription: 'Delete the last N messages',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All Messages',\n\t\t\t\t\t\tvalue: 'all',\n\t\t\t\t\t\tdescription: 'Clear all messages from memory',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['delete'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Chat Messages',\n\t\t\t\tname: 'messages',\n\t\t\t\tdescription: 'Chat messages to insert into memory',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t},\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add message',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'messageValues',\n\t\t\t\t\t\tdisplayName: 'Message',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type Name or ID',\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\toptions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'AI',\n\t\t\t\t\t\t\t\t\t\tvalue: 'ai',\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: 'System',\n\t\t\t\t\t\t\t\t\t\tvalue: 'system',\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: 'User',\n\t\t\t\t\t\t\t\t\t\tvalue: 'user',\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: 'system',\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: 'Message',\n\t\t\t\t\t\t\t\tname: 'message',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdefault: '',\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: 'Hide Message in Chat',\n\t\t\t\t\t\t\t\tname: 'hideFromUI',\n\t\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\t\t\tdescription: 'Whether to hide the message from the chat UI',\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\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Messages Count',\n\t\t\t\tname: 'lastMessagesCount',\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'The amount of last messages to delete',\n\t\t\t\tdefault: 2,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['delete'],\n\t\t\t\t\t\tdeleteMode: ['lastN'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Simplify Output',\n\t\t\t\tname: 'simplifyOutput',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Whether to simplify the output to only include the sender and the text',\n\t\t\t\tdefault: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['load'],\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\tplaceholder: 'Add Option',\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: 'Group Messages',\n\t\t\t\t\t\tname: 'groupMessages',\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 group messages into a single item or return each message as a separate item',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['load'],\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 items = this.getInputData();\n\t\tconst mode = this.getNodeParameter('mode', 0, 'load') as 'load' | 'insert' | 'delete';\n\t\tconst memory = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiMemory,\n\t\t\t0,\n\t\t)) as BaseChatMemory;\n\n\t\tconst prepareOutput = prepareOutputSetup(this, nodeVersion, memory);\n\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\tfor (let i = 0; i < items.length; i++) {\n\t\t\tconst messages = await memory.chatHistory.getMessages();\n\n\t\t\tif (mode === 'delete') {\n\t\t\t\tconst deleteMode = this.getNodeParameter('deleteMode', i) as 'lastN' | 'all';\n\n\t\t\t\tif (deleteMode === 'lastN') {\n\t\t\t\t\tconst lastMessagesCount = this.getNodeParameter('lastMessagesCount', i) as number;\n\t\t\t\t\tif (messages.length >= lastMessagesCount) {\n\t\t\t\t\t\tconst newMessages = messages.slice(0, messages.length - lastMessagesCount);\n\n\t\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t\t\tfor (const message of newMessages) {\n\t\t\t\t\t\t\tawait memory.chatHistory.addMessage(message);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t}\n\n\t\t\t\treturnData.push(...(await prepareOutput(i)));\n\t\t\t}\n\n\t\t\tif (mode === 'insert') {\n\t\t\t\tconst insertMode = this.getNodeParameter('insertMode', i) as 'insert' | 'override';\n\t\t\t\tconst messagesToInsert = this.getNodeParameter(\n\t\t\t\t\t'messages.messageValues',\n\t\t\t\t\ti,\n\t\t\t\t\t[],\n\t\t\t\t) as MessageRecord[];\n\n\t\t\t\tconst templateMapper = {\n\t\t\t\t\tai: AIMessage,\n\t\t\t\t\tsystem: SystemMessage,\n\t\t\t\t\tuser: HumanMessage,\n\t\t\t\t};\n\n\t\t\t\tif (insertMode === 'override') {\n\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t}\n\n\t\t\t\tfor (const message of messagesToInsert) {\n\t\t\t\t\tconst MessageClass = new templateMapper[message.type](message.message);\n\n\t\t\t\t\tif (message.hideFromUI) {\n\t\t\t\t\t\tMessageClass.additional_kwargs.hideFromUI = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tawait memory.chatHistory.addMessage(MessageClass);\n\t\t\t\t}\n\n\t\t\t\treturnData.push(...(await prepareOutput(i)));\n\t\t\t}\n\n\t\t\tif (mode === 'load') {\n\t\t\t\tconst simplifyOutput = this.getNodeParameter('simplifyOutput', i, false) as boolean;\n\t\t\t\tconst options = this.getNodeParameter('options', i);\n\n\t\t\t\t//Load mode, legacy behavior for version 1, buggy - outputs only for single input item\n\t\t\t\tif (simplifyOutput && messages.length && nodeVersion === 1) {\n\t\t\t\t\tconst groupMessages = options.groupMessages as boolean;\n\t\t\t\t\tconst output = simplifyMessages(messages);\n\n\t\t\t\t\treturn [\n\t\t\t\t\t\tthis.helpers.constructExecutionMetaData(\n\t\t\t\t\t\t\tthis.helpers.returnJsonArray(\n\t\t\t\t\t\t\t\tgroupMessages ? [{ messages: output, messagesCount: output.length }] : output,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t{ itemData: { item: i } },\n\t\t\t\t\t\t),\n\t\t\t\t\t];\n\t\t\t\t}\n\n\t\t\t\tlet groupMessages = true;\n\t\t\t\t//disable grouping if explicitly set to false\n\t\t\t\tif (options.groupMessages === false) {\n\t\t\t\t\tgroupMessages = false;\n\t\t\t\t}\n\t\t\t\t//disable grouping if not set and node version is 1 (legacy behavior)\n\t\t\t\tif (options.groupMessages === undefined && nodeVersion === 1) {\n\t\t\t\t\tgroupMessages = false;\n\t\t\t\t}\n\n\t\t\t\tlet output: IDataObject[] =\n\t\t\t\t\t(simplifyOutput\n\t\t\t\t\t\t? simplifyMessages(messages)\n\t\t\t\t\t\t: (messages?.map((message) => message.toJSON()) as unknown as IDataObject[])) ?? [];\n\n\t\t\t\tif (groupMessages) {\n\t\t\t\t\toutput = [{ messages: output, messagesCount: output.length }];\n\t\t\t\t}\n\n\t\t\t\tconst executionData = this.helpers.constructExecutionMetaData(\n\t\t\t\t\tthis.helpers.returnJsonArray(output),\n\t\t\t\t\t{ itemData: { item: i } },\n\t\t\t\t);\n\n\t\t\t\treturnData.push(...executionData);\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAyE;AACzE,0BAAoC;AAgBpC,SAAS,iBAAiB,UAAyB;AAClD,QAAM,kBAAkB,CAAC;AACzB,WAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK,GAAG;AAC5C,oBAAgB,KAAK,CAAC,SAAS,CAAC,GAAG,SAAS,IAAI,CAAC,CAAC,CAAC;AAAA,EACpD;AAEA,QAAM,sBAAsB,gBAAgB,IAAI,CAAC,aAAa;AAC7D,UAAM,aAAa;AAAA,MAClB,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,GAAG,SAAS,CAAC,EAAE;AAAA,IACvC;AAEA,QAAI,SAAS,CAAC,GAAG;AAChB,iBAAW,SAAS,CAAC,EAAE,SAAS,CAAC,IAAI,SAAS,CAAC,EAAE;AAAA,IAClD;AAEA,WAAO;AAAA,EACR,CAAC;AACD,SAAO;AACR;AAEA,MAAM,qBAAqB,CAAC,KAAwB,SAAiB,WAA2B;AAC/F,MAAI,YAAY,GAAG;AAElB,WAAO,OAAO,MAAc;AAC3B,YAAM,WAAW,MAAM,OAAO,YAAY,YAAY;AAEtD,YAAM,qBAAqB,UAAU,IAAI,CAAC,YAAY,QAAQ,OAAO,CAAC,KAAK,CAAC;AAE5E,YAAM,gBAAgB,IAAI,QAAQ;AAAA,QACjC,IAAI,QAAQ,g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cAAM,gBAAgB,KAAK,QAAQ;AAAA,UAClC,KAAK,QAAQ,gBAAgB,MAAM;AAAA,UACnC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;AAAA,QACzB;AAEA,mBAAW,KAAK,GAAG,aAAa;AAAA,MACjC;AAAA,IACD;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":["groupMessages","output"]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryManager/MemoryManager.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { BaseChatMemory } from '@langchain/community/memory/chat_memory';\nimport type { MessageContent, BaseMessage } from '@langchain/core/messages';\nimport { AIMessage, SystemMessage, HumanMessage } from '@langchain/core/messages';\nimport { NodeConnectionTypes } from 'n8n-workflow';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\n\ntype MessageRole = 'ai' | 'system' | 'user';\ninterface MessageRecord {\n\ttype: MessageRole;\n\tmessage: string;\n\thideFromUI: boolean;\n}\n\nexport function simplifyMessages(messages: BaseMessage[]): Array<Record<string, MessageContent>> {\n\tif (messages.length === 0) return [];\n\n\tconst result: Array<Record<string, MessageContent>> = [];\n\tlet index = 0;\n\n\twhile (index < messages.length) {\n\t\tconst currentGroup: Record<string, MessageContent> = {};\n\n\t\tdo {\n\t\t\tconst message = messages[index];\n\t\t\tconst messageType = message.getType();\n\n\t\t\tif (messageType in currentGroup) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentGroup[messageType] = message.content;\n\t\t\tindex++;\n\t\t} while (index < messages.length);\n\n\t\tresult.push(currentGroup);\n\t}\n\n\treturn result;\n}\n\nconst prepareOutputSetup = (ctx: IExecuteFunctions, version: number, memory: BaseChatMemory) => {\n\tif (version === 1) {\n\t\t//legacy behavior of insert and delete for version 1\n\t\treturn async (i: number) => {\n\t\t\tconst messages = await memory.chatHistory.getMessages();\n\n\t\t\tconst serializedMessages = messages?.map((message) => message.toJSON()) ?? [];\n\n\t\t\tconst executionData = ctx.helpers.constructExecutionMetaData(\n\t\t\t\tctx.helpers.returnJsonArray(serializedMessages as unknown as IDataObject[]),\n\t\t\t\t{ itemData: { item: i } },\n\t\t\t);\n\n\t\t\treturn executionData;\n\t\t};\n\t}\n\treturn async (i: number) => {\n\t\treturn [\n\t\t\t{\n\t\t\t\tjson: { success: true },\n\t\t\t\tpairedItem: { item: i },\n\t\t\t},\n\t\t];\n\t};\n};\n\nexport class MemoryManager implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Chat Memory Manager',\n\t\tname: 'memoryManager',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Manage chat messages memory and use it in the workflow',\n\t\tdefaults: {\n\t\t\tname: 'Chat Memory Manager',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Miscellaneous', '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/sub-nodes/n8n-nodes-langchain.memorymanager/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: '',\n\t\t\t\ttype: NodeConnectionTypes.Main,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Memory',\n\t\t\t\ttype: NodeConnectionTypes.AiMemory,\n\t\t\t\trequired: true,\n\t\t\t\tmaxConnections: 1,\n\t\t\t},\n\t\t],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [\n\t\t\t{\n\t\t\t\tdisplayName: '',\n\t\t\t\ttype: NodeConnectionTypes.Main,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Operation Mode',\n\t\t\t\tname: 'mode',\n\t\t\t\ttype: 'options',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'load',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Get Many Messages',\n\t\t\t\t\t\tdescription: 'Retrieve chat messages from connected memory',\n\t\t\t\t\t\tvalue: 'load',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Insert Messages',\n\t\t\t\t\t\tdescription: 'Insert chat messages into connected memory',\n\t\t\t\t\t\tvalue: 'insert',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Delete Messages',\n\t\t\t\t\t\tdescription: 'Delete chat messages from connected memory',\n\t\t\t\t\t\tvalue: 'delete',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Insert Mode',\n\t\t\t\tname: 'insertMode',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'Choose how new messages are inserted into the memory',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'insert',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Insert Messages',\n\t\t\t\t\t\tvalue: 'insert',\n\t\t\t\t\t\tdescription: 'Add messages alongside existing ones',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Override All Messages',\n\t\t\t\t\t\tvalue: 'override',\n\t\t\t\t\t\tdescription: 'Replace the current memory with new messages',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Delete Mode',\n\t\t\t\tname: 'deleteMode',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'How messages are deleted from memory',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'lastN',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Last N',\n\t\t\t\t\t\tvalue: 'lastN',\n\t\t\t\t\t\tdescription: 'Delete the last N messages',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All Messages',\n\t\t\t\t\t\tvalue: 'all',\n\t\t\t\t\t\tdescription: 'Clear all messages from memory',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['delete'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Chat Messages',\n\t\t\t\tname: 'messages',\n\t\t\t\tdescription: 'Chat messages to insert into memory',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t},\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add message',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'messageValues',\n\t\t\t\t\t\tdisplayName: 'Message',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type Name or ID',\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\toptions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'AI',\n\t\t\t\t\t\t\t\t\t\tvalue: 'ai',\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: 'System',\n\t\t\t\t\t\t\t\t\t\tvalue: 'system',\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: 'User',\n\t\t\t\t\t\t\t\t\t\tvalue: 'user',\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: 'system',\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: 'Message',\n\t\t\t\t\t\t\t\tname: 'message',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdefault: '',\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: 'Hide Message in Chat',\n\t\t\t\t\t\t\t\tname: 'hideFromUI',\n\t\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\t\t\tdescription: 'Whether to hide the message from the chat UI',\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\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Messages Count',\n\t\t\t\tname: 'lastMessagesCount',\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'The amount of last messages to delete',\n\t\t\t\tdefault: 2,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['delete'],\n\t\t\t\t\t\tdeleteMode: ['lastN'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Simplify Output',\n\t\t\t\tname: 'simplifyOutput',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Whether to simplify the output to only include the sender and the text',\n\t\t\t\tdefault: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['load'],\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\tplaceholder: 'Add Option',\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: 'Group Messages',\n\t\t\t\t\t\tname: 'groupMessages',\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 group messages into a single item or return each message as a separate item',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['load'],\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 items = this.getInputData();\n\t\tconst mode = this.getNodeParameter('mode', 0, 'load') as 'load' | 'insert' | 'delete';\n\t\tconst memory = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiMemory,\n\t\t\t0,\n\t\t)) as BaseChatMemory;\n\n\t\tconst prepareOutput = prepareOutputSetup(this, nodeVersion, memory);\n\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\tfor (let i = 0; i < items.length; i++) {\n\t\t\tconst messages = await memory.chatHistory.getMessages();\n\n\t\t\tif (mode === 'delete') {\n\t\t\t\tconst deleteMode = this.getNodeParameter('deleteMode', i) as 'lastN' | 'all';\n\n\t\t\t\tif (deleteMode === 'lastN') {\n\t\t\t\t\tconst lastMessagesCount = this.getNodeParameter('lastMessagesCount', i) as number;\n\t\t\t\t\tif (messages.length >= lastMessagesCount) {\n\t\t\t\t\t\tconst newMessages = messages.slice(0, messages.length - lastMessagesCount);\n\n\t\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t\t\tfor (const message of newMessages) {\n\t\t\t\t\t\t\tawait memory.chatHistory.addMessage(message);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t}\n\n\t\t\t\treturnData.push(...(await prepareOutput(i)));\n\t\t\t}\n\n\t\t\tif (mode === 'insert') {\n\t\t\t\tconst insertMode = this.getNodeParameter('insertMode', i) as 'insert' | 'override';\n\t\t\t\tconst messagesToInsert = this.getNodeParameter(\n\t\t\t\t\t'messages.messageValues',\n\t\t\t\t\ti,\n\t\t\t\t\t[],\n\t\t\t\t) as MessageRecord[];\n\n\t\t\t\tconst templateMapper = {\n\t\t\t\t\tai: AIMessage,\n\t\t\t\t\tsystem: SystemMessage,\n\t\t\t\t\tuser: HumanMessage,\n\t\t\t\t};\n\n\t\t\t\tif (insertMode === 'override') {\n\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t}\n\n\t\t\t\tfor (const message of messagesToInsert) {\n\t\t\t\t\tconst MessageClass = new templateMapper[message.type](message.message);\n\n\t\t\t\t\tif (message.hideFromUI) {\n\t\t\t\t\t\tMessageClass.additional_kwargs.hideFromUI = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tawait memory.chatHistory.addMessage(MessageClass);\n\t\t\t\t}\n\n\t\t\t\treturnData.push(...(await prepareOutput(i)));\n\t\t\t}\n\n\t\t\tif (mode === 'load') {\n\t\t\t\tconst simplifyOutput = this.getNodeParameter('simplifyOutput', i, false) as boolean;\n\t\t\t\tconst options = this.getNodeParameter('options', i);\n\n\t\t\t\t//Load mode, legacy behavior for version 1, buggy - outputs only for single input item\n\t\t\t\tif (simplifyOutput && messages.length && nodeVersion === 1) {\n\t\t\t\t\tconst groupMessages = options.groupMessages as boolean;\n\t\t\t\t\tconst output = simplifyMessages(messages);\n\n\t\t\t\t\treturn [\n\t\t\t\t\t\tthis.helpers.constructExecutionMetaData(\n\t\t\t\t\t\t\tthis.helpers.returnJsonArray(\n\t\t\t\t\t\t\t\tgroupMessages ? [{ messages: output, messagesCount: output.length }] : output,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t{ itemData: { item: i } },\n\t\t\t\t\t\t),\n\t\t\t\t\t];\n\t\t\t\t}\n\n\t\t\t\tlet groupMessages = true;\n\t\t\t\t//disable grouping if explicitly set to false\n\t\t\t\tif (options.groupMessages === false) {\n\t\t\t\t\tgroupMessages = false;\n\t\t\t\t}\n\t\t\t\t//disable grouping if not set and node version is 1 (legacy behavior)\n\t\t\t\tif (options.groupMessages === undefined && nodeVersion === 1) {\n\t\t\t\t\tgroupMessages = false;\n\t\t\t\t}\n\n\t\t\t\tlet output: IDataObject[] =\n\t\t\t\t\t(simplifyOutput\n\t\t\t\t\t\t? simplifyMessages(messages)\n\t\t\t\t\t\t: (messages?.map((message) => message.toJSON()) as unknown as IDataObject[])) ?? [];\n\n\t\t\t\tif (groupMessages) {\n\t\t\t\t\toutput = [{ messages: output, messagesCount: output.length }];\n\t\t\t\t}\n\n\t\t\t\tconst executionData = this.helpers.constructExecutionMetaData(\n\t\t\t\t\tthis.helpers.returnJsonArray(output),\n\t\t\t\t\t{ itemData: { item: i } },\n\t\t\t\t);\n\n\t\t\t\treturnData.push(...executionData);\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAuD;AACvD,0BAAoC;AAgB7B,SAAS,iBAAiB,UAAgE;AAChG,MAAI,SAAS,WAAW,EAAG,QAAO,CAAC;AAEnC,QAAM,SAAgD,CAAC;AACvD,MAAI,QAAQ;AAEZ,SAAO,QAAQ,SAAS,QAAQ;AAC/B,UAAM,eAA+C,CAAC;AAEtD,OAAG;AACF,YAAM,UAAU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AAQ,eAAeA,QAAO,OAAO,CAAC,IAAIA;AAAA,cACxE;AAAA,cACA,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;AAAA,YACzB;AAAA,UACD;AAAA,QACD;AAEA,YAAI,gBAAgB;AAEpB,YAAI,QAAQ,kBAAkB,OAAO;AACpC,0BAAgB;AAAA,QACjB;AAEA,YAAI,QAAQ,kBAAkB,UAAa,gBAAgB,GAAG;AAC7D,0BAAgB;AAAA,QACjB;AAEA,YAAI,UACF,iBACE,iBAAiB,QAAQ,IACxB,UAAU,IAAI,CAAC,YAAY,QAAQ,OAAO,CAAC,MAAmC,CAAC;AAEpF,YAAI,eAAe;AAClB,mBAAS,CAAC,EAAE,UAAU,QAAQ,eAAe,OAAO,OAAO,CAAC;AAAA,QAC7D;AAEA,cAAM,gBAAgB,KAAK,QAAQ;AAAA,UAClC,KAAK,QAAQ,gBAAgB,MAAM;AAAA,UACnC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;AAAA,QACzB;AAEA,mBAAW,KAAK,GAAG,aAAa;AAAA,MACjC;AAAA,IACD;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":["groupMessages","output"]}
|
|
@@ -35,7 +35,7 @@ class OutputParserAutofixing {
|
|
|
35
35
|
iconColor: "black",
|
|
36
36
|
group: ["transform"],
|
|
37
37
|
version: 1,
|
|
38
|
-
description: "
|
|
38
|
+
description: "Deprecated, use structured output parser",
|
|
39
39
|
defaults: {
|
|
40
40
|
name: "Auto-fixing Output Parser"
|
|
41
41
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { PromptTemplate } from '@langchain/core/prompts';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\n\nimport {\n\tN8nOutputFixingParser,\n\ttype N8nStructuredOutputParser,\n} from '@utils/output_parsers/N8nOutputParser';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { NAIVE_FIX_PROMPT } from './prompt';\n\nexport class OutputParserAutofixing implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Auto-fixing Output Parser',\n\t\tname: 'outputParserAutofixing',\n\t\ticon: 'fa:tools',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: '
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { PromptTemplate } from '@langchain/core/prompts';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\n\nimport {\n\tN8nOutputFixingParser,\n\ttype N8nStructuredOutputParser,\n} from '@utils/output_parsers/N8nOutputParser';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { NAIVE_FIX_PROMPT } from './prompt';\n\nexport class OutputParserAutofixing implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Auto-fixing Output Parser',\n\t\tname: 'outputParserAutofixing',\n\t\ticon: 'fa:tools',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Deprecated, use structured output parser',\n\t\tdefaults: {\n\t\t\tname: 'Auto-fixing Output Parser',\n\t\t},\n\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Output Parsers'],\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/sub-nodes/n8n-nodes-langchain.outputparserautofixing/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Output Parser',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\trequired: true,\n\t\t\t\ttype: NodeConnectionTypes.AiOutputParser,\n\t\t\t},\n\t\t],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiOutputParser],\n\t\toutputNames: ['Output Parser'],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t'This node wraps another output parser. If the first one fails it calls an LLM to fix the format',\n\t\t\t\tname: 'info',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiAgent]),\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\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Retry Prompt',\n\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: NAIVE_FIX_PROMPT,\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 10,\n\t\t\t\t\t\t},\n\t\t\t\t\t\thint: 'Should include \"{error}\", \"{instructions}\", and \"{completion}\" placeholders',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Prompt template used for fixing the output. Uses placeholders: \"{instructions}\" for parsing rules, \"{completion}\" for the failed attempt, and \"{error}\" for the validation error message.',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst model = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\titemIndex,\n\t\t)) as BaseLanguageModel;\n\t\tconst outputParser = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiOutputParser,\n\t\t\titemIndex,\n\t\t)) as N8nStructuredOutputParser;\n\t\tconst prompt = this.getNodeParameter('options.prompt', itemIndex, NAIVE_FIX_PROMPT) as string;\n\n\t\tif (prompt.length === 0 || !prompt.includes('{error}')) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Auto-fixing parser prompt has to contain {error} placeholder',\n\t\t\t);\n\t\t}\n\t\tconst parser = new N8nOutputFixingParser(\n\t\t\tthis,\n\t\t\tmodel,\n\t\t\toutputParser,\n\t\t\tPromptTemplate.fromTemplate(prompt),\n\t\t);\n\n\t\treturn {\n\t\t\tresponse: parser,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA+B;AAC/B,0BAAwD;AAQxD,6BAGO;AACP,0BAA6C;AAE7C,oBAAiC;AAE1B,MAAM,uBAA4C;AAAA,EAAlD;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MAEA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,gBA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AS,GAAG;AACvD,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,MACD;AAAA,IACD;AACA,UAAM,SAAS,IAAI;AAAA,MAClB;AAAA,MACA;AAAA,MACA;AAAA,MACA,8BAAe,aAAa,MAAM;AAAA,IACnC;AAEA,WAAO;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
|
|
@@ -21,11 +21,13 @@ __export(OutputParserStructured_node_exports, {
|
|
|
21
21
|
OutputParserStructured: () => OutputParserStructured
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(OutputParserStructured_node_exports);
|
|
24
|
+
var import_prompts = require("@langchain/core/prompts");
|
|
24
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
25
26
|
var import_descriptions = require("../../../utils/descriptions");
|
|
26
27
|
var import_N8nOutputParser = require("../../../utils/output_parsers/N8nOutputParser");
|
|
27
28
|
var import_schemaParsing = require("../../../utils/schemaParsing");
|
|
28
29
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
30
|
+
var import_prompt = require("./prompt");
|
|
29
31
|
class OutputParserStructured {
|
|
30
32
|
constructor() {
|
|
31
33
|
this.description = {
|
|
@@ -34,8 +36,8 @@ class OutputParserStructured {
|
|
|
34
36
|
icon: "fa:code",
|
|
35
37
|
iconColor: "black",
|
|
36
38
|
group: ["transform"],
|
|
37
|
-
version: [1, 1.1, 1.2],
|
|
38
|
-
defaultVersion: 1.
|
|
39
|
+
version: [1, 1.1, 1.2, 1.3],
|
|
40
|
+
defaultVersion: 1.3,
|
|
39
41
|
description: "Return data in a defined JSON format",
|
|
40
42
|
defaults: {
|
|
41
43
|
name: "Structured Output Parser"
|
|
@@ -54,8 +56,17 @@ class OutputParserStructured {
|
|
|
54
56
|
]
|
|
55
57
|
}
|
|
56
58
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
inputs: `={{
|
|
60
|
+
((parameters) => {
|
|
61
|
+
if (parameters?.autoFix) {
|
|
62
|
+
return [
|
|
63
|
+
{ displayName: 'Model', maxConnections: 1, type: "${import_n8n_workflow.NodeConnectionTypes.AiLanguageModel}", required: true }
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return [];
|
|
68
|
+
})($parameter)
|
|
69
|
+
}}`,
|
|
59
70
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
60
71
|
outputs: [import_n8n_workflow.NodeConnectionTypes.AiOutputParser],
|
|
61
72
|
outputNames: ["Output Parser"],
|
|
@@ -69,6 +80,11 @@ class OutputParserStructured {
|
|
|
69
80
|
"cities": ["Los Angeles", "San Francisco", "San Diego"]
|
|
70
81
|
}`
|
|
71
82
|
},
|
|
83
|
+
(0, import_descriptions.buildJsonSchemaExampleNotice)({
|
|
84
|
+
showExtraProps: {
|
|
85
|
+
"@version": [{ _cnd: { gte: 1.3 } }]
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
72
88
|
{
|
|
73
89
|
...import_descriptions.inputSchemaField,
|
|
74
90
|
default: `{
|
|
@@ -116,15 +132,49 @@ class OutputParserStructured {
|
|
|
116
132
|
}
|
|
117
133
|
},
|
|
118
134
|
{
|
|
119
|
-
displayName:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
displayName: "Auto-Fix Format",
|
|
136
|
+
description: "Whether to automatically fix the output when it is not in the correct format. Will cause another LLM call.",
|
|
137
|
+
name: "autoFix",
|
|
138
|
+
type: "boolean",
|
|
139
|
+
default: false
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
displayName: "Customize Retry Prompt",
|
|
143
|
+
name: "customizeRetryPrompt",
|
|
144
|
+
type: "boolean",
|
|
123
145
|
displayOptions: {
|
|
124
|
-
|
|
125
|
-
|
|
146
|
+
show: {
|
|
147
|
+
autoFix: [true]
|
|
126
148
|
}
|
|
127
|
-
}
|
|
149
|
+
},
|
|
150
|
+
default: false,
|
|
151
|
+
description: "Whether to customize the prompt used for retrying the output parsing. If disabled, a default prompt will be used."
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
displayName: "Custom Prompt",
|
|
155
|
+
name: "prompt",
|
|
156
|
+
type: "string",
|
|
157
|
+
displayOptions: {
|
|
158
|
+
show: {
|
|
159
|
+
autoFix: [true],
|
|
160
|
+
customizeRetryPrompt: [true]
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
default: import_prompt.NAIVE_FIX_PROMPT,
|
|
164
|
+
typeOptions: {
|
|
165
|
+
rows: 10
|
|
166
|
+
},
|
|
167
|
+
hint: 'Should include "{error}", "{instructions}", and "{completion}" placeholders',
|
|
168
|
+
description: 'Prompt template used for fixing the output. Uses placeholders: "{instructions}" for parsing rules, "{completion}" for the failed attempt, and "{error}" for the validation error message.'
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
hints: [
|
|
172
|
+
{
|
|
173
|
+
message: "Fields that use $refs might have the wrong type, since this syntax is not currently supported",
|
|
174
|
+
type: "warning",
|
|
175
|
+
location: "outputPane",
|
|
176
|
+
whenToDisplay: "afterExecution",
|
|
177
|
+
displayCondition: '={{ $parameter["schemaType"] === "manual" && $parameter["inputSchema"]?.includes("$ref") }}'
|
|
128
178
|
}
|
|
129
179
|
]
|
|
130
180
|
};
|
|
@@ -133,26 +183,54 @@ class OutputParserStructured {
|
|
|
133
183
|
const schemaType = this.getNodeParameter("schemaType", itemIndex, "");
|
|
134
184
|
const jsonExample = this.getNodeParameter("jsonSchemaExample", itemIndex, "");
|
|
135
185
|
let inputSchema;
|
|
186
|
+
const jsonExampleAllFieldsRequired = this.getNode().typeVersion >= 1.3;
|
|
136
187
|
if (this.getNode().typeVersion <= 1.1) {
|
|
137
188
|
inputSchema = this.getNodeParameter("jsonSchema", itemIndex, "");
|
|
138
189
|
} else {
|
|
139
190
|
inputSchema = this.getNodeParameter("inputSchema", itemIndex, "");
|
|
140
191
|
}
|
|
141
|
-
const jsonSchema = schemaType === "fromJson" ? (0, import_schemaParsing.
|
|
192
|
+
const jsonSchema = schemaType === "fromJson" ? (0, import_schemaParsing.generateSchemaFromExample)(jsonExample, jsonExampleAllFieldsRequired) : (0, import_n8n_workflow.jsonParse)(inputSchema);
|
|
142
193
|
const zodSchema = (0, import_schemaParsing.convertJsonSchemaToZod)(jsonSchema);
|
|
143
194
|
const nodeVersion = this.getNode().typeVersion;
|
|
195
|
+
const autoFix = this.getNodeParameter("autoFix", itemIndex, false);
|
|
196
|
+
let outputParser;
|
|
144
197
|
try {
|
|
145
|
-
|
|
198
|
+
outputParser = await import_N8nOutputParser.N8nStructuredOutputParser.fromZodJsonSchema(
|
|
146
199
|
zodSchema,
|
|
147
200
|
nodeVersion,
|
|
148
201
|
this
|
|
149
202
|
);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
throw new import_n8n_workflow.NodeOperationError(
|
|
205
|
+
this.getNode(),
|
|
206
|
+
"Error during parsing of JSON Schema. Please check the schema and try again."
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
if (!autoFix) {
|
|
150
210
|
return {
|
|
151
|
-
response:
|
|
211
|
+
response: outputParser
|
|
152
212
|
};
|
|
153
|
-
} catch (error) {
|
|
154
|
-
throw new import_n8n_workflow.NodeOperationError(this.getNode(), "Error during parsing of JSON Schema.");
|
|
155
213
|
}
|
|
214
|
+
const model = await this.getInputConnectionData(
|
|
215
|
+
import_n8n_workflow.NodeConnectionTypes.AiLanguageModel,
|
|
216
|
+
itemIndex
|
|
217
|
+
);
|
|
218
|
+
const prompt = this.getNodeParameter("prompt", itemIndex, import_prompt.NAIVE_FIX_PROMPT);
|
|
219
|
+
if (prompt.length === 0 || !prompt.includes("{error}")) {
|
|
220
|
+
throw new import_n8n_workflow.NodeOperationError(
|
|
221
|
+
this.getNode(),
|
|
222
|
+
"Auto-fixing parser prompt has to contain {error} placeholder"
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
const parser = new import_N8nOutputParser.N8nOutputFixingParser(
|
|
226
|
+
this,
|
|
227
|
+
model,
|
|
228
|
+
outputParser,
|
|
229
|
+
import_prompts.PromptTemplate.fromTemplate(prompt)
|
|
230
|
+
);
|
|
231
|
+
return {
|
|
232
|
+
response: parser
|
|
233
|
+
};
|
|
156
234
|
}
|
|
157
235
|
}
|
|
158
236
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/output_parser/OutputParserStructured/OutputParserStructured.node.ts"],"sourcesContent":["import type { JSONSchema7 } from 'json-schema';\nimport {\n\tjsonParse,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\tNodeOperationError,\n\tNodeConnectionTypes,\n} from 'n8n-workflow';\nimport type { z } from 'zod';\n\nimport { inputSchemaField, jsonSchemaExampleField, schemaTypeField } from '@utils/descriptions';\nimport { N8nStructuredOutputParser } from '@utils/output_parsers/N8nOutputParser';\nimport { convertJsonSchemaToZod, generateSchema } from '@utils/schemaParsing';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nexport class OutputParserStructured implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Structured Output Parser',\n\t\tname: 'outputParserStructured',\n\t\ticon: 'fa:code',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2],\n\t\tdefaultVersion: 1.2,\n\t\tdescription: 'Return data in a defined JSON format',\n\t\tdefaults: {\n\t\t\tname: 'Structured Output Parser',\n\t\t},\n\n\t\tcodex: {\n\t\t\talias: ['json', 'zod'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Output Parsers'],\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/sub-nodes/n8n-nodes-langchain.outputparserstructured/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiOutputParser],\n\t\toutputNames: ['Output Parser'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiAgent]),\n\t\t\t{ ...schemaTypeField, displayOptions: { show: { '@version': [{ _cnd: { gte: 1.2 } }] } } },\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\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: 'JSON Schema',\n\t\t\t\tname: 'jsonSchema',\n\t\t\t\ttype: 'json',\n\t\t\t\tdescription: 'JSON Schema to structure and validate the output against',\n\t\t\t\tdefault: `{\n \"type\": \"object\",\n \"properties\": {\n \"state\": {\n \"type\": \"string\"\n },\n \"cities\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n }\n }\n}`,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 10,\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 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:\n\t\t\t\t\t'The schema has to be defined in the <a target=\"_blank\" href=\"https://json-schema.org/\">JSON Schema</a> format. Look at <a target=\"_blank\" href=\"https://json-schema.org/learn/miscellaneous-examples.html\">this</a> page for examples.',\n\t\t\t\tname: 'notice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\thide: {\n\t\t\t\t\t\tschemaType: ['fromJson'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst schemaType = this.getNodeParameter('schemaType', itemIndex, '') as 'fromJson' | 'manual';\n\t\t// We initialize these even though one of them will always be empty\n\t\t// it makes it easer to navigate the ternary operator\n\t\tconst jsonExample = this.getNodeParameter('jsonSchemaExample', itemIndex, '') as string;\n\t\tlet inputSchema: string;\n\n\t\tif (this.getNode().typeVersion <= 1.1) {\n\t\t\tinputSchema = this.getNodeParameter('jsonSchema', itemIndex, '') as string;\n\t\t} else {\n\t\t\tinputSchema = this.getNodeParameter('inputSchema', itemIndex, '') as string;\n\t\t}\n\n\t\tconst jsonSchema =\n\t\t\tschemaType === 'fromJson' ? generateSchema(jsonExample) : jsonParse<JSONSchema7>(inputSchema);\n\n\t\tconst zodSchema = convertJsonSchemaToZod<z.ZodSchema<object>>(jsonSchema);\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\t\ttry {\n\t\t\tconst parser = await N8nStructuredOutputParser.fromZodJsonSchema(\n\t\t\t\tzodSchema,\n\t\t\t\tnodeVersion,\n\t\t\t\tthis,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tresponse: parser,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(this.getNode(), 'Error during parsing of JSON Schema.');\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAQO;AAGP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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAcT,aAAa;AAAA,YACZ,MAAM;AAAA,UACP;AAAA,UACA,UAAU;AAAA,UACV,gBAAgB;AAAA,YACf,MAAM;AAAA,cACL,YAAY,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC;AAAA,YACpC;AAAA,UACD;AAAA,QACD;AAAA,QACA;AAAA,UACC,aACC;AAAA,UACD,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,gBAAgB;AAAA,YACf,MAAM;AAAA,cACL,YAAY,CAAC,UAAU;AAAA,YACxB;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,aAAa,KAAK,iBAAiB,cAAc,WAAW,EAAE;AAGpE,UAAM,cAAc,KAAK,iBAAiB,qBAAqB,WAAW,EAAE;AAC5E,QAAI;AAEJ,QAAI,KAAK,QAAQ,EAAE,eAAe,KAAK;AACtC,oBAAc,KAAK,iBAAiB,cAAc,WAAW,EAAE;AAAA,IAChE,OAAO;AACN,oBAAc,KAAK,iBAAiB,eAAe,WAAW,EAAE;AAAA,IACjE;AAEA,UAAM,aACL,eAAe,iBAAa,qCAAe,WAAW,QAAI,+BAAuB,WAAW;AAE7F,UAAM,gBAAY,6CAA4C,UAAU;AACxE,UAAM,cAAc,KAAK,QAAQ,EAAE;AACnC,QAAI;AACH,YAAM,SAAS,MAAM,iDAA0B;AAAA,QAC9C;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,aAAO;AAAA,QACN,UAAU;AAAA,MACX;AAAA,IACD,SAAS,OAAO;AACf,YAAM,IAAI,uCAAmB,KAAK,QAAQ,GAAG,sCAAsC;AAAA,IACpF;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/output_parser/OutputParserStructured/OutputParserStructured.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { PromptTemplate } from '@langchain/core/prompts';\nimport type { JSONSchema7 } from 'json-schema';\nimport {\n\tjsonParse,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\tNodeOperationError,\n\tNodeConnectionTypes,\n} from 'n8n-workflow';\nimport type { z } from 'zod';\n\nimport {\n\tbuildJsonSchemaExampleNotice,\n\tinputSchemaField,\n\tjsonSchemaExampleField,\n\tschemaTypeField,\n} from '@utils/descriptions';\nimport {\n\tN8nOutputFixingParser,\n\tN8nStructuredOutputParser,\n} from '@utils/output_parsers/N8nOutputParser';\nimport { convertJsonSchemaToZod, generateSchemaFromExample } from '@utils/schemaParsing';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { NAIVE_FIX_PROMPT } from './prompt';\n\nexport class OutputParserStructured implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Structured Output Parser',\n\t\tname: 'outputParserStructured',\n\t\ticon: 'fa:code',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdefaultVersion: 1.3,\n\t\tdescription: 'Return data in a defined JSON format',\n\t\tdefaults: {\n\t\t\tname: 'Structured Output Parser',\n\t\t},\n\n\t\tcodex: {\n\t\t\talias: ['json', 'zod'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Output Parsers'],\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/sub-nodes/n8n-nodes-langchain.outputparserstructured/',\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((parameters) => {\n\t\t\t\tif (parameters?.autoFix) {\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{ displayName: 'Model', maxConnections: 1, type: \"${NodeConnectionTypes.AiLanguageModel}\", required: true }\n\t\t\t\t\t];\n\t\t\t\t}\n\n\t\t\t\treturn [];\n\t\t\t})($parameter)\n\t\t}}`,\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiOutputParser],\n\t\toutputNames: ['Output Parser'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiAgent]),\n\t\t\t{ ...schemaTypeField, displayOptions: { show: { '@version': [{ _cnd: { gte: 1.2 } }] } } },\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.3 } }],\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: 'JSON Schema',\n\t\t\t\tname: 'jsonSchema',\n\t\t\t\ttype: 'json',\n\t\t\t\tdescription: 'JSON Schema to structure and validate the output against',\n\t\t\t\tdefault: `{\n \"type\": \"object\",\n \"properties\": {\n \"state\": {\n \"type\": \"string\"\n },\n \"cities\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n }\n }\n}`,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 10,\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 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: 'Auto-Fix Format',\n\t\t\t\tdescription:\n\t\t\t\t\t'Whether to automatically fix the output when it is not in the correct format. Will cause another LLM call.',\n\t\t\t\tname: 'autoFix',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Customize Retry Prompt',\n\t\t\t\tname: 'customizeRetryPrompt',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tautoFix: [true],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tdefault: false,\n\t\t\t\tdescription:\n\t\t\t\t\t'Whether to customize the prompt used for retrying the output parsing. If disabled, a default prompt will be used.',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Custom Prompt',\n\t\t\t\tname: 'prompt',\n\t\t\t\ttype: 'string',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tautoFix: [true],\n\t\t\t\t\t\tcustomizeRetryPrompt: [true],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tdefault: NAIVE_FIX_PROMPT,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 10,\n\t\t\t\t},\n\t\t\t\thint: 'Should include \"{error}\", \"{instructions}\", and \"{completion}\" placeholders',\n\t\t\t\tdescription:\n\t\t\t\t\t'Prompt template used for fixing the output. Uses placeholders: \"{instructions}\" for parsing rules, \"{completion}\" for the failed attempt, and \"{error}\" for the validation error message.',\n\t\t\t},\n\t\t],\n\t\thints: [\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t'Fields that use $refs might have the wrong type, since this syntax is not currently supported',\n\t\t\t\ttype: 'warning',\n\t\t\t\tlocation: 'outputPane',\n\t\t\t\twhenToDisplay: 'afterExecution',\n\t\t\t\tdisplayCondition:\n\t\t\t\t\t'={{ $parameter[\"schemaType\"] === \"manual\" && $parameter[\"inputSchema\"]?.includes(\"$ref\") }}',\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst schemaType = this.getNodeParameter('schemaType', itemIndex, '') as 'fromJson' | 'manual';\n\t\t// We initialize these even though one of them will always be empty\n\t\t// it makes it easer to navigate the ternary operator\n\t\tconst jsonExample = this.getNodeParameter('jsonSchemaExample', itemIndex, '') as string;\n\n\t\tlet inputSchema: string;\n\n\t\t// Enforce all fields to be required in the generated schema if the node version is 1.3 or higher\n\t\tconst jsonExampleAllFieldsRequired = this.getNode().typeVersion >= 1.3;\n\n\t\tif (this.getNode().typeVersion <= 1.1) {\n\t\t\tinputSchema = this.getNodeParameter('jsonSchema', itemIndex, '') as string;\n\t\t} else {\n\t\t\tinputSchema = this.getNodeParameter('inputSchema', itemIndex, '') as string;\n\t\t}\n\n\t\tconst jsonSchema =\n\t\t\tschemaType === 'fromJson'\n\t\t\t\t? generateSchemaFromExample(jsonExample, jsonExampleAllFieldsRequired)\n\t\t\t\t: jsonParse<JSONSchema7>(inputSchema);\n\n\t\tconst zodSchema = convertJsonSchemaToZod<z.ZodSchema<object>>(jsonSchema);\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tconst autoFix = this.getNodeParameter('autoFix', itemIndex, false) as boolean;\n\n\t\tlet outputParser;\n\t\ttry {\n\t\t\toutputParser = await N8nStructuredOutputParser.fromZodJsonSchema(\n\t\t\t\tzodSchema,\n\t\t\t\tnodeVersion,\n\t\t\t\tthis,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Error during parsing of JSON Schema. Please check the schema and try again.',\n\t\t\t);\n\t\t}\n\n\t\tif (!autoFix) {\n\t\t\treturn {\n\t\t\t\tresponse: outputParser,\n\t\t\t};\n\t\t}\n\n\t\tconst model = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\titemIndex,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst prompt = this.getNodeParameter('prompt', itemIndex, NAIVE_FIX_PROMPT) as string;\n\n\t\tif (prompt.length === 0 || !prompt.includes('{error}')) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Auto-fixing parser prompt has to contain {error} placeholder',\n\t\t\t);\n\t\t}\n\t\tconst parser = new N8nOutputFixingParser(\n\t\t\tthis,\n\t\t\tmodel,\n\t\t\toutputParser,\n\t\t\tPromptTemplate.fromTemplate(prompt),\n\t\t);\n\n\t\treturn {\n\t\t\tresponse: parser,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA+B;AAE/B,0BAQO;AAGP,0BAKO;AACP,6BAGO;AACP,2BAAkE;AAClE,0BAA6C;AAE7C,oBAAiC;AAE1B,MAAM,uBAA4C;AAAA,EAAlD;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,GAAG;AAAA,MAC1B,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MAEA,OAAO;AAAA,QACN,OAAO,CAAC,QAAQ,KAAK;AAAA,QACrB,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,gBAAgB;AAAA,QACtB;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD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AAA,QAC9C;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD,SAAS,OAAO;AACf,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,MACD;AAAA,IACD;AAEA,QAAI,CAAC,SAAS;AACb,aAAO;AAAA,QACN,UAAU;AAAA,MACX;AAAA,IACD;AAEA,UAAM,QAAS,MAAM,KAAK;AAAA,MACzB,wCAAoB;AAAA,MACpB;AAAA,IACD;AAEA,UAAM,SAAS,KAAK,iBAAiB,UAAU,WAAW,8BAAgB;AAE1E,QAAI,OAAO,WAAW,KAAK,CAAC,OAAO,SAAS,SAAS,GAAG;AACvD,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,MACD;AAAA,IACD;AACA,UAAM,SAAS,IAAI;AAAA,MAClB;AAAA,MACA;AAAA,MACA;AAAA,MACA,8BAAe,aAAa,MAAM;AAAA,IACnC;AAEA,WAAO;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var prompt_exports = {};
|
|
20
|
+
__export(prompt_exports, {
|
|
21
|
+
NAIVE_FIX_PROMPT: () => NAIVE_FIX_PROMPT
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(prompt_exports);
|
|
24
|
+
const NAIVE_FIX_PROMPT = `Instructions:
|
|
25
|
+
--------------
|
|
26
|
+
{instructions}
|
|
27
|
+
--------------
|
|
28
|
+
Completion:
|
|
29
|
+
--------------
|
|
30
|
+
{completion}
|
|
31
|
+
--------------
|
|
32
|
+
|
|
33
|
+
Above, the Completion did not satisfy the constraints given in the Instructions.
|
|
34
|
+
Error:
|
|
35
|
+
--------------
|
|
36
|
+
{error}
|
|
37
|
+
--------------
|
|
38
|
+
|
|
39
|
+
Please try again. Please only respond with an answer that satisfies the constraints laid out in the Instructions:`;
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
NAIVE_FIX_PROMPT
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/output_parser/OutputParserStructured/prompt.ts"],"sourcesContent":["export const NAIVE_FIX_PROMPT = `Instructions:\n--------------\n{instructions}\n--------------\nCompletion:\n--------------\n{completion}\n--------------\n\nAbove, the Completion did not satisfy the constraints given in the Instructions.\nError:\n--------------\n{error}\n--------------\n\nPlease try again. Please only respond with an answer that satisfies the constraints laid out in the Instructions:`;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var RerankerCohere_node_exports = {};
|
|
20
|
+
__export(RerankerCohere_node_exports, {
|
|
21
|
+
RerankerCohere: () => RerankerCohere
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(RerankerCohere_node_exports);
|
|
24
|
+
var import_cohere = require("@langchain/cohere");
|
|
25
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
26
|
+
var import_logWrapper = require("../../../utils/logWrapper");
|
|
27
|
+
class RerankerCohere {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.description = {
|
|
30
|
+
displayName: "Reranker Cohere",
|
|
31
|
+
name: "rerankerCohere",
|
|
32
|
+
icon: { light: "file:cohere.svg", dark: "file:cohere.dark.svg" },
|
|
33
|
+
group: ["transform"],
|
|
34
|
+
version: 1,
|
|
35
|
+
description: "Use Cohere Reranker to reorder documents after retrieval from a vector store by relevance to the given query.",
|
|
36
|
+
defaults: {
|
|
37
|
+
name: "Reranker Cohere"
|
|
38
|
+
},
|
|
39
|
+
requestDefaults: {
|
|
40
|
+
ignoreHttpStatusErrors: true,
|
|
41
|
+
baseURL: "={{ $credentials.host }}"
|
|
42
|
+
},
|
|
43
|
+
credentials: [
|
|
44
|
+
{
|
|
45
|
+
name: "cohereApi",
|
|
46
|
+
required: true
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
codex: {
|
|
50
|
+
categories: ["AI"],
|
|
51
|
+
subcategories: {
|
|
52
|
+
AI: ["Rerankers"]
|
|
53
|
+
},
|
|
54
|
+
resources: {
|
|
55
|
+
primaryDocumentation: [
|
|
56
|
+
{
|
|
57
|
+
url: "https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.rerankercohere/"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
inputs: [],
|
|
63
|
+
outputs: [import_n8n_workflow.NodeConnectionTypes.AiReranker],
|
|
64
|
+
outputNames: ["Reranker"],
|
|
65
|
+
properties: [
|
|
66
|
+
{
|
|
67
|
+
displayName: "Model",
|
|
68
|
+
name: "modelName",
|
|
69
|
+
type: "options",
|
|
70
|
+
description: 'The model that should be used to rerank the documents. <a href="https://docs.cohere.com/docs/models">Learn more</a>.',
|
|
71
|
+
default: "rerank-v3.5",
|
|
72
|
+
options: [
|
|
73
|
+
{
|
|
74
|
+
name: "rerank-v3.5",
|
|
75
|
+
value: "rerank-v3.5"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "rerank-english-v3.0",
|
|
79
|
+
value: "rerank-english-v3.0"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "rerank-multilingual-v3.0",
|
|
83
|
+
value: "rerank-multilingual-v3.0"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async supplyData(itemIndex) {
|
|
91
|
+
this.logger.debug("Supply data for reranking Cohere");
|
|
92
|
+
const modelName = this.getNodeParameter("modelName", itemIndex, "rerank-v3.5");
|
|
93
|
+
const credentials = await this.getCredentials("cohereApi");
|
|
94
|
+
const reranker = new import_cohere.CohereRerank({
|
|
95
|
+
apiKey: credentials.apiKey,
|
|
96
|
+
model: modelName
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
response: (0, import_logWrapper.logWrapper)(reranker, this)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
RerankerCohere
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=RerankerCohere.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/rerankers/RerankerCohere/RerankerCohere.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport { CohereRerank } from '@langchain/cohere';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\n\nexport class RerankerCohere implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Reranker Cohere',\n\t\tname: 'rerankerCohere',\n\t\ticon: { light: 'file:cohere.svg', dark: 'file:cohere.dark.svg' },\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription:\n\t\t\t'Use Cohere Reranker to reorder documents after retrieval from a vector store by relevance to the given query.',\n\t\tdefaults: {\n\t\t\tname: 'Reranker Cohere',\n\t\t},\n\t\trequestDefaults: {\n\t\t\tignoreHttpStatusErrors: true,\n\t\t\tbaseURL: '={{ $credentials.host }}',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'cohereApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Rerankers'],\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/sub-nodes/n8n-nodes-langchain.rerankercohere/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [NodeConnectionTypes.AiReranker],\n\t\toutputNames: ['Reranker'],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tname: 'modelName',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription:\n\t\t\t\t\t'The model that should be used to rerank the documents. <a href=\"https://docs.cohere.com/docs/models\">Learn more</a>.',\n\t\t\t\tdefault: 'rerank-v3.5',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'rerank-v3.5',\n\t\t\t\t\t\tvalue: 'rerank-v3.5',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'rerank-english-v3.0',\n\t\t\t\t\t\tvalue: 'rerank-english-v3.0',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'rerank-multilingual-v3.0',\n\t\t\t\t\t\tvalue: 'rerank-multilingual-v3.0',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supply data for reranking Cohere');\n\t\tconst modelName = this.getNodeParameter('modelName', itemIndex, 'rerank-v3.5') as string;\n\t\tconst credentials = await this.getCredentials<{ apiKey: string }>('cohereApi');\n\t\tconst reranker = new CohereRerank({\n\t\t\tapiKey: credentials.apiKey,\n\t\t\tmodel: modelName,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(reranker, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;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AAW,aAAa;AAC7E,UAAM,cAAc,MAAM,KAAK,eAAmC,WAAW;AAC7E,UAAM,WAAW,IAAI,2BAAa;AAAA,MACjC,QAAQ,YAAY;AAAA,MACpB,OAAO;AAAA,IACR,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,UAAU,IAAI;AAAA,IACpC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.96 23.84C14.0267 23.84 16.16 23.7867 19.1467 22.56C22.6133 21.12 29.44 18.56 34.4 15.8933C37.8667 14.0267 39.36 11.5733 39.36 8.26667C39.36 3.73333 35.68 0 31.0933 0H11.8933C5.33333 0 0 5.33333 0 11.8933C0 18.4533 5.01333 23.84 12.96 23.84Z" fill="white"/>
|
|
3
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M16.2134 31.9999C16.2134 28.7999 18.1334 25.8666 21.12 24.6399L27.1467 22.1333C33.28 19.6266 40 24.1066 40 30.7199C40 35.8399 35.84 39.9999 30.72 39.9999H24.16C19.7867 39.9999 16.2134 36.4266 16.2134 31.9999Z" fill="white"/>
|
|
4
|
+
<path d="M6.88 25.3867C3.09333 25.3867 0 28.4801 0 32.2667V33.1734C0 36.9067 3.09333 40.0001 6.88 40.0001C10.6667 40.0001 13.76 36.9067 13.76 33.1201V32.2134C13.7067 28.4801 10.6667 25.3867 6.88 25.3867Z" fill="white"/>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.96 23.84C14.0267 23.84 16.16 23.7867 19.1467 22.56C22.6133 21.12 29.44 18.56 34.4 15.8933C37.8667 14.0267 39.36 11.5733 39.36 8.26667C39.36 3.73333 35.68 0 31.0933 0H11.8933C5.33333 0 0 5.33333 0 11.8933C0 18.4533 5.01333 23.84 12.96 23.84Z" fill="#39594D"/>
|
|
3
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M16.2134 31.9999C16.2134 28.7999 18.1334 25.8666 21.12 24.6399L27.1467 22.1333C33.28 19.6266 40 24.1066 40 30.7199C40 35.8399 35.84 39.9999 30.72 39.9999H24.16C19.7867 39.9999 16.2134 36.4266 16.2134 31.9999Z" fill="#D18EE2"/>
|
|
4
|
+
<path d="M6.88 25.3867C3.09333 25.3867 0 28.4801 0 32.2667V33.1734C0 36.9067 3.09333 40.0001 6.88 40.0001C10.6667 40.0001 13.76 36.9067 13.76 33.1201V32.2134C13.7067 28.4801 10.6667 25.3867 6.88 25.3867Z" fill="#FF7759"/>
|
|
5
|
+
</svg>
|
|
@@ -21,6 +21,8 @@ __export(RetrieverVectorStore_node_exports, {
|
|
|
21
21
|
RetrieverVectorStore: () => RetrieverVectorStore
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(RetrieverVectorStore_node_exports);
|
|
24
|
+
var import_vectorstores = require("@langchain/core/vectorstores");
|
|
25
|
+
var import_contextual_compression = require("langchain/retrievers/contextual_compression");
|
|
24
26
|
var import_n8n_workflow = require("n8n-workflow");
|
|
25
27
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
26
28
|
class RetrieverVectorStore {
|
|
@@ -79,7 +81,15 @@ class RetrieverVectorStore {
|
|
|
79
81
|
import_n8n_workflow.NodeConnectionTypes.AiVectorStore,
|
|
80
82
|
itemIndex
|
|
81
83
|
);
|
|
82
|
-
|
|
84
|
+
let retriever = null;
|
|
85
|
+
if (vectorStore instanceof import_vectorstores.VectorStore) {
|
|
86
|
+
retriever = vectorStore.asRetriever(topK);
|
|
87
|
+
} else {
|
|
88
|
+
retriever = new import_contextual_compression.ContextualCompressionRetriever({
|
|
89
|
+
baseCompressor: vectorStore.reranker,
|
|
90
|
+
baseRetriever: vectorStore.vectorStore.asRetriever(topK)
|
|
91
|
+
});
|
|
92
|
+
}
|
|
83
93
|
return {
|
|
84
94
|
response: (0, import_logWrapper.logWrapper)(retriever, this)
|
|
85
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\n\nexport class RetrieverVectorStore implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Vector Store Retriever',\n\t\tname: 'retrieverVectorStore',\n\t\ticon: 'fa:box-open',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Use a Vector Store as Retriever',\n\t\tdefaults: {\n\t\t\tname: 'Vector Store Retriever',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Retrievers'],\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/sub-nodes/n8n-nodes-langchain.retrievervectorstore/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Vector Store',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiVectorStore,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiRetriever],\n\t\toutputNames: ['Retriever'],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Limit',\n\t\t\t\tname: 'topK',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 4,\n\t\t\t\tdescription: 'The maximum number of results to return',\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supplying data for Vector Store Retriever');\n\n\t\tconst topK = this.getNodeParameter('topK', itemIndex, 4) as number;\n\t\tconst vectorStore = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiVectorStore,\n\t\t\titemIndex,\n\t\t)) as VectorStore;\n\n\t\
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';\nimport { VectorStore } from '@langchain/core/vectorstores';\nimport { ContextualCompressionRetriever } from 'langchain/retrievers/contextual_compression';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\n\nexport class RetrieverVectorStore implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Vector Store Retriever',\n\t\tname: 'retrieverVectorStore',\n\t\ticon: 'fa:box-open',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Use a Vector Store as Retriever',\n\t\tdefaults: {\n\t\t\tname: 'Vector Store Retriever',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Retrievers'],\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/sub-nodes/n8n-nodes-langchain.retrievervectorstore/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Vector Store',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiVectorStore,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiRetriever],\n\t\toutputNames: ['Retriever'],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Limit',\n\t\t\t\tname: 'topK',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 4,\n\t\t\t\tdescription: 'The maximum number of results to return',\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supplying data for Vector Store Retriever');\n\n\t\tconst topK = this.getNodeParameter('topK', itemIndex, 4) as number;\n\t\tconst vectorStore = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiVectorStore,\n\t\t\titemIndex,\n\t\t)) as\n\t\t\t| VectorStore\n\t\t\t| {\n\t\t\t\t\treranker: BaseDocumentCompressor;\n\t\t\t\t\tvectorStore: VectorStore;\n\t\t\t };\n\n\t\tlet retriever = null;\n\n\t\tif (vectorStore instanceof VectorStore) {\n\t\t\tretriever = vectorStore.asRetriever(topK);\n\t\t} else {\n\t\t\tretriever = new ContextualCompressionRetriever({\n\t\t\t\tbaseCompressor: vectorStore.reranker,\n\t\t\t\tbaseRetriever: vectorStore.vectorStore.asRetriever(topK),\n\t\t\t});\n\t\t}\n\n\t\tre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