@n8n/n8n-nodes-langchain 1.86.0 → 1.87.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/credentials/AnthropicApi.credentials.js +1 -0
- package/dist/credentials/AnthropicApi.credentials.js.map +1 -0
- package/dist/credentials/AzureOpenAiApi.credentials.js +1 -0
- package/dist/credentials/AzureOpenAiApi.credentials.js.map +1 -0
- package/dist/credentials/CohereApi.credentials.js +1 -0
- package/dist/credentials/CohereApi.credentials.js.map +1 -0
- package/dist/credentials/DeepSeekApi.credentials.js +1 -0
- package/dist/credentials/DeepSeekApi.credentials.js.map +1 -0
- package/dist/credentials/GooglePalmApi.credentials.js +1 -0
- package/dist/credentials/GooglePalmApi.credentials.js.map +1 -0
- package/dist/credentials/GroqApi.credentials.js +1 -0
- package/dist/credentials/GroqApi.credentials.js.map +1 -0
- package/dist/credentials/HuggingFaceApi.credentials.js +1 -0
- package/dist/credentials/HuggingFaceApi.credentials.js.map +1 -0
- package/dist/credentials/MistralCloudApi.credentials.js +1 -0
- package/dist/credentials/MistralCloudApi.credentials.js.map +1 -0
- package/dist/credentials/MotorheadApi.credentials.js +1 -0
- package/dist/credentials/MotorheadApi.credentials.js.map +1 -0
- package/dist/credentials/OllamaApi.credentials.js +1 -0
- package/dist/credentials/OllamaApi.credentials.js.map +1 -0
- package/dist/credentials/OpenRouterApi.credentials.js +1 -0
- package/dist/credentials/OpenRouterApi.credentials.js.map +1 -0
- package/dist/credentials/PineconeApi.credentials.js +1 -0
- package/dist/credentials/PineconeApi.credentials.js.map +1 -0
- package/dist/credentials/QdrantApi.credentials.js +1 -0
- package/dist/credentials/QdrantApi.credentials.js.map +1 -0
- package/dist/credentials/SerpApi.credentials.js +1 -0
- package/dist/credentials/SerpApi.credentials.js.map +1 -0
- package/dist/credentials/WolframAlphaApi.credentials.js +1 -0
- package/dist/credentials/WolframAlphaApi.credentials.js.map +1 -0
- package/dist/credentials/XAiApi.credentials.js +1 -0
- package/dist/credentials/XAiApi.credentials.js.map +1 -0
- package/dist/credentials/XataApi.credentials.js +1 -0
- package/dist/credentials/XataApi.credentials.js.map +1 -0
- package/dist/credentials/ZepApi.credentials.js +1 -0
- package/dist/credentials/ZepApi.credentials.js.map +1 -0
- package/dist/known/nodes.json +12 -0
- package/dist/nodes/agents/Agent/Agent.node.js +1 -0
- package/dist/nodes/agents/Agent/Agent.node.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/description.js +1 -0
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/description.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js +1 -0
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/prompt.js +1 -0
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/prompt.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/description.js +1 -0
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/description.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js +1 -0
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/prompt.js +1 -0
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/prompt.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/description.js +1 -0
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/description.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js +1 -0
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/prompt.js +1 -0
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/prompt.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ReActAgent/description.js +1 -0
- package/dist/nodes/agents/Agent/agents/ReActAgent/description.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js +1 -0
- package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ReActAgent/prompt.js +1 -0
- package/dist/nodes/agents/Agent/agents/ReActAgent/prompt.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/description.js +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/description.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/execute.js +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/execute.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/other/handlers/mysql.js +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/other/handlers/mysql.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/other/handlers/postgres.js +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/other/handlers/postgres.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/other/handlers/sqlite.js +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/other/handlers/sqlite.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/other/prompts.js +1 -0
- package/dist/nodes/agents/Agent/agents/SqlAgent/other/prompts.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/description.js +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/description.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/execute.js +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/execute.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/prompt.js +1 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/prompt.js.map +1 -0
- package/dist/nodes/agents/Agent/agents/utils.js +1 -0
- package/dist/nodes/agents/Agent/agents/utils.js.map +1 -0
- package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js +1 -0
- package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js.map +1 -0
- package/dist/nodes/agents/OpenAiAssistant/utils.js +1 -0
- package/dist/nodes/agents/OpenAiAssistant/utils.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js +1 -0
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/chainExecutor.js +1 -0
- package/dist/nodes/chains/ChainLLM/methods/chainExecutor.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/config.js +1 -0
- package/dist/nodes/chains/ChainLLM/methods/config.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/imageUtils.js +1 -0
- package/dist/nodes/chains/ChainLLM/methods/imageUtils.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/index.js +1 -0
- package/dist/nodes/chains/ChainLLM/methods/index.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/promptUtils.js +1 -0
- package/dist/nodes/chains/ChainLLM/methods/promptUtils.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/responseFormatter.js +1 -0
- package/dist/nodes/chains/ChainLLM/methods/responseFormatter.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/types.js +1 -0
- package/dist/nodes/chains/ChainLLM/methods/types.js.map +1 -0
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js +1 -0
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js.map +1 -0
- package/dist/nodes/chains/ChainSummarization/ChainSummarization.node.js +1 -0
- package/dist/nodes/chains/ChainSummarization/ChainSummarization.node.js.map +1 -0
- package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js +1 -0
- package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js.map +1 -0
- package/dist/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.js +1 -0
- package/dist/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.js.map +1 -0
- package/dist/nodes/chains/ChainSummarization/helpers.js +1 -0
- package/dist/nodes/chains/ChainSummarization/helpers.js.map +1 -0
- package/dist/nodes/chains/ChainSummarization/prompt.js +1 -0
- package/dist/nodes/chains/ChainSummarization/prompt.js.map +1 -0
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js +1 -0
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js.map +1 -0
- package/dist/nodes/chains/InformationExtractor/helpers.js +1 -0
- package/dist/nodes/chains/InformationExtractor/helpers.js.map +1 -0
- package/dist/nodes/chains/InformationExtractor/types.js +1 -0
- package/dist/nodes/chains/InformationExtractor/types.js.map +1 -0
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js +1 -0
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js.map +1 -0
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js +1 -0
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js.map +1 -0
- package/dist/nodes/code/Code.node.js +1 -0
- package/dist/nodes/code/Code.node.js.map +1 -0
- package/dist/nodes/document_loaders/DocumentBinaryInputLoader/DocumentBinaryInputLoader.node.js +1 -0
- package/dist/nodes/document_loaders/DocumentBinaryInputLoader/DocumentBinaryInputLoader.node.js.map +1 -0
- package/dist/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.js +1 -0
- package/dist/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.js.map +1 -0
- package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js +1 -0
- package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js.map +1 -0
- package/dist/nodes/document_loaders/DocumentJSONInputLoader/DocumentJsonInputLoader.node.js +1 -0
- package/dist/nodes/document_loaders/DocumentJSONInputLoader/DocumentJsonInputLoader.node.js.map +1 -0
- package/dist/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.js +1 -0
- package/dist/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.js.map +1 -0
- package/dist/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.js +1 -0
- package/dist/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.js.map +1 -0
- package/dist/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.js +1 -0
- package/dist/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.js.map +1 -0
- package/dist/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.js +1 -0
- package/dist/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.js.map +1 -0
- package/dist/nodes/embeddings/EmbeddingsGoogleVertex/EmbeddingsGoogleVertex.node.js +166 -0
- package/dist/nodes/embeddings/EmbeddingsGoogleVertex/EmbeddingsGoogleVertex.node.js.map +1 -0
- package/dist/nodes/embeddings/EmbeddingsGoogleVertex/google.svg +1 -0
- package/dist/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.js +1 -0
- package/dist/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.js.map +1 -0
- package/dist/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.js +1 -0
- package/dist/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.js.map +1 -0
- package/dist/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.js +1 -0
- package/dist/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.js.map +1 -0
- package/dist/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.js +1 -0
- package/dist/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.js.map +1 -0
- package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js +1 -0
- package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js.map +1 -0
- package/dist/nodes/llms/LMChatAnthropic/methods/searchModels.js +1 -0
- package/dist/nodes/llms/LMChatAnthropic/methods/searchModels.js.map +1 -0
- package/dist/nodes/llms/LMChatOllama/LmChatOllama.node.js +1 -0
- package/dist/nodes/llms/LMChatOllama/LmChatOllama.node.js.map +1 -0
- package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js +1 -0
- package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js.map +1 -0
- package/dist/nodes/llms/LMChatOpenAi/methods/loadModels.js +1 -0
- package/dist/nodes/llms/LMChatOpenAi/methods/loadModels.js.map +1 -0
- package/dist/nodes/llms/LMCohere/LmCohere.node.js +1 -0
- package/dist/nodes/llms/LMCohere/LmCohere.node.js.map +1 -0
- package/dist/nodes/llms/LMOllama/LmOllama.node.js +1 -0
- package/dist/nodes/llms/LMOllama/LmOllama.node.js.map +1 -0
- package/dist/nodes/llms/LMOllama/description.js +1 -0
- package/dist/nodes/llms/LMOllama/description.js.map +1 -0
- package/dist/nodes/llms/LMOpenAi/LmOpenAi.node.js +1 -0
- package/dist/nodes/llms/LMOpenAi/LmOpenAi.node.js.map +1 -0
- package/dist/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.js +1 -0
- package/dist/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.js.map +1 -0
- package/dist/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.js +1 -0
- package/dist/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.js.map +1 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js +1 -0
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js.map +1 -0
- package/dist/nodes/llms/LmChatDeepSeek/LmChatDeepSeek.node.js +1 -0
- package/dist/nodes/llms/LmChatDeepSeek/LmChatDeepSeek.node.js.map +1 -0
- package/dist/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.js +1 -0
- package/dist/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.js.map +1 -0
- package/dist/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.js +1 -0
- package/dist/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.js.map +1 -0
- package/dist/nodes/llms/LmChatGoogleVertex/error-handling.js +1 -0
- package/dist/nodes/llms/LmChatGoogleVertex/error-handling.js.map +1 -0
- package/dist/nodes/llms/LmChatGroq/LmChatGroq.node.js +1 -0
- package/dist/nodes/llms/LmChatGroq/LmChatGroq.node.js.map +1 -0
- package/dist/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.js +1 -0
- package/dist/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.js.map +1 -0
- package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js +1 -0
- package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js.map +1 -0
- package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js +1 -0
- package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js.map +1 -0
- package/dist/nodes/llms/N8nLlmTracing.js +1 -0
- package/dist/nodes/llms/N8nLlmTracing.js.map +1 -0
- package/dist/nodes/llms/gemini-common/additional-options.js +1 -0
- package/dist/nodes/llms/gemini-common/additional-options.js.map +1 -0
- package/dist/nodes/llms/gemini-common/safety-options.js +1 -0
- package/dist/nodes/llms/gemini-common/safety-options.js.map +1 -0
- package/dist/nodes/llms/n8nDefaultFailedAttemptHandler.js +1 -0
- package/dist/nodes/llms/n8nDefaultFailedAttemptHandler.js.map +1 -0
- package/dist/nodes/llms/n8nLlmFailedAttemptHandler.js +1 -0
- package/dist/nodes/llms/n8nLlmFailedAttemptHandler.js.map +1 -0
- package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js +1 -0
- package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js.map +1 -0
- package/dist/nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.js +1 -0
- package/dist/nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.js.map +1 -0
- package/dist/nodes/memory/MemoryManager/MemoryManager.node.js +1 -0
- package/dist/nodes/memory/MemoryManager/MemoryManager.node.js.map +1 -0
- package/dist/nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.js +155 -0
- package/dist/nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.js.map +1 -0
- package/dist/nodes/memory/MemoryMongoDbChat/mongodb.dark.svg +3 -0
- package/dist/nodes/memory/MemoryMongoDbChat/mongodb.svg +3 -0
- package/dist/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.js +1 -0
- package/dist/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.js.map +1 -0
- package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js +1 -0
- package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js.map +1 -0
- package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js +1 -0
- package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js.map +1 -0
- package/dist/nodes/memory/MemoryXata/MemoryXata.node.js +1 -0
- package/dist/nodes/memory/MemoryXata/MemoryXata.node.js.map +1 -0
- package/dist/nodes/memory/MemoryZep/MemoryZep.node.js +1 -0
- package/dist/nodes/memory/MemoryZep/MemoryZep.node.js.map +1 -0
- package/dist/nodes/memory/descriptions.js +1 -0
- package/dist/nodes/memory/descriptions.js.map +1 -0
- package/dist/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.js +1 -0
- package/dist/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.js.map +1 -0
- package/dist/nodes/output_parser/OutputParserAutofixing/prompt.js +1 -0
- package/dist/nodes/output_parser/OutputParserAutofixing/prompt.js.map +1 -0
- package/dist/nodes/output_parser/OutputParserItemList/OutputParserItemList.node.js +1 -0
- package/dist/nodes/output_parser/OutputParserItemList/OutputParserItemList.node.js.map +1 -0
- package/dist/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.js +1 -0
- package/dist/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.js.map +1 -0
- package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js +1 -0
- package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js.map +1 -0
- package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js +1 -0
- package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js.map +1 -0
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js +1 -0
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js.map +1 -0
- package/dist/nodes/retrievers/RetrieverWorkflow/RetrieverWorkflow.node.js +1 -0
- package/dist/nodes/retrievers/RetrieverWorkflow/RetrieverWorkflow.node.js.map +1 -0
- package/dist/nodes/text_splitters/TextSplitterCharacterTextSplitter/TextSplitterCharacterTextSplitter.node.js +1 -0
- package/dist/nodes/text_splitters/TextSplitterCharacterTextSplitter/TextSplitterCharacterTextSplitter.node.js.map +1 -0
- package/dist/nodes/text_splitters/TextSplitterRecursiveCharacterTextSplitter/TextSplitterRecursiveCharacterTextSplitter.node.js +1 -0
- package/dist/nodes/text_splitters/TextSplitterRecursiveCharacterTextSplitter/TextSplitterRecursiveCharacterTextSplitter.node.js.map +1 -0
- package/dist/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.js +1 -0
- package/dist/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.js.map +1 -0
- package/dist/nodes/tools/ToolCalculator/ToolCalculator.node.js +1 -0
- package/dist/nodes/tools/ToolCalculator/ToolCalculator.node.js.map +1 -0
- package/dist/nodes/tools/ToolCode/ToolCode.node.js +1 -0
- package/dist/nodes/tools/ToolCode/ToolCode.node.js.map +1 -0
- package/dist/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.js +1 -0
- package/dist/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.js.map +1 -0
- package/dist/nodes/tools/ToolHttpRequest/descriptions.js +1 -0
- package/dist/nodes/tools/ToolHttpRequest/descriptions.js.map +1 -0
- package/dist/nodes/tools/ToolHttpRequest/interfaces.js +1 -0
- package/dist/nodes/tools/ToolHttpRequest/interfaces.js.map +1 -0
- package/dist/nodes/tools/ToolHttpRequest/utils.js +3 -2
- package/dist/nodes/tools/ToolHttpRequest/utils.js.map +1 -0
- package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js +1 -0
- package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js.map +1 -0
- package/dist/nodes/tools/ToolThink/ToolThink.node.js +94 -0
- package/dist/nodes/tools/ToolThink/ToolThink.node.js.map +1 -0
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js +1 -0
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js.map +1 -0
- package/dist/nodes/tools/ToolWikipedia/ToolWikipedia.node.js +1 -0
- package/dist/nodes/tools/ToolWikipedia/ToolWikipedia.node.js.map +1 -0
- package/dist/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.js +1 -0
- package/dist/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.js.map +1 -0
- package/dist/nodes/tools/ToolWorkflow/ToolWorkflow.node.js +1 -0
- package/dist/nodes/tools/ToolWorkflow/ToolWorkflow.node.js.map +1 -0
- package/dist/nodes/tools/ToolWorkflow/v1/ToolWorkflowV1.node.js +1 -0
- package/dist/nodes/tools/ToolWorkflow/v1/ToolWorkflowV1.node.js.map +1 -0
- package/dist/nodes/tools/ToolWorkflow/v1/versionDescription.js +1 -0
- package/dist/nodes/tools/ToolWorkflow/v1/versionDescription.js.map +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.js +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.js.map +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/methods/index.js +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/methods/index.js.map +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/methods/localResourceMapping.js +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/methods/localResourceMapping.js.map +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/versionDescription.js +1 -0
- package/dist/nodes/tools/ToolWorkflow/v2/versionDescription.js.map +1 -0
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js +1 -0
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js.map +1 -0
- package/dist/nodes/trigger/ChatTrigger/GenericFunctions.js +1 -0
- package/dist/nodes/trigger/ChatTrigger/GenericFunctions.js.map +1 -0
- package/dist/nodes/trigger/ChatTrigger/constants.js +1 -0
- package/dist/nodes/trigger/ChatTrigger/constants.js.map +1 -0
- package/dist/nodes/trigger/ChatTrigger/error.js +1 -0
- package/dist/nodes/trigger/ChatTrigger/error.js.map +1 -0
- package/dist/nodes/trigger/ChatTrigger/templates.js +1 -0
- package/dist/nodes/trigger/ChatTrigger/templates.js.map +1 -0
- package/dist/nodes/trigger/ChatTrigger/types.js +1 -0
- package/dist/nodes/trigger/ChatTrigger/types.js.map +1 -0
- package/dist/nodes/trigger/ManualChatTrigger/ManualChatTrigger.node.js +1 -0
- package/dist/nodes/trigger/ManualChatTrigger/ManualChatTrigger.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreInMemoryLoad/VectorStoreInMemoryLoad.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreInMemoryLoad/VectorStoreInMemoryLoad.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.js +1 -0
- package/dist/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStorePinecone/VectorStorePinecone.node.js +1 -0
- package/dist/nodes/vector_store/VectorStorePinecone/VectorStorePinecone.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStorePineconeInsert/VectorStorePineconeInsert.node.js +1 -0
- package/dist/nodes/vector_store/VectorStorePineconeInsert/VectorStorePineconeInsert.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStorePineconeLoad/VectorStorePineconeLoad.node.js +1 -0
- package/dist/nodes/vector_store/VectorStorePineconeLoad/VectorStorePineconeLoad.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreSupabase/VectorStoreSupabase.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreSupabase/VectorStoreSupabase.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreSupabaseInsert/VectorStoreSupabaseInsert.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreSupabaseInsert/VectorStoreSupabaseInsert.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.js +1 -0
- package/dist/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.js.map +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryCalculator.js +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryCalculator.js.map +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryVectorStoreManager.js +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryVectorStoreManager.js.map +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/StoreCleanupService.js +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/StoreCleanupService.js.map +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/config.js +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/config.js.map +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/types.js +1 -0
- package/dist/nodes/vector_store/shared/MemoryManager/types.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/constants.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/constants.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/index.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/index.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/insertOperation.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/insertOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/updateOperation.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/updateOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/types.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/types.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/utils.js +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/utils.js.map +1 -0
- package/dist/nodes/vector_store/shared/descriptions.js +1 -0
- package/dist/nodes/vector_store/shared/descriptions.js.map +1 -0
- package/dist/nodes/vector_store/shared/processDocuments.js +1 -0
- package/dist/nodes/vector_store/shared/processDocuments.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/OpenAi.node.js +1 -0
- package/dist/nodes/vendors/OpenAi/OpenAi.node.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/create.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/create.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/deleteAssistant.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/deleteAssistant.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/index.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/index.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/list.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/list.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/message.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/message.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/update.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/assistant/update.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/audio/generate.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/audio/generate.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/audio/index.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/audio/index.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/audio/transcribe.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/audio/transcribe.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/audio/translate.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/audio/translate.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/descriptions.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/descriptions.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/file/deleteFile.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/file/deleteFile.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/file/index.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/file/index.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/file/list.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/file/list.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/file/upload.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/file/upload.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/image/analyze.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/image/analyze.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/image/generate.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/image/generate.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/image/index.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/image/index.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/node.type.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/node.type.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/router.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/router.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/text/classify.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/text/classify.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/text/index.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/text/index.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/text/message.operation.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/text/message.operation.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/actions/versionDescription.js +1 -0
- package/dist/nodes/vendors/OpenAi/actions/versionDescription.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/helpers/constants.js +1 -0
- package/dist/nodes/vendors/OpenAi/helpers/constants.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/helpers/error-handling.js +1 -0
- package/dist/nodes/vendors/OpenAi/helpers/error-handling.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/helpers/interfaces.js +1 -0
- package/dist/nodes/vendors/OpenAi/helpers/interfaces.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/helpers/utils.js +1 -0
- package/dist/nodes/vendors/OpenAi/helpers/utils.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/methods/index.js +1 -0
- package/dist/nodes/vendors/OpenAi/methods/index.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/methods/listSearch.js +1 -0
- package/dist/nodes/vendors/OpenAi/methods/listSearch.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/methods/loadOptions.js +1 -0
- package/dist/nodes/vendors/OpenAi/methods/loadOptions.js.map +1 -0
- package/dist/nodes/vendors/OpenAi/transport/index.js +1 -0
- package/dist/nodes/vendors/OpenAi/transport/index.js.map +1 -0
- package/dist/types/nodes.json +3 -0
- package/dist/types/types.js +1 -0
- package/dist/types/types.js.map +1 -0
- package/dist/types/zod.types.js +1 -0
- package/dist/types/zod.types.js.map +1 -0
- package/dist/utils/N8nBinaryLoader.js +1 -0
- package/dist/utils/N8nBinaryLoader.js.map +1 -0
- package/dist/utils/N8nJsonLoader.js +1 -0
- package/dist/utils/N8nJsonLoader.js.map +1 -0
- package/dist/utils/N8nTool.js +1 -0
- package/dist/utils/N8nTool.js.map +1 -0
- package/dist/utils/descriptions.js +1 -0
- package/dist/utils/descriptions.js.map +1 -0
- package/dist/utils/helpers.js +1 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/logWrapper.js +1 -0
- package/dist/utils/logWrapper.js.map +1 -0
- package/dist/utils/output_parsers/N8nItemListOutputParser.js +1 -0
- package/dist/utils/output_parsers/N8nItemListOutputParser.js.map +1 -0
- package/dist/utils/output_parsers/N8nOutputFixingParser.js +1 -0
- package/dist/utils/output_parsers/N8nOutputFixingParser.js.map +1 -0
- package/dist/utils/output_parsers/N8nOutputParser.js +1 -0
- package/dist/utils/output_parsers/N8nOutputParser.js.map +1 -0
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js +1 -0
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js.map +1 -0
- package/dist/utils/output_parsers/prompt.js +1 -0
- package/dist/utils/output_parsers/prompt.js.map +1 -0
- package/dist/utils/schemaParsing.js +1 -0
- package/dist/utils/schemaParsing.js.map +1 -0
- package/dist/utils/sharedFields.js +1 -0
- package/dist/utils/sharedFields.js.map +1 -0
- package/dist/utils/tracing.js +1 -0
- package/dist/utils/tracing.js.map +1 -0
- package/package.json +8 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../nodes/agents/Agent/agents/SqlAgent/execute.ts"],"sourcesContent":["import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';\nimport type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { DataSource } from '@n8n/typeorm';\nimport type { SqlCreatePromptArgs } from 'langchain/agents/toolkits/sql';\nimport { SqlToolkit, createSqlAgent } from 'langchain/agents/toolkits/sql';\nimport { SqlDatabase } from 'langchain/sql_db';\nimport {\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n\ttype IDataObject,\n} from 'n8n-workflow';\n\nimport { getPromptInputByType, serializeChatHistory } from '@utils/helpers';\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { getMysqlDataSource } from './other/handlers/mysql';\nimport { getPostgresDataSource } from './other/handlers/postgres';\nimport { getSqliteDataSource } from './other/handlers/sqlite';\nimport { SQL_PREFIX, SQL_SUFFIX } from './other/prompts';\n\nconst parseTablesString = (tablesString: string) =>\n\ttablesString\n\t\t.split(',')\n\t\t.map((table) => table.trim())\n\t\t.filter((table) => table.length > 0);\n\nexport async function sqlAgentAgentExecute(\n\tthis: IExecuteFunctions,\n): Promise<INodeExecutionData[][]> {\n\tthis.logger.debug('Executing SQL Agent');\n\n\tconst model = (await this.getInputConnectionData(\n\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t0,\n\t)) as BaseLanguageModel;\n\tconst items = this.getInputData();\n\n\tconst returnData: INodeExecutionData[] = [];\n\n\tfor (let i = 0; i < items.length; i++) {\n\t\ttry {\n\t\t\tconst item = items[i];\n\t\t\tlet input;\n\t\t\tif (this.getNode().typeVersion <= 1.2) {\n\t\t\t\tinput = this.getNodeParameter('input', i) as string;\n\t\t\t} else {\n\t\t\t\tinput = getPromptInputByType({\n\t\t\t\t\tctx: this,\n\t\t\t\t\ti,\n\t\t\t\t\tinputKey: 'text',\n\t\t\t\t\tpromptTypeKey: 'promptType',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (input === undefined) {\n\t\t\t\tthrow new NodeOperationError(this.getNode(), 'The ‘prompt’ parameter is empty.');\n\t\t\t}\n\n\t\t\tconst options = this.getNodeParameter('options', i, {});\n\t\t\tconst selectedDataSource = this.getNodeParameter('dataSource', i, 'sqlite') as\n\t\t\t\t| 'mysql'\n\t\t\t\t| 'postgres'\n\t\t\t\t| 'sqlite';\n\n\t\t\tconst includedSampleRows = options.includedSampleRows as number;\n\t\t\tconst includedTablesArray = parseTablesString((options.includedTables as string) ?? '');\n\t\t\tconst ignoredTablesArray = parseTablesString((options.ignoredTables as string) ?? '');\n\n\t\t\tlet dataSource: DataSource | null = null;\n\t\t\tif (selectedDataSource === 'sqlite') {\n\t\t\t\tif (!item.binary) {\n\t\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\t\tthis.getNode(),\n\t\t\t\t\t\t'No binary data found, please connect a binary to the input if you want to use SQLite as data source',\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst binaryPropertyName = this.getNodeParameter('binaryPropertyName', i, 'data');\n\t\t\t\tdataSource = await getSqliteDataSource.call(this, item.binary, binaryPropertyName);\n\t\t\t}\n\n\t\t\tif (selectedDataSource === 'postgres') {\n\t\t\t\tdataSource = await getPostgresDataSource.call(this);\n\t\t\t}\n\n\t\t\tif (selectedDataSource === 'mysql') {\n\t\t\t\tdataSource = await getMysqlDataSource.call(this);\n\t\t\t}\n\n\t\t\tif (!dataSource) {\n\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\tthis.getNode(),\n\t\t\t\t\t'No data source found, please configure data source',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst agentOptions: SqlCreatePromptArgs = {\n\t\t\t\ttopK: (options.topK as number) ?? 10,\n\t\t\t\tprefix: (options.prefixPrompt as string) ?? SQL_PREFIX,\n\t\t\t\tsuffix: (options.suffixPrompt as string) ?? SQL_SUFFIX,\n\t\t\t\tinputVariables: ['chatHistory', 'input', 'agent_scratchpad'],\n\t\t\t};\n\n\t\t\tconst dbInstance = await SqlDatabase.fromDataSourceParams({\n\t\t\t\tappDataSource: dataSource,\n\t\t\t\tincludesTables: includedTablesArray.length > 0 ? includedTablesArray : undefined,\n\t\t\t\tignoreTables: ignoredTablesArray.length > 0 ? ignoredTablesArray : undefined,\n\t\t\t\tsampleRowsInTableInfo: includedSampleRows ?? 3,\n\t\t\t});\n\n\t\t\tconst toolkit = new SqlToolkit(dbInstance, model);\n\t\t\tconst agentExecutor = createSqlAgent(model, toolkit, agentOptions);\n\n\t\t\tconst memory = (await this.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t\t| BaseChatMemory\n\t\t\t\t| undefined;\n\n\t\t\tagentExecutor.memory = memory;\n\n\t\t\tlet chatHistory = '';\n\t\t\tif (memory) {\n\t\t\t\tconst messages = await memory.chatHistory.getMessages();\n\t\t\t\tchatHistory = serializeChatHistory(messages);\n\t\t\t}\n\n\t\t\tlet response: IDataObject;\n\t\t\ttry {\n\t\t\t\tresponse = await agentExecutor.withConfig(getTracingConfig(this)).invoke({\n\t\t\t\t\tinput,\n\t\t\t\t\tsignal: this.getExecutionCancelSignal(),\n\t\t\t\t\tchatHistory,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tif ((error.message as IDataObject)?.output) {\n\t\t\t\t\tresponse = error.message as IDataObject;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), error.message as string, { itemIndex: i });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturnData.push({ json: response });\n\t\t} catch (error) {\n\t\t\tif (this.continueOnFail()) {\n\t\t\t\treturnData.push({ json: { error: error.message }, pairedItem: { item: i } });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\treturn [returnData];\n}\n"],"mappings":";;;;;;;;;;;;;;;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,KAAK,yBAAyB;AAAA,UACtC;AAAA,QACD,CAAC;AAAA,MACF,SAAS,OAAO;AACf,YAAK,MAAM,SAAyB,QAAQ;AAC3C,qBAAW,MAAM;AAAA,QAClB,OAAO;AACN,gBAAM,IAAI,uCAAmB,KAAK,QAAQ,GAAG,MAAM,SAAmB,EAAE,WAAW,EAAE,CAAC;AAAA,QACvF;AAAA,MACD;AAEA,iBAAW,KAAK,EAAE,MAAM,SAAS,CAAC;AAAA,IACnC,SAAS,OAAO;AACf,UAAI,KAAK,eAAe,GAAG;AAC1B,mBAAW,KAAK,EAAE,MAAM,EAAE,OAAO,MAAM,QAAQ,GAAG,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;AAC3E;AAAA,MACD;AAEA,YAAM;AAAA,IACP;AAAA,EACD;AAEA,SAAO,CAAC,UAAU;AACnB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/SqlAgent/other/handlers/mysql.ts"],"sourcesContent":["import { DataSource } from '@n8n/typeorm';\nimport { type IExecuteFunctions } from 'n8n-workflow';\n\nexport async function getMysqlDataSource(this: IExecuteFunctions): Promise<DataSource> {\n\tconst credentials = await this.getCredentials('mySql');\n\n\tconst dataSource = new DataSource({\n\t\ttype: 'mysql',\n\t\thost: credentials.host as string,\n\t\tport: credentials.port as number,\n\t\tusername: credentials.user as string,\n\t\tpassword: credentials.password as string,\n\t\tdatabase: credentials.database as string,\n\t\tssl: {\n\t\t\trejectUnauthorized: credentials.ssl as boolean,\n\t\t},\n\t});\n\n\treturn dataSource;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAG3B,eAAsB,qBAAiE;AACtF,QAAM,cAAc,MAAM,KAAK,eAAe,OAAO;AAErD,QAAM,aAAa,IAAI,0BAAW;AAAA,IACjC,MAAM;AAAA,IACN,MAAM,YAAY;AAAA,IAClB,MAAM,YAAY;AAAA,IAClB,UAAU,YAAY;AAAA,IACtB,UAAU,YAAY;AAAA,IACtB,UAAU,YAAY;AAAA,IACtB,KAAK;AAAA,MACJ,oBAAoB,YAAY;AAAA,IACjC;AAAA,EACD,CAAC;AAED,SAAO;AACR;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/SqlAgent/other/handlers/postgres.ts"],"sourcesContent":["import { DataSource } from '@n8n/typeorm';\nimport type { PostgresNodeCredentials } from 'n8n-nodes-base/dist/nodes/Postgres/v2/helpers/interfaces';\nimport { type IExecuteFunctions } from 'n8n-workflow';\nimport type { TlsOptions } from 'tls';\n\nexport async function getPostgresDataSource(this: IExecuteFunctions): Promise<DataSource> {\n\tconst credentials = await this.getCredentials<PostgresNodeCredentials>('postgres');\n\n\tlet ssl: TlsOptions | boolean = !['disable', undefined].includes(credentials.ssl);\n\tif (credentials.allowUnauthorizedCerts && ssl) {\n\t\tssl = { rejectUnauthorized: false };\n\t}\n\n\treturn new DataSource({\n\t\ttype: 'postgres',\n\t\thost: credentials.host,\n\t\tport: credentials.port,\n\t\tusername: credentials.user,\n\t\tpassword: credentials.password,\n\t\tdatabase: credentials.database,\n\t\tssl,\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAK3B,eAAsB,wBAAoE;AACzF,QAAM,cAAc,MAAM,KAAK,eAAwC,UAAU;AAEjF,MAAI,MAA4B,CAAC,CAAC,WAAW,MAAS,EAAE,SAAS,YAAY,GAAG;AAChF,MAAI,YAAY,0BAA0B,KAAK;AAC9C,UAAM,EAAE,oBAAoB,MAAM;AAAA,EACnC;AAEA,SAAO,IAAI,0BAAW;AAAA,IACrB,MAAM;AAAA,IACN,MAAM,YAAY;AAAA,IAClB,MAAM,YAAY;AAAA,IAClB,UAAU,YAAY;AAAA,IACtB,UAAU,YAAY;AAAA,IACtB,UAAU,YAAY;AAAA,IACtB;AAAA,EACD,CAAC;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/SqlAgent/other/handlers/sqlite.ts"],"sourcesContent":["import { DataSource } from '@n8n/typeorm';\nimport * as fs from 'fs';\nimport type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';\nimport { BINARY_ENCODING, NodeOperationError } from 'n8n-workflow';\nimport * as sqlite3 from 'sqlite3';\nimport * as temp from 'temp';\n\nexport async function getSqliteDataSource(\n\tthis: IExecuteFunctions,\n\tbinary: INodeExecutionData['binary'],\n\tbinaryPropertyName = 'data',\n): Promise<DataSource> {\n\tconst binaryData = binary?.[binaryPropertyName];\n\n\tif (!binaryData) {\n\t\tthrow new NodeOperationError(this.getNode(), 'No binary data received.');\n\t}\n\n\tlet fileBase64;\n\tif (binaryData.id) {\n\t\tconst chunkSize = 256 * 1024;\n\t\tconst stream = await this.helpers.getBinaryStream(binaryData.id, chunkSize);\n\t\tconst buffer = await this.helpers.binaryToBuffer(stream);\n\t\tfileBase64 = buffer.toString('base64');\n\t} else {\n\t\tfileBase64 = binaryData.data;\n\t}\n\n\tconst bufferString = Buffer.from(fileBase64, BINARY_ENCODING);\n\n\t// Track and cleanup temp files at exit\n\ttemp.track();\n\n\tconst tempDbPath = temp.path({ suffix: '.sqlite' });\n\tfs.writeFileSync(tempDbPath, bufferString);\n\n\t// Initialize a new SQLite database from the temp file\n\tconst tempDb = new sqlite3.Database(tempDbPath, (error: Error | null) => {\n\t\tif (error) {\n\t\t\tthrow new NodeOperationError(this.getNode(), 'Could not connect to database');\n\t\t}\n\t});\n\ttempDb.close();\n\n\treturn new DataSource({\n\t\ttype: 'sqlite',\n\t\tdatabase: tempDbPath,\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAC3B,SAAoB;AAEpB,0BAAoD;AACpD,cAAyB;AACzB,WAAsB;AAEtB,eAAsB,oBAErB,QACA,qBAAqB,QACC;AACtB,QAAM,aAAa,SAAS,kBAAkB;AAE9C,MAAI,CAAC,YAAY;AAChB,UAAM,IAAI,uCAAmB,KAAK,QAAQ,GAAG,0BAA0B;AAAA,EACxE;AAEA,MAAI;AACJ,MAAI,WAAW,IAAI;AAClB,UAAM,YAAY,MAAM;AACxB,UAAM,SAAS,MAAM,KAAK,QAAQ,gBAAgB,WAAW,IAAI,SAAS;AAC1E,UAAM,SAAS,MAAM,KAAK,QAAQ,eAAe,MAAM;AACvD,iBAAa,OAAO,SAAS,QAAQ;AAAA,EACtC,OAAO;AACN,iBAAa,WAAW;AAAA,EACzB;AAEA,QAAM,eAAe,OAAO,KAAK,YAAY,mCAAe;AAG5D,OAAK,MAAM;AAEX,QAAM,aAAa,KAAK,KAAK,EAAE,QAAQ,UAAU,CAAC;AAClD,KAAG,cAAc,YAAY,YAAY;AAGzC,QAAM,SAAS,IAAI,QAAQ,SAAS,YAAY,CAAC,UAAwB;AACxE,QAAI,OAAO;AACV,YAAM,IAAI,uCAAmB,KAAK,QAAQ,GAAG,+BAA+B;AAAA,IAC7E;AAAA,EACD,CAAC;AACD,SAAO,MAAM;AAEb,SAAO,IAAI,0BAAW;AAAA,IACrB,MAAM;AAAA,IACN,UAAU;AAAA,EACX,CAAC;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../nodes/agents/Agent/agents/SqlAgent/other/prompts.ts"],"sourcesContent":["export const SQL_PREFIX = `You are an agent designed to interact with an SQL database.\nGiven an input question, create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer.\nUnless the user specifies a specific number of examples they wish to obtain, always limit your query to at most {top_k} results using the LIMIT clause.\nYou can order the results by a relevant column to return the most interesting examples in the database.\nNever query for all the columns from a specific table, only ask for a the few relevant columns given the question.\nYou have access to tools for interacting with the database.\nOnly use the below tools. Only use the information returned by the below tools to construct your final answer.\nYou MUST double check your query before executing it. If you get an error while executing a query, rewrite the query and try again.\n\nDO NOT make any DML statements (INSERT, UPDATE, DELETE, DROP etc.) to the database.\n\nIf the question does not seem related to the database, just return \"I don't know\" as the answer.`;\n\nexport const SQL_SUFFIX = `Begin!\nChat History:\n{chatHistory}\n\nQuestion: {input}\nThought: I should look at the tables in the database to see what I can query.\n{agent_scratchpad}`;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAanB,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../nodes/agents/Agent/agents/ToolsAgent/description.ts"],"sourcesContent":["import type { INodeProperties } from 'n8n-workflow';\n\nimport { SYSTEM_MESSAGE } from './prompt';\n\nexport const toolsAgentProperties: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\ttype: 'collection',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tagent: ['toolsAgent'],\n\t\t\t},\n\t\t},\n\t\tdefault: {},\n\t\tplaceholder: 'Add Option',\n\t\toptions: [\n\t\t\t{\n\t\t\t\tdisplayName: 'System Message',\n\t\t\t\tname: 'systemMessage',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: SYSTEM_MESSAGE,\n\t\t\t\tdescription: 'The message that will be sent to the agent before the conversation starts',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 6,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Max Iterations',\n\t\t\t\tname: 'maxIterations',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 10,\n\t\t\t\tdescription: 'The maximum number of iterations the agent will run before stopping',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Return Intermediate Steps',\n\t\t\t\tname: 'returnIntermediateSteps',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t\tdescription: 'Whether or not the output should include intermediate steps the agent took',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Automatically Passthrough Binary Images',\n\t\t\t\tname: 'passthroughBinaryImages',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: true,\n\t\t\t\tdescription:\n\t\t\t\t\t'Whether or not binary images should be automatically passed through to the agent as image type messages',\n\t\t\t},\n\t\t],\n\t},\n];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA+B;AAExB,MAAM,uBAA0C;AAAA,EACtD;AAAA,IACC,aAAa;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AAAA,IACN,gBAAgB;AAAA,MACf,MAAM;AAAA,QACL,OAAO,CAAC,YAAY;AAAA,MACrB;AAAA,IACD;AAAA,IACA,SAAS,CAAC;AAAA,IACV,aAAa;AAAA,IACb,SAAS;AAAA,MACR;AAAA,QACC,aAAa;AAAA,QACb,MAAM;AAAA,QACN,MAAM;AAAA,QACN,SAAS;AAAA,QACT,aAAa;AAAA,QACb,aAAa;AAAA,UACZ,MAAM;AAAA,QACP;AAAA,MACD;AAAA,MACA;AAAA,QACC,aAAa;AAAA,QACb,MAAM;AAAA,QACN,MAAM;AAAA,QACN,SAAS;AAAA,QACT,aAAa;AAAA,MACd;AAAA,MACA;AAAA,QACC,aAAa;AAAA,QACb,MAAM;AAAA,QACN,MAAM;AAAA,QACN,SAAS;AAAA,QACT,aAAa;AAAA,MACd;AAAA,MACA;AAAA,QACC,aAAa;AAAA,QACb,MAAM;AAAA,QACN,MAAM;AAAA,QACN,SAAS;AAAA,QACT,aACC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../nodes/agents/Agent/agents/ToolsAgent/execute.ts"],"sourcesContent":["import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';\nimport type { BaseChatModel } from '@langchain/core/language_models/chat_models';\nimport { HumanMessage } from '@langchain/core/messages';\nimport type { BaseMessage } from '@langchain/core/messages';\nimport type { BaseMessagePromptTemplateLike } from '@langchain/core/prompts';\nimport { ChatPromptTemplate } from '@langchain/core/prompts';\nimport { RunnableSequence } from '@langchain/core/runnables';\nimport type { Tool } from '@langchain/core/tools';\nimport { DynamicStructuredTool } from '@langchain/core/tools';\nimport type { AgentAction, AgentFinish } from 'langchain/agents';\nimport { AgentExecutor, createToolCallingAgent } from 'langchain/agents';\nimport type { ToolsAgentAction } from 'langchain/dist/agents/tool_calling/output_parser';\nimport { omit } from 'lodash';\nimport { BINARY_ENCODING, jsonParse, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';\nimport type { ZodObject } from 'zod';\nimport { z } from 'zod';\n\nimport { isChatInstance, getPromptInputByType, getConnectedTools } from '@utils/helpers';\nimport {\n\tgetOptionalOutputParser,\n\ttype N8nOutputParser,\n} from '@utils/output_parsers/N8nOutputParser';\n\nimport { SYSTEM_MESSAGE } from './prompt';\n\n/* -----------------------------------------------------------\n Output Parser Helper\n----------------------------------------------------------- */\n/**\n * Retrieve the output parser schema.\n * If the parser does not return a valid schema, default to a schema with a single text field.\n */\nexport function getOutputParserSchema(\n\toutputParser: N8nOutputParser,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n): ZodObject<any, any, any, any> {\n\tconst schema =\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t(outputParser.getSchema() as ZodObject<any, any, any, any>) ?? z.object({ text: z.string() });\n\treturn schema;\n}\n\n/* -----------------------------------------------------------\n Binary Data Helpers\n----------------------------------------------------------- */\n/**\n * Extracts binary image messages from the input data.\n * When operating in filesystem mode, the binary stream is first converted to a buffer.\n *\n * @param ctx - The execution context\n * @param itemIndex - The current item index\n * @returns A HumanMessage containing the binary image messages.\n */\nexport async function extractBinaryMessages(\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n): Promise<HumanMessage> {\n\tconst binaryData = ctx.getInputData()?.[itemIndex]?.binary ?? {};\n\tconst binaryMessages = await Promise.all(\n\t\tObject.values(binaryData)\n\t\t\t.filter((data) => data.mimeType.startsWith('image/'))\n\t\t\t.map(async (data) => {\n\t\t\t\tlet binaryUrlString: string;\n\n\t\t\t\t// In filesystem mode we need to get binary stream by id before converting it to buffer\n\t\t\t\tif (data.id) {\n\t\t\t\t\tconst binaryBuffer = await ctx.helpers.binaryToBuffer(\n\t\t\t\t\t\tawait ctx.helpers.getBinaryStream(data.id),\n\t\t\t\t\t);\n\t\t\t\t\tbinaryUrlString = `data:${data.mimeType};base64,${Buffer.from(binaryBuffer).toString(\n\t\t\t\t\t\tBINARY_ENCODING,\n\t\t\t\t\t)}`;\n\t\t\t\t} else {\n\t\t\t\t\tbinaryUrlString = data.data.includes('base64')\n\t\t\t\t\t\t? data.data\n\t\t\t\t\t\t: `data:${data.mimeType};base64,${data.data}`;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'image_url',\n\t\t\t\t\timage_url: {\n\t\t\t\t\t\turl: binaryUrlString,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}),\n\t);\n\treturn new HumanMessage({\n\t\tcontent: [...binaryMessages],\n\t});\n}\n\n/* -----------------------------------------------------------\n Agent Output Format Helpers\n----------------------------------------------------------- */\n/**\n * Fixes empty content messages in agent steps.\n *\n * This function is necessary when using RunnableSequence.from in LangChain.\n * If a tool doesn't have any arguments, LangChain returns input: '' (empty string).\n * This can throw an error for some providers (like Anthropic) which expect the input to always be an object.\n * This function replaces empty string inputs with empty objects to prevent such errors.\n *\n * @param steps - The agent steps to fix\n * @returns The fixed agent steps\n */\nexport function fixEmptyContentMessage(\n\tsteps: AgentFinish | ToolsAgentAction[],\n): AgentFinish | ToolsAgentAction[] {\n\tif (!Array.isArray(steps)) return steps;\n\n\tsteps.forEach((step) => {\n\t\tif ('messageLog' in step && step.messageLog !== undefined) {\n\t\t\tif (Array.isArray(step.messageLog)) {\n\t\t\t\tstep.messageLog.forEach((message: BaseMessage) => {\n\t\t\t\t\tif ('content' in message && Array.isArray(message.content)) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t(message.content as Array<{ input?: string | object }>).forEach((content) => {\n\t\t\t\t\t\t\tif (content.input === '') {\n\t\t\t\t\t\t\t\tcontent.input = {};\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\treturn steps;\n}\n\n/**\n * Ensures consistent handling of outputs regardless of the model used,\n * providing a unified output format for further processing.\n *\n * This method is necessary to handle different output formats from various language models.\n * Specifically, it checks if the agent step is the final step (contains returnValues) and determines\n * if the output is a simple string (e.g., from OpenAI models) or an array of outputs (e.g., from Anthropic models).\n *\n * Examples:\n * 1. Anthropic model output:\n * ```json\n * {\n * \"output\": [\n * {\n * \"index\": 0,\n * \"type\": \"text\",\n * \"text\": \"The result of the calculation is approximately 1001.8166...\"\n * }\n * ]\n * }\n *```\n * 2. OpenAI model output:\n * ```json\n * {\n * \"output\": \"The result of the calculation is approximately 1001.82...\"\n * }\n * ```\n *\n * @param steps - The agent finish or agent action steps.\n * @returns The modified agent finish steps or the original steps.\n */\nexport function handleAgentFinishOutput(\n\tsteps: AgentFinish | AgentAction[],\n): AgentFinish | AgentAction[] {\n\ttype AgentMultiOutputFinish = AgentFinish & {\n\t\treturnValues: { output: Array<{ text: string; type: string; index: number }> };\n\t};\n\tconst agentFinishSteps = steps as AgentMultiOutputFinish | AgentFinish;\n\n\tif (agentFinishSteps.returnValues) {\n\t\tconst isMultiOutput = Array.isArray(agentFinishSteps.returnValues?.output);\n\t\tif (isMultiOutput) {\n\t\t\t// If all items in the multi-output array are of type 'text', merge them into a single string\n\t\t\tconst multiOutputSteps = agentFinishSteps.returnValues.output as Array<{\n\t\t\t\tindex: number;\n\t\t\t\ttype: string;\n\t\t\t\ttext: string;\n\t\t\t}>;\n\t\t\tconst isTextOnly = multiOutputSteps.every((output) => 'text' in output);\n\t\t\tif (isTextOnly) {\n\t\t\t\tagentFinishSteps.returnValues.output = multiOutputSteps\n\t\t\t\t\t.map((output) => output.text)\n\t\t\t\t\t.join('\\n')\n\t\t\t\t\t.trim();\n\t\t\t}\n\t\t\treturn agentFinishSteps;\n\t\t}\n\t}\n\n\treturn agentFinishSteps;\n}\n\n/**\n * Wraps the parsed output so that it can be stored in memory.\n * If memory is connected, the output is stringified.\n *\n * @param output - The parsed output object\n * @param memory - The connected memory (if any)\n * @returns The formatted output object\n */\nexport function handleParsedStepOutput(\n\toutput: Record<string, unknown>,\n\tmemory?: BaseChatMemory,\n): { returnValues: Record<string, unknown>; log: string } {\n\treturn {\n\t\treturnValues: memory ? { output: JSON.stringify(output) } : output,\n\t\tlog: 'Final response formatted',\n\t};\n}\n\n/**\n * Parses agent steps using the provided output parser.\n * If the agent used the 'format_final_json_response' tool, the output is parsed accordingly.\n *\n * @param steps - The agent finish or action steps\n * @param outputParser - The output parser (if defined)\n * @param memory - The connected memory (if any)\n * @returns The parsed steps with the final output\n */\nexport const getAgentStepsParser =\n\t(outputParser?: N8nOutputParser, memory?: BaseChatMemory) =>\n\tasync (steps: AgentFinish | AgentAction[]): Promise<AgentFinish | AgentAction[]> => {\n\t\t// Check if the steps contain the 'format_final_json_response' tool invocation.\n\t\tif (Array.isArray(steps)) {\n\t\t\tconst responseParserTool = steps.find((step) => step.tool === 'format_final_json_response');\n\t\t\tif (responseParserTool && outputParser) {\n\t\t\t\tconst toolInput = responseParserTool.toolInput;\n\t\t\t\t// Ensure the tool input is a string\n\t\t\t\tconst parserInput = toolInput instanceof Object ? JSON.stringify(toolInput) : toolInput;\n\t\t\t\tconst returnValues = (await outputParser.parse(parserInput)) as Record<string, unknown>;\n\t\t\t\treturn handleParsedStepOutput(returnValues, memory);\n\t\t\t}\n\t\t}\n\n\t\t// Otherwise, if the steps contain a returnValues field, try to parse them manually.\n\t\tif (outputParser && typeof steps === 'object' && (steps as AgentFinish).returnValues) {\n\t\t\tconst finalResponse = (steps as AgentFinish).returnValues;\n\t\t\tlet parserInput: string;\n\n\t\t\tif (finalResponse instanceof Object) {\n\t\t\t\tif ('output' in finalResponse) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// If the output is an object, we will try to parse it as JSON\n\t\t\t\t\t\t// this is because parser expects stringified JSON object like { \"output\": { .... } }\n\t\t\t\t\t\t// so we try to parse the output before wrapping it and then stringify it\n\t\t\t\t\t\tparserInput = JSON.stringify({ output: jsonParse(finalResponse.output) });\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Fallback to the raw output if parsing fails.\n\t\t\t\t\t\tparserInput = finalResponse.output;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// If the output is not an object, we will stringify it as it is\n\t\t\t\t\tparserInput = JSON.stringify(finalResponse);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tparserInput = finalResponse;\n\t\t\t}\n\n\t\t\tconst returnValues = (await outputParser.parse(parserInput)) as Record<string, unknown>;\n\t\t\treturn handleParsedStepOutput(returnValues, memory);\n\t\t}\n\n\t\treturn handleAgentFinishOutput(steps);\n\t};\n\n/* -----------------------------------------------------------\n Agent Setup Helpers\n----------------------------------------------------------- */\n/**\n * Retrieves the language model from the input connection.\n * Throws an error if the model is not a valid chat instance or does not support tools.\n *\n * @param ctx - The execution context\n * @returns The validated chat model\n */\nexport async function getChatModel(ctx: IExecuteFunctions): Promise<BaseChatModel> {\n\tconst model = await ctx.getInputConnectionData(NodeConnectionTypes.AiLanguageModel, 0);\n\tif (!isChatInstance(model) || !model.bindTools) {\n\t\tthrow new NodeOperationError(\n\t\t\tctx.getNode(),\n\t\t\t'Tools Agent requires Chat Model which supports Tools calling',\n\t\t);\n\t}\n\treturn model;\n}\n\n/**\n * Retrieves the memory instance from the input connection if it is connected\n *\n * @param ctx - The execution context\n * @returns The connected memory (if any)\n */\nexport async function getOptionalMemory(\n\tctx: IExecuteFunctions,\n): Promise<BaseChatMemory | undefined> {\n\treturn (await ctx.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t| BaseChatMemory\n\t\t| undefined;\n}\n\n/**\n * Retrieves the connected tools and (if an output parser is defined)\n * appends a structured output parser tool.\n *\n * @param ctx - The execution context\n * @param outputParser - The optional output parser\n * @returns The array of connected tools\n */\nexport async function getTools(\n\tctx: IExecuteFunctions,\n\toutputParser?: N8nOutputParser,\n): Promise<Array<DynamicStructuredTool | Tool>> {\n\tconst tools = (await getConnectedTools(ctx, true, false)) as Array<DynamicStructuredTool | Tool>;\n\n\t// If an output parser is available, create a dynamic tool to validate the final output.\n\tif (outputParser) {\n\t\tconst schema = getOutputParserSchema(outputParser);\n\t\tconst structuredOutputParserTool = new DynamicStructuredTool({\n\t\t\tschema,\n\t\t\tname: 'format_final_json_response',\n\t\t\tdescription:\n\t\t\t\t'Use this tool to format your final response to the user in a structured JSON format. This tool validates your output against a schema to ensure it meets the required format. ONLY use this tool when you have completed all necessary reasoning and are ready to provide your final answer. Do not use this tool for intermediate steps or for asking questions. The output from this tool will be directly returned to the user.',\n\t\t\t// We do not use a function here because we intercept the output with the parser.\n\t\t\tfunc: async () => '',\n\t\t});\n\t\ttools.push(structuredOutputParserTool);\n\t}\n\treturn tools;\n}\n\n/**\n * Prepares the prompt messages for the agent.\n *\n * @param ctx - The execution context\n * @param itemIndex - The current item index\n * @param options - Options containing systemMessage and other parameters\n * @returns The array of prompt messages\n */\nexport async function prepareMessages(\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n\toptions: {\n\t\tsystemMessage?: string;\n\t\tpassthroughBinaryImages?: boolean;\n\t\toutputParser?: N8nOutputParser;\n\t},\n): Promise<BaseMessagePromptTemplateLike[]> {\n\tconst messages: BaseMessagePromptTemplateLike[] = [\n\t\t['system', `{system_message}${options.outputParser ? '\\n\\n{formatting_instructions}' : ''}`],\n\t\t['placeholder', '{chat_history}'],\n\t\t['human', '{input}'],\n\t];\n\n\t// If there is binary data and the node option permits it, add a binary message\n\tconst hasBinaryData = ctx.getInputData()?.[itemIndex]?.binary !== undefined;\n\tif (hasBinaryData && options.passthroughBinaryImages) {\n\t\tconst binaryMessage = await extractBinaryMessages(ctx, itemIndex);\n\t\tmessages.push(binaryMessage);\n\t}\n\n\t// We add the agent scratchpad last, so that the agent will not run in loops\n\t// by adding binary messages between each interaction\n\tmessages.push(['placeholder', '{agent_scratchpad}']);\n\treturn messages;\n}\n\n/**\n * Creates the chat prompt from messages.\n *\n * @param messages - The messages array\n * @returns The ChatPromptTemplate instance\n */\nexport function preparePrompt(messages: BaseMessagePromptTemplateLike[]): ChatPromptTemplate {\n\treturn ChatPromptTemplate.fromMessages(messages);\n}\n\n/* -----------------------------------------------------------\n Main Executor Function\n----------------------------------------------------------- */\n/**\n * The main executor method for the Tools Agent.\n *\n * This function retrieves necessary components (model, memory, tools), prepares the prompt,\n * creates the agent, and processes each input item. The error handling for each item is also\n * managed here based on the node's continueOnFail setting.\n *\n * @returns The array of execution data for all processed items\n */\nexport async function toolsAgentExecute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\tthis.logger.debug('Executing Tools Agent');\n\n\tconst returnData: INodeExecutionData[] = [];\n\tconst items = this.getInputData();\n\tconst outputParser = await getOptionalOutputParser(this);\n\tconst tools = await getTools(this, outputParser);\n\n\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\ttry {\n\t\t\tconst model = await getChatModel(this);\n\t\t\tconst memory = await getOptionalMemory(this);\n\n\t\t\tconst input = getPromptInputByType({\n\t\t\t\tctx: this,\n\t\t\t\ti: itemIndex,\n\t\t\t\tinputKey: 'text',\n\t\t\t\tpromptTypeKey: 'promptType',\n\t\t\t});\n\t\t\tif (input === undefined) {\n\t\t\t\tthrow new NodeOperationError(this.getNode(), 'The “text” parameter is empty.');\n\t\t\t}\n\n\t\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\t\tsystemMessage?: string;\n\t\t\t\tmaxIterations?: number;\n\t\t\t\treturnIntermediateSteps?: boolean;\n\t\t\t\tpassthroughBinaryImages?: boolean;\n\t\t\t};\n\n\t\t\t// Prepare the prompt messages and prompt template.\n\t\t\tconst messages = await prepareMessages(this, itemIndex, {\n\t\t\t\tsystemMessage: options.systemMessage,\n\t\t\t\tpassthroughBinaryImages: options.passthroughBinaryImages ?? true,\n\t\t\t\toutputParser,\n\t\t\t});\n\t\t\tconst prompt = preparePrompt(messages);\n\n\t\t\t// Create the base agent that calls tools.\n\t\t\tconst agent = createToolCallingAgent({\n\t\t\t\tllm: model,\n\t\t\t\ttools,\n\t\t\t\tprompt,\n\t\t\t\tstreamRunnable: false,\n\t\t\t});\n\t\t\tagent.streamRunnable = false;\n\t\t\t// Wrap the agent with parsers and fixes.\n\t\t\tconst runnableAgent = RunnableSequence.from([\n\t\t\t\tagent,\n\t\t\t\tgetAgentStepsParser(outputParser, memory),\n\t\t\t\tfixEmptyContentMessage,\n\t\t\t]);\n\t\t\tconst executor = AgentExecutor.fromAgentAndTools({\n\t\t\t\tagent: runnableAgent,\n\t\t\t\tmemory,\n\t\t\t\ttools,\n\t\t\t\treturnIntermediateSteps: options.returnIntermediateSteps === true,\n\t\t\t\tmaxIterations: options.maxIterations ?? 10,\n\t\t\t});\n\n\t\t\t// Invoke the executor with the given input and system message.\n\t\t\tconst response = await executor.invoke(\n\t\t\t\t{\n\t\t\t\t\tinput,\n\t\t\t\t\tsystem_message: options.systemMessage ?? SYSTEM_MESSAGE,\n\t\t\t\t\tformatting_instructions:\n\t\t\t\t\t\t'IMPORTANT: For your response to user, you MUST use the `format_final_json_response` tool with your complete answer formatted according to the required schema. Do not attempt to format the JSON manually - always use this tool. Your response will be rejected if it is not properly formatted through this tool. Only use this tool once you are ready to provide your final answer.',\n\t\t\t\t},\n\t\t\t\t{ signal: this.getExecutionCancelSignal() },\n\t\t\t);\n\n\t\t\t// If memory and outputParser are connected, parse the output.\n\t\t\tif (memory && outputParser) {\n\t\t\t\tconst parsedOutput = jsonParse<{ output: Record<string, unknown> }>(\n\t\t\t\t\tresponse.output as string,\n\t\t\t\t);\n\t\t\t\tresponse.output = parsedOutput?.output ?? parsedOutput;\n\t\t\t}\n\n\t\t\t// Omit internal keys before returning the result.\n\t\t\tconst itemResult = {\n\t\t\t\tjson: omit(\n\t\t\t\t\tresponse,\n\t\t\t\t\t'system_message',\n\t\t\t\t\t'formatting_instructions',\n\t\t\t\t\t'input',\n\t\t\t\t\t'chat_history',\n\t\t\t\t\t'agent_scratchpad',\n\t\t\t\t),\n\t\t\t};\n\n\t\t\treturnData.push(itemResult);\n\t\t} catch (error) {\n\t\t\tif (this.continueOnFail()) {\n\t\t\t\treturnData.push({\n\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\treturn [returnData];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAA6B;AAG7B,qBAAmC;AACnC,uBAAiC;AAEjC,mBAAsC;AAEtC,oBAAsD;AAEtD,oBAAqB;AACrB,0BAAoF;AAGpF,iBAAkB;AAElB,qBAAwE;AACxE,6BAGO;AAEP,oBAA+B;AASxB,SAAS,sBACf,cAEgC;AAChC,QAAM;AAAA;AAAA,IAEJ,aAAa,UAAU,KAAuC,aAAE,OAAO,EAAE,MAAM,aAAE,OAAO,EAAE,CAAC;AAAA;AAC7F,SAAO;AACR;AAaA,eAAsB,sBACrB,KACA,WACwB;AACxB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AAQ,4BAA4B;AAAA,QAC7D,eAAe,QAAQ,iBAAiB;AAAA,MACzC,CAAC;AAGD,YAAM,WAAW,MAAM,SAAS;AAAA,QAC/B;AAAA,UACC;AAAA,UACA,gBAAgB,QAAQ,iBAAiB;AAAA,UACzC,yBACC;AAAA,QACF;AAAA,QACA,EAAE,QAAQ,KAAK,yBAAyB,EAAE;AAAA,MAC3C;AAGA,UAAI,UAAU,cAAc;AAC3B,cAAM,mBAAe;AAAA,UACpB,SAAS;AAAA,QACV;AACA,iBAAS,SAAS,cAAc,UAAU;AAAA,MAC3C;AAGA,YAAM,aAAa;AAAA,QAClB,UAAM;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAEA,iBAAW,KAAK,UAAU;AAAA,IAC3B,SAAS,OAAO;AACf,UAAI,KAAK,eAAe,GAAG;AAC1B,mBAAW,KAAK;AAAA,UACf,MAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,UAC7B,YAAY,EAAE,MAAM,UAAU;AAAA,QAC/B,CAAC;AACD;AAAA,MACD;AACA,YAAM;AAAA,IACP;AAAA,EACD;AAEA,SAAO,CAAC,UAAU;AACnB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../nodes/agents/Agent/agents/ToolsAgent/prompt.ts"],"sourcesContent":["export const SYSTEM_MESSAGE = 'You are a helpful assistant';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,iBAAiB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/agents/Agent/agents/utils.ts"],"sourcesContent":["import type { BaseOutputParser } from '@langchain/core/output_parsers';\nimport type { DynamicStructuredTool, Tool } from 'langchain/tools';\nimport { NodeOperationError, type IExecuteFunctions, type INode } from 'n8n-workflow';\nimport type { z } from 'zod';\n\ntype ZodObjectAny = z.ZodObject<any, any, any, any>;\n\nexport async function extractParsedOutput(\n\tctx: IExecuteFunctions,\n\toutputParser: BaseOutputParser<unknown>,\n\toutput: string,\n): Promise<Record<string, unknown> | undefined> {\n\tconst parsedOutput = (await outputParser.parse(output)) as {\n\t\toutput: Record<string, unknown>;\n\t};\n\n\tif (ctx.getNode().typeVersion <= 1.6) {\n\t\treturn parsedOutput;\n\t}\n\t// For 1.7 and above, we try to extract the output from the parsed output\n\t// with fallback to the original output if it's not present\n\treturn parsedOutput?.output ?? parsedOutput;\n}\n\nexport async function checkForStructuredTools(\n\ttools: Array<Tool | DynamicStructuredTool<ZodObjectAny>>,\n\tnode: INode,\n\tcurrentAgentType: string,\n) {\n\tconst dynamicStructuredTools = tools.filter(\n\t\t(tool) => tool.constructor.name === 'DynamicStructuredTool',\n\t);\n\tif (dynamicStructuredTools.length > 0) {\n\t\tconst getToolName = (tool: Tool | DynamicStructuredTool) => `\"${tool.name}\"`;\n\t\tthrow new NodeOperationError(\n\t\t\tnode,\n\t\t\t`The selected tools are not supported by \"${currentAgentType}\", please use \"Tools Agent\" instead`,\n\t\t\t{\n\t\t\t\titemIndex: 0,\n\t\t\t\tdescription: `Incompatible connected tools: ${dynamicStructuredTools.map(getToolName).join(', ')}`,\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAuE;AAKvE,eAAsB,oBACrB,KACA,cACA,QAC+C;AAC/C,QAAM,eAAgB,MAAM,aAAa,MAAM,MAAM;AAIrD,MAAI,IAAI,QAAQ,EAAE,eAAe,KAAK;AACrC,WAAO;AAAA,EACR;AAGA,SAAO,cAAc,UAAU;AAChC;AAEA,eAAsB,wBACrB,OACA,MACA,kBACC;AACD,QAAM,yBAAyB,MAAM;AAAA,IACpC,CAAC,SAAS,KAAK,YAAY,SAAS;AAAA,EACrC;AACA,MAAI,uBAAuB,SAAS,GAAG;AACtC,UAAM,cAAc,CAAC,SAAuC,IAAI,KAAK,IAAI;AACzE,UAAM,IAAI;AAAA,MACT;AAAA,MACA,4CAA4C,gBAAgB;AAAA,MAC5D;AAAA,QACC,WAAW;AAAA,QACX,aAAa,iCAAiC,uBAAuB,IAAI,WAAW,EAAE,KAAK,IAAI,CAAC;AAAA,MACjG;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +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\t\t\t\t\t\t\t\t\t\t\t// eslint-disable-next-line n8n-local-rules/no-interpolation-in-regular-string\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,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,QAAQ;AAAA,QACP,EAAE,MAAM,wCAAoB,KAAK;AAAA,QACjC,EAAE,MAAM,wCAAoB,QAAQ,aAAa,QAAQ;AAAA,MAC1D;AAAA,MACA,SAAS,CAAC,wCAAoB,IAAI;AAAA,MAClC,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,iBAAiB;AAAA,QAChB,wBAAwB;AA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aAAa,QAAQ,SAAS,KAAK,CAAC;AAE1E,gBAAM,OAAO,KAAK,WAAW,OAAO,aAAa;AAAA,YAChD,OAAO;AAAA,UACR,CAAC;AAAA,QACF,OAAO;AACN,gBAAM,OAAO,KAAK,iBAAiB,QAAQ,WAAW,EAAE;AACxD,gBAAM,eAAe,KAAK,iBAAiB,gBAAgB,WAAW,EAAE;AACxE,gBAAM,QAAQ,KAAK,iBAAiB,SAAS,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/agents/OpenAiAssistant/utils.ts"],"sourcesContent":["import type { StructuredTool } from '@langchain/core/tools';\nimport type { OpenAIClient } from '@langchain/openai';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\n// Copied from langchain(`langchain/src/tools/convert_to_openai.ts`)\n// since these functions are not exported\n\n/**\n * Formats a `StructuredTool` instance into a format that is compatible\n * with OpenAI's ChatCompletionFunctions. It uses the `zodToJsonSchema`\n * function to convert the schema of the `StructuredTool` into a JSON\n * schema, which is then used as the parameters for the OpenAI function.\n */\nexport function formatToOpenAIFunction(\n\ttool: StructuredTool,\n): OpenAIClient.Chat.ChatCompletionCreateParams.Function {\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tparameters: zodToJsonSchema(tool.schema),\n\t};\n}\n\nexport function formatToOpenAITool(tool: StructuredTool): OpenAIClient.Chat.ChatCompletionTool {\n\tconst schema = zodToJsonSchema(tool.schema);\n\treturn {\n\t\ttype: 'function',\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: schema,\n\t\t},\n\t};\n}\n\nexport function formatToOpenAIAssistantTool(tool: StructuredTool): OpenAIClient.Beta.AssistantTool {\n\treturn {\n\t\ttype: 'function',\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: zodToJsonSchema(tool.schema),\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,gCAAgC;AAWzB,SAAS,uBACf,MACwD;AACxD,SAAO;AAAA,IACN,MAAM,KAAK;AAAA,IACX,aAAa,KAAK;AAAA,IAClB,gBAAY,2CAAgB,KAAK,MAAM;AAAA,EACxC;AACD;AAEO,SAAS,mBAAmB,MAA4D;AAC9F,QAAM,aAAS,2CAAgB,KAAK,MAAM;AAC1C,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,MACT,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,YAAY;AAAA,IACb;AAAA,EACD;AACD;AAEO,SAAS,4BAA4B,MAAuD;AAClG,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,MACT,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,gBAAY,2CAAgB,KAAK,MAAM;AAAA,IACxC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainLLM/ChainLlm.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\nimport { NodeApiError, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\n\nimport { getPromptInputByType } from '@utils/helpers';\nimport { getOptionalOutputParser } from '@utils/output_parsers/N8nOutputParser';\n\n// Import from centralized module\nimport {\n\texecuteChain,\n\tformatResponse,\n\tgetInputs,\n\tnodeProperties,\n\ttype MessageTemplate,\n} from './methods';\nimport {\n\tgetCustomErrorMessage as getCustomOpenAiErrorMessage,\n\tisOpenAiError,\n} from '../../vendors/OpenAi/helpers/error-handling';\n\n/**\n * Basic LLM Chain Node Implementation\n * Allows connecting to language models with optional structured output parsing\n */\nexport class ChainLlm implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Basic LLM Chain',\n\t\tname: 'chainLlm',\n\t\ticon: 'fa:link',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6],\n\t\tdescription: 'A simple chain to prompt a large language model',\n\t\tdefaults: {\n\t\t\tname: 'Basic LLM Chain',\n\t\t\tcolor: '#909298',\n\t\t},\n\t\tcodex: {\n\t\t\talias: ['LangChain'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainllm/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: `={{ ((parameter) => { ${getInputs.toString()}; return getInputs(parameter) })($parameter) }}`,\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [],\n\t\tproperties: nodeProperties,\n\t};\n\n\t/**\n\t * Main execution method for the node\n\t */\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Basic LLM Chain');\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\t// Process each input item\n\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\ttry {\n\t\t\t\t// Get the language model\n\t\t\t\tconst llm = (await this.getInputConnectionData(\n\t\t\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t\t\t0,\n\t\t\t\t)) as BaseLanguageModel;\n\n\t\t\t\t// Get output parser if configured\n\t\t\t\tconst outputParser = await getOptionalOutputParser(this);\n\n\t\t\t\t// Get user prompt based on node version\n\t\t\t\tlet prompt: string;\n\n\t\t\t\tif (this.getNode().typeVersion <= 1.3) {\n\t\t\t\t\tprompt = this.getNodeParameter('prompt', itemIndex) as string;\n\t\t\t\t} else {\n\t\t\t\t\tprompt = getPromptInputByType({\n\t\t\t\t\t\tctx: this,\n\t\t\t\t\t\ti: itemIndex,\n\t\t\t\t\t\tinputKey: 'text',\n\t\t\t\t\t\tpromptTypeKey: 'promptType',\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Validate prompt\n\t\t\t\tif (prompt === undefined) {\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), \"The 'prompt' parameter is empty.\");\n\t\t\t\t}\n\n\t\t\t\t// Get chat messages if configured\n\t\t\t\tconst messages = this.getNodeParameter(\n\t\t\t\t\t'messages.messageValues',\n\t\t\t\t\titemIndex,\n\t\t\t\t\t[],\n\t\t\t\t) as MessageTemplate[];\n\n\t\t\t\t// Execute the chain\n\t\t\t\tconst responses = await executeChain({\n\t\t\t\t\tcontext: this,\n\t\t\t\t\titemIndex,\n\t\t\t\t\tquery: prompt,\n\t\t\t\t\tllm,\n\t\t\t\t\toutputParser,\n\t\t\t\t\tmessages,\n\t\t\t\t});\n\n\t\t\t\t// If the node version is 1.6(and LLM is using `response_format: json_object`) or higher or an output parser is configured,\n\t\t\t\t// we unwrap the response and return the object directly as JSON\n\t\t\t\tconst shouldUnwrapObjects = this.getNode().typeVersion >= 1.6 || !!outputParser;\n\t\t\t\t// Process each response and add to return data\n\t\t\t\tresponses.forEach((response) => {\n\t\t\t\t\treturnData.push({\n\t\t\t\t\t\tjson: formatResponse(response, shouldUnwrapObjects),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\t// Handle OpenAI specific rate limit errors\n\t\t\t\tif (error instanceof NodeApiError && isOpenAiError(error.cause)) {\n\t\t\t\t\tconst openAiErrorCode: string | undefined = (error.cause as any).error?.code;\n\t\t\t\t\tif (openAiErrorCode) {\n\t\t\t\t\t\tconst customMessage = getCustomOpenAiErrorMessage(openAiErrorCode);\n\t\t\t\t\t\tif (customMessage) {\n\t\t\t\t\t\t\terror.message = customMessage;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Continue on failure if configured\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;AAOA,0BAAsE;AAEtE,qBAAqC;AACrC,6BAAwC;AAGxC,qBAMO;AACP,4BAGO;AAMA,MAAM,SAA8B;AAAA,EAApC;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,M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AK;AAAA,UACrB;AAAA,UACA;AAAA,UACA,CAAC;AAAA,QACF;AAGA,cAAM,YAAY,UAAM,6BAAa;AAAA,UACpC,SAAS;AAAA,UACT;AAAA,UACA,OAAO;AAAA,UACP;AAAA,UACA;AAAA,UACA;AAAA,QACD,CAAC;AAID,cAAM,sBAAsB,KAAK,QAAQ,EAAE,eAAe,OAAO,CAAC,CAAC;AAEnE,kBAAU,QAAQ,CAAC,aAAa;AAC/B,qBAAW,KAAK;AAAA,YACf,UAAM,+BAAe,UAAU,mBAAmB;AAAA,UACnD,CAAC;AAAA,QACF,CAAC;AAAA,MACF,SAAS,OAAO;AAEf,YAAI,iBAAiB,wCAAgB,qCAAc,MAAM,KAAK,GAAG;AAChE,gBAAM,kBAAuC,MAAM,MAAc,OAAO;AACxE,cAAI,iBAAiB;AACpB,kBAAM,oBAAgB,sBAAAA,uBAA4B,eAAe;AACjE,gBAAI,eAAe;AAClB,oBAAM,UAAU;AAAA,YACjB;AAAA,UACD;AAAA,QACD;AAGA,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":["getCustomOpenAiErrorMessage"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainLLM/methods/chainExecutor.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { BaseLLMOutputParser } from '@langchain/core/output_parsers';\nimport { JsonOutputParser, StringOutputParser } from '@langchain/core/output_parsers';\nimport type { ChatPromptTemplate, PromptTemplate } from '@langchain/core/prompts';\nimport type { IExecuteFunctions } from 'n8n-workflow';\n\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { createPromptTemplate } from './promptUtils';\nimport type { ChainExecutionParams } from './types';\n\nexport class NaiveJsonOutputParser<\n\tT extends Record<string, any> = Record<string, any>,\n> extends JsonOutputParser<T> {\n\tasync parse(text: string): Promise<T> {\n\t\t// First try direct JSON parsing\n\t\ttry {\n\t\t\tconst directParsed = JSON.parse(text);\n\t\t\treturn directParsed as T;\n\t\t} catch (e) {\n\t\t\t// If fails, fall back to JsonOutputParser parser\n\t\t\treturn await super.parse(text);\n\t\t}\n\t}\n}\n\n/**\n * Type guard to check if the LLM has a modelKwargs property(OpenAI)\n */\nexport function isModelWithResponseFormat(\n\tllm: BaseLanguageModel,\n): llm is BaseLanguageModel & { modelKwargs: { response_format: { type: string } } } {\n\treturn (\n\t\t'modelKwargs' in llm &&\n\t\t!!llm.modelKwargs &&\n\t\ttypeof llm.modelKwargs === 'object' &&\n\t\t'response_format' in llm.modelKwargs\n\t);\n}\n\n/**\n * Type guard to check if the LLM has a format property(Ollama)\n */\nexport function isModelWithFormat(\n\tllm: BaseLanguageModel,\n): llm is BaseLanguageModel & { format: string } {\n\treturn 'format' in llm && typeof llm.format !== 'undefined';\n}\n\n/**\n * Determines if an LLM is configured to output JSON and returns the appropriate output parser\n */\nexport function getOutputParserForLLM(\n\tllm: BaseLanguageModel,\n): BaseLLMOutputParser<string | Record<string, unknown>> {\n\tif (isModelWithResponseFormat(llm) && llm.modelKwargs?.response_format?.type === 'json_object') {\n\t\treturn new NaiveJsonOutputParser();\n\t}\n\n\tif (isModelWithFormat(llm) && llm.format === 'json') {\n\t\treturn new NaiveJsonOutputParser();\n\t}\n\n\treturn new StringOutputParser();\n}\n\n/**\n * Creates a simple chain for LLMs without output parsers\n */\nasync function executeSimpleChain({\n\tcontext,\n\tllm,\n\tquery,\n\tprompt,\n}: {\n\tcontext: IExecuteFunctions;\n\tllm: BaseLanguageModel;\n\tquery: string;\n\tprompt: ChatPromptTemplate | PromptTemplate;\n}) {\n\tconst outputParser = getOutputParserForLLM(llm);\n\n\tconst chain = prompt.pipe(llm).pipe(outputParser).withConfig(getTracingConfig(context));\n\n\t// Execute the chain\n\tconst response = await chain.invoke({\n\t\tquery,\n\t\tsignal: context.getExecutionCancelSignal(),\n\t});\n\n\t// Ensure response is always returned as an array\n\treturn [response];\n}\n\n/**\n * Creates and executes an LLM chain with the given prompt and optional output parsers\n */\nexport async function executeChain({\n\tcontext,\n\titemIndex,\n\tquery,\n\tllm,\n\toutputParser,\n\tmessages,\n}: ChainExecutionParams): Promise<unknown[]> {\n\t// If no output parsers provided, use a simple chain with basic prompt template\n\tif (!outputParser) {\n\t\tconst promptTemplate = await createPromptTemplate({\n\t\t\tcontext,\n\t\t\titemIndex,\n\t\t\tllm,\n\t\t\tmessages,\n\t\t\tquery,\n\t\t});\n\n\t\treturn await executeSimpleChain({\n\t\t\tcontext,\n\t\t\tllm,\n\t\t\tquery,\n\t\t\tprompt: promptTemplate,\n\t\t});\n\t}\n\n\tconst formatInstructions = outputParser.getFormatInstructions();\n\n\t// Create a prompt template with format instructions\n\tconst promptWithInstructions = await createPromptTemplate({\n\t\tcontext,\n\t\titemIndex,\n\t\tllm,\n\t\tmessages,\n\t\tformatInstructions,\n\t\tquery,\n\t});\n\n\tconst chain = promptWithInstructions\n\t\t.pipe(llm)\n\t\t.pipe(outputParser)\n\t\t.withConfig(getTracingConfig(context));\n\tconst response = await chain.invoke({ query }, { signal: context.getExecutionCancelSignal() });\n\n\t// Ensure response is always returned as an array\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\treturn Array.isArray(response) ? response : [response];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,4BAAqD;AAIrD,qBAAiC;AAEjC,yBAAqC;AAG9B,MAAM,8BAEH,uCAAoB;AAAA,EAC7B,MAAM,MAAM,MAA0B;AAErC,QAAI;AACH,YAAM,eAAe,KAAK,MAAM,IAAI;AACpC,aAAO;AAAA,IACR,SAAS,GAAG;AAEX,aAAO,MAAM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AAA,IACzD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAC;AAED,QAAM,QAAQ,uBACZ,KAAK,GAAG,EACR,KAAK,YAAY,EACjB,eAAW,iCAAiB,OAAO,CAAC;AACtC,QAAM,WAAW,MAAM,MAAM,OAAO,EAAE,MAAM,GAAG,EAAE,QAAQ,QAAQ,yBAAyB,EAAE,CAAC;AAI7F,SAAO,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ;AACtD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainLLM/methods/config.ts"],"sourcesContent":["import {\n\tAIMessagePromptTemplate,\n\tHumanMessagePromptTemplate,\n\tSystemMessagePromptTemplate,\n} from '@langchain/core/prompts';\nimport type { IDataObject, INodeInputConfiguration, INodeProperties } from 'n8n-workflow';\nimport { NodeConnectionTypes } from 'n8n-workflow';\n\nimport { promptTypeOptions, textFromPreviousNode } from '@utils/descriptions';\nimport { getTemplateNoticeField } from '@utils/sharedFields';\n\n/**\n * Dynamic input configuration generation based on node parameters\n */\nexport function getInputs(parameters: IDataObject) {\n\tconst inputs: INodeInputConfiguration[] = [\n\t\t{ displayName: '', type: 'main' },\n\t\t{\n\t\t\tdisplayName: 'Model',\n\t\t\tmaxConnections: 1,\n\t\t\ttype: 'ai_languageModel',\n\t\t\trequired: true,\n\t\t},\n\t];\n\n\t// If `hasOutputParser` is undefined it must be version 1.3 or earlier so we\n\t// always add the output parser input\n\tconst hasOutputParser = parameters?.hasOutputParser;\n\tif (hasOutputParser === undefined || hasOutputParser === true) {\n\t\tinputs.push({\n\t\t\tdisplayName: 'Output Parser',\n\t\t\ttype: 'ai_outputParser',\n\t\t\tmaxConnections: 1,\n\t\t\trequired: false,\n\t\t});\n\t}\n\n\treturn inputs;\n}\n\n/**\n * Node properties configuration\n */\nexport const nodeProperties: INodeProperties[] = [\n\tgetTemplateNoticeField(1978),\n\t{\n\t\tdisplayName: 'Prompt',\n\t\tname: 'prompt',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '={{ $json.input }}',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [1],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Prompt',\n\t\tname: 'prompt',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '={{ $json.chat_input }}',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [1.1, 1.2],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Prompt',\n\t\tname: 'prompt',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '={{ $json.chatInput }}',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\t...promptTypeOptions,\n\t\tdisplayOptions: {\n\t\t\thide: {\n\t\t\t\t'@version': [1, 1.1, 1.2, 1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\t...textFromPreviousNode,\n\t\tdisplayOptions: { show: { promptType: ['auto'], '@version': [{ _cnd: { gte: 1.5 } }] } },\n\t},\n\t{\n\t\tdisplayName: 'Prompt (User Message)',\n\t\tname: 'text',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '',\n\t\tplaceholder: 'e.g. Hello, how can you help me?',\n\t\ttypeOptions: {\n\t\t\trows: 2,\n\t\t},\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tpromptType: ['define'],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Require Specific Output Format',\n\t\tname: 'hasOutputParser',\n\t\ttype: 'boolean',\n\t\tdefault: false,\n\t\tnoDataExpression: true,\n\t\tdisplayOptions: {\n\t\t\thide: {\n\t\t\t\t'@version': [1, 1.1, 1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Chat Messages (if Using a Chat Model)',\n\t\tname: 'messages',\n\t\ttype: 'fixedCollection',\n\t\ttypeOptions: {\n\t\t\tmultipleValues: true,\n\t\t},\n\t\tdefault: {},\n\t\tplaceholder: 'Add prompt',\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'messageValues',\n\t\t\t\tdisplayName: 'Prompt',\n\t\t\t\tvalues: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Type Name or ID',\n\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'AI',\n\t\t\t\t\t\t\t\tvalue: AIMessagePromptTemplate.lc_name(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'System',\n\t\t\t\t\t\t\t\tvalue: SystemMessagePromptTemplate.lc_name(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'User',\n\t\t\t\t\t\t\t\tvalue: HumanMessagePromptTemplate.lc_name(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: SystemMessagePromptTemplate.lc_name(),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Message Type',\n\t\t\t\t\t\tname: 'messageType',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\ttype: [HumanMessagePromptTemplate.lc_name()],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Text',\n\t\t\t\t\t\t\t\tvalue: 'text',\n\t\t\t\t\t\t\t\tdescription: 'Simple text message',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Image (Binary)',\n\t\t\t\t\t\t\t\tvalue: 'imageBinary',\n\t\t\t\t\t\t\t\tdescription: 'Process the binary input from the previous node',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Image (URL)',\n\t\t\t\t\t\t\t\tvalue: 'imageUrl',\n\t\t\t\t\t\t\t\tdescription: 'Process the image from the specified URL',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'text',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Image Data Field Name',\n\t\t\t\t\t\tname: 'binaryImageDataKey',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'data',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"The name of the field in the chain's input that contains the binary image file to be processed\",\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tmessageType: ['imageBinary'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Image URL',\n\t\t\t\t\t\tname: 'imageUrl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tdescription: 'URL to the image to be processed',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tmessageType: ['imageUrl'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Image Details',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Control how the model processes the image and generates its textual understanding',\n\t\t\t\t\t\tname: 'imageDetail',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\ttype: [HumanMessagePromptTemplate.lc_name()],\n\t\t\t\t\t\t\t\tmessageType: ['imageBinary', 'imageUrl'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Auto',\n\t\t\t\t\t\t\t\tvalue: 'auto',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'Model will use the auto setting which will look at the image input size and decide if it should use the low or high setting',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Low',\n\t\t\t\t\t\t\t\tvalue: 'low',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'The model will receive a low-res 512px x 512px version of the image, and represent the image with a budget of 65 tokens. This allows the API to return faster responses and consume fewer input tokens for use cases that do not require high detail.',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'High',\n\t\t\t\t\t\t\t\tvalue: 'high',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'Allows the model to see the low res image and then creates detailed crops of input images as 512px squares based on the input image size. Each of the detailed crops uses twice the token budget (65 tokens) for a total of 129 tokens.',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'auto',\n\t\t\t\t\t},\n\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Message',\n\t\t\t\t\t\tname: 'message',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tmessageType: ['imageBinary', 'imageUrl'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tdisplayName: `Connect an <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='${NodeConnectionTypes.AiOutputParser}'>output parser</a> on the canvas to specify the output format you require`,\n\t\tname: 'notice',\n\t\ttype: 'notice',\n\t\tdefault: '',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\thasOutputParser: [true],\n\t\t\t},\n\t\t},\n\t},\n];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAIO;AAEP,0BAAoC;AAEpC,0BAAwD;AACxD,0BAAuC;AAKhC,SAAS,UAAU,YAAyB;AAClD,QAAM,SAAoC;AAAA,IACzC,EAAE,aAAa,IAAI,MAAM,OAAO;AAAA,IAChC;AAAA,MACC,aAAa;AAAA,MACb,gBAAgB;AAAA,MAChB,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AAIA,QAAM,kBAAkB,YAAY;AACpC,MAAI,oBAAoB,UAAa,oBAAoB,MAAM;AAC9D,WAAO,KAAK;AAAA,MACX,aAAa;AAAA,MACb,MAAM;AAAA,MACN,gBAAgB;AAAA,MAChB,UAAU;AAAA,IACX,CAAC;AAAA,EACF;AAEA,SAAO;AACR;AAKO,MAAM,iBAAoC;AAAA,MAChD,4CAAuB,IAAI;AAAA,EAC3B;AAAA,IACC,aAAa;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS;AAAA,IACT,gBAAgB;AAAA,MACf,MAAM;AAAA,QACL,YAAY,CAAC,CAAC;AAAA,MACf;AAAA,IACD;AAAA,EACD;AAAA,EACA;AAAA,IACC,aAAa;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS;AAAA,IACT,gBAAgB;AAAA,MACf,MAAM;AAAA,QACL,YAAY,CAAC,KAAK,GAAG;AAAA,MACtB;AA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ACA;AAAA,YACC,aAAa;AAAA,YACb,aACC;AAAA,YACD,MAAM;AAAA,YACN,MAAM;AAAA,YACN,gBAAgB;AAAA,cACf,MAAM;AAAA,gBACL,MAAM,CAAC,0CAA2B,QAAQ,CAAC;AAAA,gBAC3C,aAAa,CAAC,eAAe,UAAU;AAAA,cACxC;AAAA,YACD;AAAA,YACA,SAAS;AAAA,cACR;AAAA,gBACC,MAAM;AAAA,gBACN,OAAO;AAAA,gBACP,aACC;AAAA,cACF;AAAA,cACA;AAAA,gBACC,MAAM;AAAA,gBACN,OAAO;AAAA,gBACP,aACC;AAAA,cACF;AAAA,cACA;AAAA,gBACC,MAAM;AAAA,gBACN,OAAO;AAAA,gBACP,aACC;AAAA,cACF;AAAA,YACD;AAAA,YACA,SAAS;AAAA,UACV;AAAA,UAEA;AAAA,YACC,aAAa;AAAA,YACb,MAAM;AAAA,YACN,MAAM;AAAA,YACN,UAAU;AAAA,YACV,gBAAgB;AAAA,cACf,MAAM;AAAA,gBACL,aAAa,CAAC,eAAe,UAAU;AAAA,cACxC;AAAA,YACD;AAAA,YACA,SAAS;AAAA,UACV;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EACA;AAAA,IACC,aAAa,8FAA8F,wCAAoB,cAAc;AAAA,IAC7I,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,gBAAgB;AAAA,MACf,MAAM;AAAA,QACL,iBAAiB,CAAC,IAAI;AAAA,MACvB;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainLLM/methods/imageUtils.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { HumanMessage } from '@langchain/core/messages';\nimport { ChatGoogleGenerativeAI } from '@langchain/google-genai';\nimport { ChatOllama } from '@langchain/ollama';\nimport type { IExecuteFunctions, IBinaryData } from 'n8n-workflow';\nimport { NodeOperationError, NodeConnectionTypes, OperationalError } from 'n8n-workflow';\n\nimport type { MessageTemplate } from './types';\n\nexport class UnsupportedMimeTypeError extends OperationalError {}\n\n/**\n * Converts binary image data to a data URI\n */\nexport function dataUriFromImageData(binaryData: IBinaryData, bufferData: Buffer): string {\n\tif (!binaryData.mimeType?.startsWith('image/')) {\n\t\tthrow new UnsupportedMimeTypeError(\n\t\t\t`${binaryData.mimeType} is not a supported type of binary data. Only images are supported.`,\n\t\t);\n\t}\n\treturn `data:${binaryData.mimeType};base64,${bufferData.toString('base64')}`;\n}\n\n/**\n * Creates a human message with image content from either binary data or URL\n */\nexport async function createImageMessage({\n\tcontext,\n\titemIndex,\n\tmessage,\n}: {\n\tcontext: IExecuteFunctions;\n\titemIndex: number;\n\tmessage: MessageTemplate;\n}): Promise<HumanMessage> {\n\t// Validate message type\n\tif (message.messageType !== 'imageBinary' && message.messageType !== 'imageUrl') {\n\t\tthrow new NodeOperationError(\n\t\t\tcontext.getNode(),\n\t\t\t'Invalid message type. Only imageBinary and imageUrl are supported',\n\t\t);\n\t}\n\n\tconst detail = message.imageDetail === 'auto' ? undefined : message.imageDetail;\n\n\t// Handle image URL case\n\tif (message.messageType === 'imageUrl' && message.imageUrl) {\n\t\treturn new HumanMessage({\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'image_url',\n\t\t\t\t\timage_url: {\n\t\t\t\t\t\turl: message.imageUrl,\n\t\t\t\t\t\tdetail,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t}\n\n\t// Handle binary image case\n\tconst binaryDataKey = message.binaryImageDataKey ?? 'data';\n\tconst inputData = context.getInputData()[itemIndex];\n\tconst binaryData = inputData.binary?.[binaryDataKey] as IBinaryData;\n\n\tif (!binaryData) {\n\t\tthrow new NodeOperationError(context.getNode(), 'No binary data set.');\n\t}\n\n\tconst bufferData = await context.helpers.getBinaryDataBuffer(itemIndex, binaryDataKey);\n\tconst model = (await context.getInputConnectionData(\n\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t0,\n\t)) as BaseLanguageModel;\n\n\ttry {\n\t\t// Create data URI from binary data\n\t\tconst dataURI = dataUriFromImageData(binaryData, bufferData);\n\n\t\t// Some models need different image URL formats\n\t\tconst directUriModels = [ChatGoogleGenerativeAI, ChatOllama];\n\t\tconst imageUrl = directUriModels.some((i) => model instanceof i)\n\t\t\t? dataURI\n\t\t\t: { url: dataURI, detail };\n\n\t\treturn new HumanMessage({\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'image_url',\n\t\t\t\t\timage_url: imageUrl,\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t} catch (error) {\n\t\tif (error instanceof UnsupportedMimeTypeError)\n\t\t\tthrow new NodeOperationError(context.getNode(), error.message);\n\t\tthrow error;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAA6B;AAC7B,0BAAuC;AACvC,oBAA2B;AAE3B,0BAA0E;AAInE,MAAM,iCAAiC,qCAAiB;AAAC;AAKzD,SAAS,qBAAqB,YAAyB,YAA4B;AACzF,MAAI,CAAC,WAAW,UAAU,WAAW,QAAQ,GAAG;AAC/C,UAAM,IAAI;AAAA,MACT,GAAG,WAAW,QAAQ;AAAA,IACvB;AAAA,EACD;AACA,SAAO,QAAQ,WAAW,QAAQ,WAAW,WAAW,SAAS,QAAQ,CAAC;AAC3E;AAKA,eAAsB,mBAAmB;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACD,GAI0B;AAEzB,MAAI,QAAQ,gBAAgB,iBAAiB,QAAQ,gBAAgB,YAAY;AAChF,UAAM,IAAI;AAAA,MACT,QAAQ,QAAQ;AAAA,MAChB;AAAA,IACD;AAAA,EACD;AAEA,QAAM,SAAS,QAAQ,gBAAgB,SAAS,SAAY,QAAQ;AAGpE,MAAI,QAAQ,gBAAgB,cAAc,QAAQ,UAAU;AAC3D,WAAO,IAAI,6BAAa;AAAA,MACvB,SAAS;AAAA,QACR;AAAA,UACC,MAAM;AAAA,UACN,WAAW;AAAA,YACV,KAAK,QAAQ;AAAA,YACb;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAC;AAAA,EACF;AAGA,QAAM,gBAAgB,QAAQ,sBAAsB;AACpD,QAAM,YAAY,QAAQ,aAAa,EAAE,SAAS;AAClD,QAAM,aAAa,UAAU,SAAS,aAAa;AAEnD,MAAI,CAAC,YAAY;AAChB,UAAM,IAAI,uCAAmB,QAAQ,QAAQ,GAAG,qBAAqB;AAAA,EACtE;AAEA,QAAM,aAAa,MAAM,QAAQ,QAAQ,oBAAoB,WAAW,aAAa;AACrF,QAAM,QAAS,MAAM,QAAQ;AAAA,IAC5B,wCAAoB;AAAA,IACpB;AAAA,EACD;AAEA,MAAI;AAEH,UAAM,UAAU,qBAAqB,YAAY,UAAU;AAG3D,UAAM,kBAAkB,CAAC,4CAAwB,wBAAU;AAC3D,UAAM,WAAW,gBAAgB,KAAK,CAAC,MAAM,iBAAiB,CAAC,IAC5D,UACA,EAAE,KAAK,SAAS,OAAO;AAE1B,WAAO,IAAI,6BAAa;AAAA,MACvB,SAAS;AAAA,QACR;AAAA,UACC,MAAM;AAAA,UACN,WAAW;AAAA,QACZ;AAAA,MACD;AAAA,IACD,CAAC;AAAA,EACF,SAAS,OAAO;AACf,QAAI,iBAAiB;AACpB,YAAM,IAAI,uCAAmB,QAAQ,QAAQ,GAAG,MAAM,OAAO;AAC9D,UAAM;AAAA,EACP;AACD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainLLM/methods/index.ts"],"sourcesContent":["export { executeChain } from './chainExecutor';\nexport { getInputs, nodeProperties } from './config';\nexport { formatResponse } from './responseFormatter';\nexport type { MessageTemplate } from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA6B;AAC7B,oBAA0C;AAC1C,+BAA+B;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainLLM/methods/promptUtils.ts"],"sourcesContent":["import { HumanMessage } from '@langchain/core/messages';\nimport type { BaseMessagePromptTemplateLike } from '@langchain/core/prompts';\nimport {\n\tAIMessagePromptTemplate,\n\tPromptTemplate,\n\tSystemMessagePromptTemplate,\n\tHumanMessagePromptTemplate,\n\tChatPromptTemplate,\n} from '@langchain/core/prompts';\nimport type { IExecuteFunctions } from 'n8n-workflow';\nimport { OperationalError } from 'n8n-workflow';\n\nimport { isChatInstance } from '@utils/helpers';\n\nimport { createImageMessage } from './imageUtils';\nimport type { MessageTemplate, PromptParams } from './types';\n\n/**\n * Creates a basic query template that may include format instructions\n */\nfunction buildQueryTemplate(formatInstructions?: string): PromptTemplate {\n\treturn new PromptTemplate({\n\t\ttemplate: `{query}${formatInstructions ? '\\n{formatInstructions}' : ''}`,\n\t\tinputVariables: ['query'],\n\t\tpartialVariables: formatInstructions ? { formatInstructions } : undefined,\n\t});\n}\n\n/**\n * Process an array of message templates into LangChain message objects\n */\nasync function processMessageTemplates({\n\tcontext,\n\titemIndex,\n\tmessages,\n}: {\n\tcontext: IExecuteFunctions;\n\titemIndex: number;\n\tmessages: MessageTemplate[];\n}): Promise<BaseMessagePromptTemplateLike[]> {\n\treturn await Promise.all(\n\t\tmessages.map(async (message) => {\n\t\t\t// Find the appropriate message class based on type\n\t\t\tconst messageClass = [\n\t\t\t\tSystemMessagePromptTemplate,\n\t\t\t\tAIMessagePromptTemplate,\n\t\t\t\tHumanMessagePromptTemplate,\n\t\t\t].find((m) => m.lc_name() === message.type);\n\n\t\t\tif (!messageClass) {\n\t\t\t\tthrow new OperationalError('Invalid message type', {\n\t\t\t\t\textra: { messageType: message.type },\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Handle image messages specially for human messages\n\t\t\tif (messageClass === HumanMessagePromptTemplate && message.messageType !== 'text') {\n\t\t\t\treturn await createImageMessage({ context, itemIndex, message });\n\t\t\t}\n\n\t\t\t// Process text messages\n\t\t\t// Escape curly braces in the message to prevent LangChain from treating them as variables\n\t\t\treturn messageClass.fromTemplate(\n\t\t\t\t(message.message || '').replace(/[{}]/g, (match) => match + match),\n\t\t\t);\n\t\t}),\n\t);\n}\n\n/**\n * Finalizes the prompt template by adding or updating the query in the message chain\n */\nasync function finalizePromptTemplate({\n\tparsedMessages,\n\tqueryTemplate,\n\tquery,\n}: {\n\tparsedMessages: BaseMessagePromptTemplateLike[];\n\tqueryTemplate: PromptTemplate;\n\tquery?: string;\n}): Promise<ChatPromptTemplate> {\n\t// Check if the last message is a human message with multi-content array\n\tconst lastMessage = parsedMessages[parsedMessages.length - 1];\n\n\tif (lastMessage instanceof HumanMessage && Array.isArray(lastMessage.content)) {\n\t\t// Add the query to the existing human message content\n\t\tconst humanMessage = new HumanMessagePromptTemplate(queryTemplate);\n\n\t\t// Format the message with the query and add the content synchronously\n\t\tconst formattedMessage = await humanMessage.format({ query });\n\n\t\t// Create a new array with the existing content plus the new item\n\t\tif (Array.isArray(lastMessage.content)) {\n\t\t\t// Clone the current content array and add the new item\n\t\t\tconst updatedContent = [\n\t\t\t\t...lastMessage.content,\n\t\t\t\t{\n\t\t\t\t\ttext: formattedMessage.content.toString(),\n\t\t\t\t\ttype: 'text',\n\t\t\t\t},\n\t\t\t];\n\n\t\t\t// Replace the content with the updated array\n\t\t\tlastMessage.content = updatedContent;\n\t\t}\n\t} else {\n\t\t// Otherwise, add a new human message with the query\n\t\tparsedMessages.push(new HumanMessagePromptTemplate(queryTemplate));\n\t}\n\n\treturn ChatPromptTemplate.fromMessages(parsedMessages);\n}\n\n/**\n * Builds the appropriate prompt template based on model type (chat vs completion)\n * and provided messages\n */\nexport async function createPromptTemplate({\n\tcontext,\n\titemIndex,\n\tllm,\n\tmessages,\n\tformatInstructions,\n\tquery,\n}: PromptParams) {\n\t// Create base query template\n\tconst queryTemplate = buildQueryTemplate(formatInstructions);\n\n\t// For non-chat models, just return the query template\n\tif (!isChatInstance(llm)) {\n\t\treturn queryTemplate;\n\t}\n\n\t// For chat models, process the messages if provided\n\tconst parsedMessages = messages?.length\n\t\t? await processMessageTemplates({ context, itemIndex, messages })\n\t\t: [];\n\n\t// Add or update the query in the message chain\n\treturn await finalizePromptTemplate({\n\t\tparsedMessages,\n\t\tqueryTemplate,\n\t\tquery,\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA6B;AAE7B,qBAMO;AAEP,0BAAiC;AAEjC,qBAA+B;AAE/B,wBAAmC;AAMnC,SAAS,mBAAmB,oBAA6C;AACxE,SAAO,IAAI,8BAAe;AAAA,IACzB,UAAU,UAAU,qBAAqB,2BAA2B,EAAE;AAAA,IACtE,gBAAgB,CAAC,OAAO;AAAA,IACxB,kBAAkB,qBAAqB,EAAE,mBAAmB,IAAI;AAAA,EACjE,CAAC;AACF;AAKA,eAAe,wBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AACD,GAI6C;AAC5C,SAAO,MAAM,QAAQ;AAAA,IACpB,SAAS,IAAI,OAAO,YAAY;AAE/B,YAAM,eAAe;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,MACD,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,MAAM,QAAQ,IAAI;AAE1C,UAAI,CAAC,cAAc;AAClB,cAAM,IAAI,qCAAiB,wBAAwB;AAAA,UAClD,OAAO,EAAE,aAAa,QAAQ,KAAK;AAAA,QACpC,CAAC;AAAA,MACF;AAGA,UAAI,iBAAiB,6CAA8B,QAAQ,gBAAgB,QAAQ;AAClF,eAAO,UAAM,sCAAmB,EAAE,SAAS,WAAW,QAAQ,CAAC;AAAA,MAChE;AAIA,aAAO,aAAa;AAAA,SAClB,QAAQ,WAAW,IAAI,QAAQ,SAAS,CAAC,UAAU,QAAQ,KAAK;AAAA,MAClE;AAAA,IACD,CAAC;AAAA,EACF;AACD;AAKA,eAAe,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AACD,GAIgC;AAE/B,QAAM,cAAc,eAAe,eAAe,SAAS,CAAC;AAE5D,MAAI,uBAAuB,gCAAgB,MAAM,QAAQ,YAAY,OAAO,GAAG;AAE9E,UAAM,eAAe,IAAI,0CAA2B,aAAa;AAGjE,UAAM,mBAAmB,MAAM,aAAa,OAAO,EAAE,MAAM,CAAC;AAG5D,QAAI,MAAM,QAAQ,YAAY,OAAO,GAAG;AAEvC,YAAM,iBAAiB;AAAA,QACtB,GAAG,YAAY;AAAA,QACf;AAAA,UACC,MAAM,iBAAiB,QAAQ,SAAS;AAAA,UACxC,MAAM;AAAA,QACP;AAAA,MACD;AAGA,kBAAY,UAAU;AAAA,IACvB;AAAA,EACD,OAAO;AAEN,mBAAe,KAAK,IAAI,0CAA2B,aAAa,CAAC;AAAA,EAClE;AAEA,SAAO,kCAAmB,aAAa,cAAc;AACtD;AAMA,eAAsB,qBAAqB;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAiB;AAEhB,QAAM,gBAAgB,mBAAmB,kBAAkB;AAG3D,MAAI,KAAC,+BAAe,GAAG,GAAG;AACzB,WAAO;AAAA,EACR;AAGA,QAAM,iBAAiB,UAAU,SAC9B,MAAM,wBAAwB,EAAE,SAAS,WAAW,SAAS,CAAC,IAC9D,CAAC;AAGJ,SAAO,MAAM,uBAAuB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAC;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainLLM/methods/responseFormatter.ts"],"sourcesContent":["import type { IDataObject } from 'n8n-workflow';\n\n/**\n * Formats the response from the LLM chain into a consistent structure\n */\nexport function formatResponse(response: unknown, returnUnwrappedObject: boolean): IDataObject {\n\tif (typeof response === 'string') {\n\t\treturn {\n\t\t\ttext: response.trim(),\n\t\t};\n\t}\n\n\tif (Array.isArray(response)) {\n\t\treturn {\n\t\t\tdata: response,\n\t\t};\n\t}\n\n\tif (response instanceof Object) {\n\t\tif (returnUnwrappedObject) {\n\t\t\treturn response as IDataObject;\n\t\t}\n\n\t\t// If the response is an object and we are not unwrapping it, we need to stringify it\n\t\t// to be backwards compatible with older versions of the chain(< 1.6)\n\t\treturn {\n\t\t\ttext: JSON.stringify(response),\n\t\t};\n\t}\n\n\treturn {\n\t\tresponse: {\n\t\t\ttext: response,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,eAAe,UAAmB,uBAA6C;AAC9F,MAAI,OAAO,aAAa,UAAU;AACjC,WAAO;AAAA,MACN,MAAM,SAAS,KAAK;AAAA,IACrB;AAAA,EACD;AAEA,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC5B,WAAO;AAAA,MACN,MAAM;AAAA,IACP;AAAA,EACD;AAEA,MAAI,oBAAoB,QAAQ;AAC/B,QAAI,uBAAuB;AAC1B,aAAO;AAAA,IACR;AAIA,WAAO;AAAA,MACN,MAAM,KAAK,UAAU,QAAQ;AAAA,IAC9B;AAAA,EACD;AAEA,SAAO;AAAA,IACN,UAAU;AAAA,MACT,MAAM;AAAA,IACP;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainLLM/methods/types.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { BaseChatModel } from '@langchain/core/language_models/chat_models';\nimport type { IExecuteFunctions } from 'n8n-workflow';\n\nimport type { N8nOutputParser } from '@utils/output_parsers/N8nOutputParser';\n\n/**\n * Interface for describing a message template in the UI\n */\nexport interface MessageTemplate {\n\ttype: string;\n\tmessage: string;\n\tmessageType: 'text' | 'imageBinary' | 'imageUrl';\n\tbinaryImageDataKey?: string;\n\timageUrl?: string;\n\timageDetail?: 'auto' | 'low' | 'high';\n}\n\n/**\n * Parameters for prompt creation\n */\nexport interface PromptParams {\n\tcontext: IExecuteFunctions;\n\titemIndex: number;\n\tllm: BaseLanguageModel | BaseChatModel;\n\tmessages?: MessageTemplate[];\n\tformatInstructions?: string;\n\tquery?: string;\n}\n\n/**\n * Parameters for chain execution\n */\nexport interface ChainExecutionParams {\n\tcontext: IExecuteFunctions;\n\titemIndex: number;\n\tquery: string;\n\tllm: BaseLanguageModel;\n\toutputParser?: N8nOutputParser;\n\tmessages?: MessageTemplate[];\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport {\n\tChatPromptTemplate,\n\tSystemMessagePromptTemplate,\n\tHumanMessagePromptTemplate,\n\tPromptTemplate,\n} from '@langchain/core/prompts';\nimport type { BaseRetriever } from '@langchain/core/retrievers';\nimport { createStuffDocumentsChain } from 'langchain/chains/combine_documents';\nimport { createRetrievalChain } from 'langchain/chains/retrieval';\nimport { NodeConnectionTypes, NodeOperationError, parseErrorMetadata } from 'n8n-workflow';\nimport {\n\ttype INodeProperties,\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n} from 'n8n-workflow';\n\nimport { promptTypeOptions, textFromPreviousNode } from '@utils/descriptions';\nimport { getPromptInputByType, isChatInstance } from '@utils/helpers';\nimport { getTemplateNoticeField } from '@utils/sharedFields';\nimport { getTracingConfig } from '@utils/tracing';\n\nconst SYSTEM_PROMPT_TEMPLATE = `You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question.\nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\n----------------\nContext: {context}`;\n\n// Due to the refactoring in version 1.5, the variable name {question} needed to be changed to {input} in the prompt template.\nconst LEGACY_INPUT_TEMPLATE_KEY = 'question';\nconst INPUT_TEMPLATE_KEY = 'input';\n\nconst systemPromptOption: INodeProperties = {\n\tdisplayName: 'System Prompt Template',\n\tname: 'systemPromptTemplate',\n\ttype: 'string',\n\tdefault: SYSTEM_PROMPT_TEMPLATE,\n\ttypeOptions: {\n\t\trows: 6,\n\t},\n};\n\nexport class ChainRetrievalQa implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Question and Answer Chain',\n\t\tname: 'chainRetrievalQa',\n\t\ticon: 'fa:link',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5],\n\t\tdescription: 'Answer questions about retrieved documents',\n\t\tdefaults: {\n\t\t\tname: 'Question and Answer Chain',\n\t\t\tcolor: '#909298',\n\t\t},\n\t\tcodex: {\n\t\t\talias: ['LangChain'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainretrievalqa/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [\n\t\t\tNodeConnectionTypes.Main,\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Retriever',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiRetriever,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [],\n\t\tproperties: [\n\t\t\tgetTemplateNoticeField(1960),\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chat_input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chatInput }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.2],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...promptTypeOptions,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\thide: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...textFromPreviousNode,\n\t\t\t\tdisplayOptions: { show: { promptType: ['auto'], '@version': [{ _cnd: { gte: 1.4 } }] } },\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Prompt (User Message)',\n\t\t\t\tname: 'text',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. Hello, how can you help me?',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tpromptType: ['define'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${LEGACY_INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { lt: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Retrieval QA Chain');\n\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\t// Run for each item\n\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\ttry {\n\t\t\t\tconst model = (await this.getInputConnectionData(\n\t\t\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t\t\t0,\n\t\t\t\t)) as BaseLanguageModel;\n\n\t\t\t\tconst retriever = (await this.getInputConnectionData(\n\t\t\t\t\tNodeConnectionTypes.AiRetriever,\n\t\t\t\t\t0,\n\t\t\t\t)) as BaseRetriever;\n\n\t\t\t\tlet query;\n\n\t\t\t\tif (this.getNode().typeVersion <= 1.2) {\n\t\t\t\t\tquery = this.getNodeParameter('query', itemIndex) as string;\n\t\t\t\t} else {\n\t\t\t\t\tquery = getPromptInputByType({\n\t\t\t\t\t\tctx: this,\n\t\t\t\t\t\ti: itemIndex,\n\t\t\t\t\t\tinputKey: 'text',\n\t\t\t\t\t\tpromptTypeKey: 'promptType',\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (query === undefined) {\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), 'The ‘query‘ parameter is empty.');\n\t\t\t\t}\n\n\t\t\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\t\t\tsystemPromptTemplate?: string;\n\t\t\t\t};\n\n\t\t\t\tlet templateText = options.systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE;\n\n\t\t\t\t// Replace legacy input template key for versions 1.4 and below\n\t\t\t\tif (this.getNode().typeVersion < 1.5) {\n\t\t\t\t\ttemplateText = templateText.replace(\n\t\t\t\t\t\t`{${LEGACY_INPUT_TEMPLATE_KEY}}`,\n\t\t\t\t\t\t`{${INPUT_TEMPLATE_KEY}}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Create prompt template based on model type and user configuration\n\t\t\t\tlet promptTemplate;\n\t\t\t\tif (isChatInstance(model)) {\n\t\t\t\t\t// For chat models, create a chat prompt template with system and human messages\n\t\t\t\t\tconst messages = [\n\t\t\t\t\t\tSystemMessagePromptTemplate.fromTemplate(templateText),\n\t\t\t\t\t\tHumanMessagePromptTemplate.fromTemplate('{input}'),\n\t\t\t\t\t];\n\t\t\t\t\tpromptTemplate = ChatPromptTemplate.fromMessages(messages);\n\t\t\t\t} else {\n\t\t\t\t\t// For non-chat models, create a text prompt template with Question/Answer format\n\t\t\t\t\tconst questionSuffix =\n\t\t\t\t\t\toptions.systemPromptTemplate === undefined ? '\\n\\nQuestion: {input}\\nAnswer:' : '';\n\n\t\t\t\t\tpromptTemplate = new PromptTemplate({\n\t\t\t\t\t\ttemplate: templateText + questionSuffix,\n\t\t\t\t\t\tinputVariables: ['context', 'input'],\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Create the document chain that combines the retrieved documents\n\t\t\t\tconst combineDocsChain = await createStuffDocumentsChain({\n\t\t\t\t\tllm: model,\n\t\t\t\t\tprompt: promptTemplate,\n\t\t\t\t});\n\n\t\t\t\t// Create the retrieval chain that handles the retrieval and then passes to the combine docs chain\n\t\t\t\tconst retrievalChain = await createRetrievalChain({\n\t\t\t\t\tcombineDocsChain,\n\t\t\t\t\tretriever,\n\t\t\t\t});\n\n\t\t\t\t// Execute the chain with tracing config\n\t\t\t\tconst tracingConfig = getTracingConfig(this);\n\t\t\t\tconst response = await retrievalChain\n\t\t\t\t\t.withConfig(tracingConfig)\n\t\t\t\t\t.invoke({ input: query }, { signal: this.getExecutionCancelSignal() });\n\n\t\t\t\t// Get the answer from the response\n\t\t\t\tconst answer: string = response.answer;\n\t\t\t\tif (this.getNode().typeVersion >= 1.5) {\n\t\t\t\t\treturnData.push({ json: { response: answer } });\n\t\t\t\t} else {\n\t\t\t\t\t// Legacy format for versions 1.4 and below is { text: string }\n\t\t\t\t\treturnData.push({ json: { response: { text: answer } } });\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\treturnData.push({\n\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t\tmetadata,\n\t\t\t\t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AAE,EAAE,CAAC;AAAA,QACzD;AAAA,MACD,SAAS,OAAO;AACf,YAAI,KAAK,eAAe,GAAG;AAC1B,gBAAM,eAAW,wCAAmB,KAAK;AACzC,qBAAW,KAAK;AAAA,YACf,MAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,YAC7B,YAAY,EAAE,MAAM,UAAU;AAAA,YAC9B;AAAA,UACD,CAAC;AACD;AAAA,QACD;AAEA,cAAM;AAAA,MACP;AAAA,IACD;AACA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainSummarization/ChainSummarization.node.ts"],"sourcesContent":["import type { INodeTypeBaseDescription, IVersionedNodeType } from 'n8n-workflow';\nimport { VersionedNodeType } from 'n8n-workflow';\n\nimport { ChainSummarizationV1 } from './V1/ChainSummarizationV1.node';\nimport { ChainSummarizationV2 } from './V2/ChainSummarizationV2.node';\n\nexport class ChainSummarization extends VersionedNodeType {\n\tconstructor() {\n\t\tconst baseDescription: INodeTypeBaseDescription = {\n\t\t\tdisplayName: 'Summarization Chain',\n\t\t\tname: 'chainSummarization',\n\t\t\ticon: 'fa:link',\n\t\t\ticonColor: 'black',\n\t\t\tgroup: ['transform'],\n\t\t\tdescription: 'Transforms text into a concise summary',\n\t\t\tcodex: {\n\t\t\t\talias: ['LangChain'],\n\t\t\t\tcategories: ['AI'],\n\t\t\t\tsubcategories: {\n\t\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t\t},\n\t\t\t\tresources: {\n\t\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainsummarization/',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t\tdefaultVersion: 2,\n\t\t};\n\n\t\tconst nodeVersions: IVersionedNodeType['nodeVersions'] = {\n\t\t\t1: new ChainSummarizationV1(baseDescription),\n\t\t\t2: new ChainSummarizationV2(baseDescription),\n\t\t};\n\n\t\tsuper(nodeVersions, baseDescription);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAAkC;AAElC,kCAAqC;AACrC,kCAAqC;AAE9B,MAAM,2BAA2B,sCAAkB;AAAA,EACzD,cAAc;AACb,UAAM,kBAA4C;AAAA,MACjD,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,aAAa;AAAA,MACb,OAAO;AAAA,QACN,OAAO,CAAC,WAAW;AAAA,QACnB,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,UAAU,YAAY;AAAA,QAC5B;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,gBAAgB;AAAA,IACjB;AAEA,UAAM,eAAmD;AAAA,MACxD,GAAG,IAAI,iDAAqB,eAAe;AAAA,MAC3C,GAAG,IAAI,iDAAqB,eAAe;AAAA,IAC5C;AAEA,UAAM,cAAc,eAAe;AAAA,EACpC;AACD;","names":[]}
|
|
@@ -0,0 +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\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\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":";;;;;;;;;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