@n8n/n8n-nodes-langchain 1.83.1 → 1.84.1
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/build.tsbuildinfo +1 -1
- package/dist/known/nodes.json +4 -0
- package/dist/nodes/agents/Agent/Agent.node.js +5 -1
- package/dist/nodes/agents/Agent/Agent.node.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js +9 -19
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js +3 -7
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js +3 -7
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js +3 -7
- package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/execute.js +5 -6
- package/dist/nodes/agents/Agent/agents/ToolsAgent/execute.js.map +1 -1
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js +17 -389
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js.map +1 -1
- package/dist/nodes/chains/ChainLLM/methods/chainExecutor.d.ts +15 -0
- package/dist/nodes/chains/ChainLLM/methods/chainExecutor.js +69 -0
- package/dist/nodes/chains/ChainLLM/methods/chainExecutor.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/config.d.ts +14 -0
- package/dist/nodes/chains/ChainLLM/methods/config.js +253 -0
- package/dist/nodes/chains/ChainLLM/methods/config.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/imageUtils.d.ts +12 -0
- package/dist/nodes/chains/ChainLLM/methods/imageUtils.js +66 -0
- package/dist/nodes/chains/ChainLLM/methods/imageUtils.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/index.d.ts +4 -0
- package/dist/nodes/chains/ChainLLM/methods/index.js +11 -0
- package/dist/nodes/chains/ChainLLM/methods/index.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/promptUtils.d.ts +3 -0
- package/dist/nodes/chains/ChainLLM/methods/promptUtils.js +69 -0
- package/dist/nodes/chains/ChainLLM/methods/promptUtils.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/responseFormatter.d.ts +2 -0
- package/dist/nodes/chains/ChainLLM/methods/responseFormatter.js +29 -0
- package/dist/nodes/chains/ChainLLM/methods/responseFormatter.js.map +1 -0
- package/dist/nodes/chains/ChainLLM/methods/types.d.ts +28 -0
- package/dist/nodes/chains/ChainLLM/methods/types.js +3 -0
- package/dist/nodes/chains/ChainLLM/methods/types.js.map +1 -0
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js +68 -33
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js.map +1 -1
- package/dist/nodes/llms/LMChatOpenAi/methods/loadModels.js +1 -0
- package/dist/nodes/llms/LMChatOpenAi/methods/loadModels.js.map +1 -1
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js +1 -1
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.d.ts +16 -0
- package/dist/nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.js +244 -0
- package/dist/nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreMongoDBAtlas/mongodb.dark.svg +3 -0
- package/dist/nodes/vector_store/VectorStoreMongoDBAtlas/mongodb.svg +3 -0
- package/dist/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.js +1 -1
- package/dist/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStorePinecone/VectorStorePinecone.node.js +2 -2
- package/dist/nodes/vector_store/VectorStorePinecone/VectorStorePinecone.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStorePineconeInsert/VectorStorePineconeInsert.node.d.ts +1 -1
- package/dist/nodes/vector_store/VectorStorePineconeInsert/VectorStorePineconeInsert.node.js +1 -1
- package/dist/nodes/vector_store/VectorStorePineconeInsert/VectorStorePineconeInsert.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStorePineconeLoad/VectorStorePineconeLoad.node.d.ts +1 -1
- package/dist/nodes/vector_store/VectorStorePineconeLoad/VectorStorePineconeLoad.node.js +1 -1
- package/dist/nodes/vector_store/VectorStorePineconeLoad/VectorStorePineconeLoad.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.js +2 -2
- package/dist/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreSupabase/VectorStoreSupabase.node.js +2 -2
- package/dist/nodes/vector_store/VectorStoreSupabase/VectorStoreSupabase.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreSupabaseInsert/VectorStoreSupabaseInsert.node.d.ts +1 -1
- package/dist/nodes/vector_store/VectorStoreSupabaseInsert/VectorStoreSupabaseInsert.node.js +1 -1
- package/dist/nodes/vector_store/VectorStoreSupabaseInsert/VectorStoreSupabaseInsert.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.d.ts +1 -1
- package/dist/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.js +1 -1
- package/dist/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.js +1 -1
- package/dist/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.js.map +1 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/constants.d.ts +4 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/constants.js +44 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/constants.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.d.ts +15 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js +226 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/index.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/index.js +22 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/index.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/insertOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/insertOperation.js +34 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/insertOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js +33 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js +42 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js +16 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/updateOperation.d.ts +5 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/updateOperation.js +39 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/updateOperation.js.map +1 -0
- package/dist/nodes/vector_store/shared/{createVectorStoreNode.d.ts → createVectorStoreNode/types.d.ts} +3 -16
- package/dist/nodes/vector_store/shared/createVectorStoreNode/types.js +3 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/types.js.map +1 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/utils.d.ts +6 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/utils.js +20 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/utils.js.map +1 -0
- package/dist/types/nodes.json +10 -9
- package/dist/utils/helpers.d.ts +1 -0
- package/dist/utils/helpers.js +12 -0
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/output_parsers/N8nOutputFixingParser.js +6 -1
- package/dist/utils/output_parsers/N8nOutputFixingParser.js.map +1 -1
- package/dist/utils/output_parsers/N8nOutputParser.d.ts +1 -1
- package/dist/utils/output_parsers/N8nOutputParser.js +5 -5
- package/dist/utils/output_parsers/N8nOutputParser.js.map +1 -1
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js +2 -1
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js.map +1 -1
- package/package.json +9 -6
- package/dist/nodes/chains/ChainLLM/utils.d.ts +0 -5
- package/dist/nodes/chains/ChainLLM/utils.js +0 -14
- package/dist/nodes/chains/ChainLLM/utils.js.map +0 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode.js +0 -369
- package/dist/nodes/vector_store/shared/createVectorStoreNode.js.map +0 -1
- package/dist/nodes/vector_store/shared/methods/listSearch.js.map +0 -1
- /package/dist/nodes/vector_store/shared/{methods → createVectorStoreNode/methods}/listSearch.d.ts +0 -0
- /package/dist/nodes/vector_store/shared/{methods → createVectorStoreNode/methods}/listSearch.js +0 -0
|
@@ -1,144 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChainLlm = void 0;
|
|
4
|
-
const messages_1 = require("@langchain/core/messages");
|
|
5
|
-
const prompts_1 = require("@langchain/core/prompts");
|
|
6
|
-
const google_genai_1 = require("@langchain/google-genai");
|
|
7
|
-
const ollama_1 = require("@langchain/ollama");
|
|
8
|
-
const chains_1 = require("langchain/chains");
|
|
9
|
-
const output_parsers_1 = require("langchain/output_parsers");
|
|
10
4
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
11
|
-
const descriptions_1 = require("../../../utils/descriptions");
|
|
12
5
|
const helpers_1 = require("../../../utils/helpers");
|
|
13
6
|
const N8nOutputParser_1 = require("../../../utils/output_parsers/N8nOutputParser");
|
|
14
|
-
const
|
|
15
|
-
const tracing_1 = require("../../../utils/tracing");
|
|
16
|
-
const utils_1 = require("./utils");
|
|
7
|
+
const methods_1 = require("./methods");
|
|
17
8
|
const error_handling_1 = require("../../vendors/OpenAi/helpers/error-handling");
|
|
18
|
-
async function getImageMessage(context, itemIndex, message) {
|
|
19
|
-
if (message.messageType !== 'imageBinary' && message.messageType !== 'imageUrl') {
|
|
20
|
-
throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'Invalid message type. Only imageBinary and imageUrl are supported');
|
|
21
|
-
}
|
|
22
|
-
const detail = message.imageDetail === 'auto' ? undefined : message.imageDetail;
|
|
23
|
-
if (message.messageType === 'imageUrl' && message.imageUrl) {
|
|
24
|
-
return new messages_1.HumanMessage({
|
|
25
|
-
content: [
|
|
26
|
-
{
|
|
27
|
-
type: 'image_url',
|
|
28
|
-
image_url: {
|
|
29
|
-
url: message.imageUrl,
|
|
30
|
-
detail,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
const binaryDataKey = message.binaryImageDataKey ?? 'data';
|
|
37
|
-
const inputData = context.getInputData()[itemIndex];
|
|
38
|
-
const binaryData = inputData.binary?.[binaryDataKey];
|
|
39
|
-
if (!binaryData) {
|
|
40
|
-
throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'No binary data set.');
|
|
41
|
-
}
|
|
42
|
-
const bufferData = await context.helpers.getBinaryDataBuffer(itemIndex, binaryDataKey);
|
|
43
|
-
const model = (await context.getInputConnectionData("ai_languageModel", 0));
|
|
44
|
-
try {
|
|
45
|
-
const dataURI = (0, utils_1.dataUriFromImageData)(binaryData, bufferData);
|
|
46
|
-
const directUriModels = [google_genai_1.ChatGoogleGenerativeAI, ollama_1.ChatOllama];
|
|
47
|
-
const imageUrl = directUriModels.some((i) => model instanceof i)
|
|
48
|
-
? dataURI
|
|
49
|
-
: { url: dataURI, detail };
|
|
50
|
-
return new messages_1.HumanMessage({
|
|
51
|
-
content: [
|
|
52
|
-
{
|
|
53
|
-
type: 'image_url',
|
|
54
|
-
image_url: imageUrl,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
if (error instanceof utils_1.UnsupportedMimeTypeError)
|
|
61
|
-
throw new n8n_workflow_1.NodeOperationError(context.getNode(), error.message);
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async function getChainPromptTemplate(context, itemIndex, llm, messages, formatInstructions, query) {
|
|
66
|
-
const queryTemplate = new prompts_1.PromptTemplate({
|
|
67
|
-
template: `{query}${formatInstructions ? '\n{formatInstructions}' : ''}`,
|
|
68
|
-
inputVariables: ['query'],
|
|
69
|
-
partialVariables: formatInstructions ? { formatInstructions } : undefined,
|
|
70
|
-
});
|
|
71
|
-
if ((0, helpers_1.isChatInstance)(llm)) {
|
|
72
|
-
const parsedMessages = await Promise.all((messages ?? []).map(async (message) => {
|
|
73
|
-
const messageClass = [
|
|
74
|
-
prompts_1.SystemMessagePromptTemplate,
|
|
75
|
-
prompts_1.AIMessagePromptTemplate,
|
|
76
|
-
prompts_1.HumanMessagePromptTemplate,
|
|
77
|
-
].find((m) => m.lc_name() === message.type);
|
|
78
|
-
if (!messageClass) {
|
|
79
|
-
throw new n8n_workflow_1.ApplicationError('Invalid message type', {
|
|
80
|
-
extra: { messageType: message.type },
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (messageClass === prompts_1.HumanMessagePromptTemplate && message.messageType !== 'text') {
|
|
84
|
-
const test = await getImageMessage(context, itemIndex, message);
|
|
85
|
-
return test;
|
|
86
|
-
}
|
|
87
|
-
const res = messageClass.fromTemplate((message.message || '').replace(/[{}]/g, (match) => match + match));
|
|
88
|
-
return res;
|
|
89
|
-
}));
|
|
90
|
-
const lastMessage = parsedMessages[parsedMessages.length - 1];
|
|
91
|
-
if (lastMessage instanceof messages_1.HumanMessage && Array.isArray(lastMessage.content)) {
|
|
92
|
-
const humanMessage = new prompts_1.HumanMessagePromptTemplate(queryTemplate);
|
|
93
|
-
const test = await humanMessage.format({ query });
|
|
94
|
-
lastMessage.content.push({ text: test.content.toString(), type: 'text' });
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
parsedMessages.push(new prompts_1.HumanMessagePromptTemplate(queryTemplate));
|
|
98
|
-
}
|
|
99
|
-
return prompts_1.ChatPromptTemplate.fromMessages(parsedMessages);
|
|
100
|
-
}
|
|
101
|
-
return queryTemplate;
|
|
102
|
-
}
|
|
103
|
-
async function createSimpleLLMChain(context, llm, query, prompt) {
|
|
104
|
-
const chain = new chains_1.LLMChain({
|
|
105
|
-
llm,
|
|
106
|
-
prompt,
|
|
107
|
-
}).withConfig((0, tracing_1.getTracingConfig)(context));
|
|
108
|
-
const response = (await chain.invoke({
|
|
109
|
-
query,
|
|
110
|
-
signal: context.getExecutionCancelSignal(),
|
|
111
|
-
}));
|
|
112
|
-
return Array.isArray(response) ? response : [response];
|
|
113
|
-
}
|
|
114
|
-
async function getChain(context, itemIndex, query, llm, outputParsers, messages) {
|
|
115
|
-
const chatTemplate = await getChainPromptTemplate(context, itemIndex, llm, messages, undefined, query);
|
|
116
|
-
if (!outputParsers.length) {
|
|
117
|
-
return await createSimpleLLMChain(context, llm, query, chatTemplate);
|
|
118
|
-
}
|
|
119
|
-
const combinedOutputParser = outputParsers.length === 1 ? outputParsers[0] : new output_parsers_1.CombiningOutputParser(...outputParsers);
|
|
120
|
-
const formatInstructions = combinedOutputParser.getFormatInstructions();
|
|
121
|
-
const prompt = await getChainPromptTemplate(context, itemIndex, llm, messages, formatInstructions, query);
|
|
122
|
-
const chain = prompt.pipe(llm).pipe(combinedOutputParser);
|
|
123
|
-
const response = (await chain.withConfig((0, tracing_1.getTracingConfig)(context)).invoke({ query }));
|
|
124
|
-
return Array.isArray(response) ? response : [response];
|
|
125
|
-
}
|
|
126
|
-
function getInputs(parameters) {
|
|
127
|
-
const hasOutputParser = parameters?.hasOutputParser;
|
|
128
|
-
const inputs = [
|
|
129
|
-
{ displayName: '', type: "main" },
|
|
130
|
-
{
|
|
131
|
-
displayName: 'Model',
|
|
132
|
-
maxConnections: 1,
|
|
133
|
-
type: "ai_languageModel",
|
|
134
|
-
required: true,
|
|
135
|
-
},
|
|
136
|
-
];
|
|
137
|
-
if (hasOutputParser === undefined || hasOutputParser === true) {
|
|
138
|
-
inputs.push({ displayName: 'Output Parser', type: "ai_outputParser" });
|
|
139
|
-
}
|
|
140
|
-
return inputs;
|
|
141
|
-
}
|
|
142
9
|
class ChainLlm {
|
|
143
10
|
constructor() {
|
|
144
11
|
this.description = {
|
|
@@ -147,7 +14,7 @@ class ChainLlm {
|
|
|
147
14
|
icon: 'fa:link',
|
|
148
15
|
iconColor: 'black',
|
|
149
16
|
group: ['transform'],
|
|
150
|
-
version: [1, 1.1, 1.2, 1.3, 1.4, 1.5],
|
|
17
|
+
version: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6],
|
|
151
18
|
description: 'A simple chain to prompt a large language model',
|
|
152
19
|
defaults: {
|
|
153
20
|
name: 'Basic LLM Chain',
|
|
@@ -167,244 +34,21 @@ class ChainLlm {
|
|
|
167
34
|
],
|
|
168
35
|
},
|
|
169
36
|
},
|
|
170
|
-
inputs: `={{ ((parameter) => { ${getInputs.toString()}; return getInputs(parameter) })($parameter) }}`,
|
|
37
|
+
inputs: `={{ ((parameter) => { ${methods_1.getInputs.toString()}; return getInputs(parameter) })($parameter) }}`,
|
|
171
38
|
outputs: ["main"],
|
|
172
39
|
credentials: [],
|
|
173
|
-
properties:
|
|
174
|
-
(0, sharedFields_1.getTemplateNoticeField)(1978),
|
|
175
|
-
{
|
|
176
|
-
displayName: 'Prompt',
|
|
177
|
-
name: 'prompt',
|
|
178
|
-
type: 'string',
|
|
179
|
-
required: true,
|
|
180
|
-
default: '={{ $json.input }}',
|
|
181
|
-
displayOptions: {
|
|
182
|
-
show: {
|
|
183
|
-
'@version': [1],
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
displayName: 'Prompt',
|
|
189
|
-
name: 'prompt',
|
|
190
|
-
type: 'string',
|
|
191
|
-
required: true,
|
|
192
|
-
default: '={{ $json.chat_input }}',
|
|
193
|
-
displayOptions: {
|
|
194
|
-
show: {
|
|
195
|
-
'@version': [1.1, 1.2],
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
displayName: 'Prompt',
|
|
201
|
-
name: 'prompt',
|
|
202
|
-
type: 'string',
|
|
203
|
-
required: true,
|
|
204
|
-
default: '={{ $json.chatInput }}',
|
|
205
|
-
displayOptions: {
|
|
206
|
-
show: {
|
|
207
|
-
'@version': [1.3],
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
...descriptions_1.promptTypeOptions,
|
|
213
|
-
displayOptions: {
|
|
214
|
-
hide: {
|
|
215
|
-
'@version': [1, 1.1, 1.2, 1.3],
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
...descriptions_1.textFromPreviousNode,
|
|
221
|
-
displayOptions: { show: { promptType: ['auto'], '@version': [{ _cnd: { gte: 1.5 } }] } },
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
displayName: 'Prompt (User Message)',
|
|
225
|
-
name: 'text',
|
|
226
|
-
type: 'string',
|
|
227
|
-
required: true,
|
|
228
|
-
default: '',
|
|
229
|
-
placeholder: 'e.g. Hello, how can you help me?',
|
|
230
|
-
typeOptions: {
|
|
231
|
-
rows: 2,
|
|
232
|
-
},
|
|
233
|
-
displayOptions: {
|
|
234
|
-
show: {
|
|
235
|
-
promptType: ['define'],
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
displayName: 'Require Specific Output Format',
|
|
241
|
-
name: 'hasOutputParser',
|
|
242
|
-
type: 'boolean',
|
|
243
|
-
default: false,
|
|
244
|
-
noDataExpression: true,
|
|
245
|
-
displayOptions: {
|
|
246
|
-
hide: {
|
|
247
|
-
'@version': [1, 1.1, 1.3],
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
displayName: 'Chat Messages (if Using a Chat Model)',
|
|
253
|
-
name: 'messages',
|
|
254
|
-
type: 'fixedCollection',
|
|
255
|
-
typeOptions: {
|
|
256
|
-
multipleValues: true,
|
|
257
|
-
},
|
|
258
|
-
default: {},
|
|
259
|
-
placeholder: 'Add prompt',
|
|
260
|
-
options: [
|
|
261
|
-
{
|
|
262
|
-
name: 'messageValues',
|
|
263
|
-
displayName: 'Prompt',
|
|
264
|
-
values: [
|
|
265
|
-
{
|
|
266
|
-
displayName: 'Type Name or ID',
|
|
267
|
-
name: 'type',
|
|
268
|
-
type: 'options',
|
|
269
|
-
options: [
|
|
270
|
-
{
|
|
271
|
-
name: 'AI',
|
|
272
|
-
value: prompts_1.AIMessagePromptTemplate.lc_name(),
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
name: 'System',
|
|
276
|
-
value: prompts_1.SystemMessagePromptTemplate.lc_name(),
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
name: 'User',
|
|
280
|
-
value: prompts_1.HumanMessagePromptTemplate.lc_name(),
|
|
281
|
-
},
|
|
282
|
-
],
|
|
283
|
-
default: prompts_1.SystemMessagePromptTemplate.lc_name(),
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
displayName: 'Message Type',
|
|
287
|
-
name: 'messageType',
|
|
288
|
-
type: 'options',
|
|
289
|
-
displayOptions: {
|
|
290
|
-
show: {
|
|
291
|
-
type: [prompts_1.HumanMessagePromptTemplate.lc_name()],
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
options: [
|
|
295
|
-
{
|
|
296
|
-
name: 'Text',
|
|
297
|
-
value: 'text',
|
|
298
|
-
description: 'Simple text message',
|
|
299
|
-
},
|
|
300
|
-
{
|
|
301
|
-
name: 'Image (Binary)',
|
|
302
|
-
value: 'imageBinary',
|
|
303
|
-
description: 'Process the binary input from the previous node',
|
|
304
|
-
},
|
|
305
|
-
{
|
|
306
|
-
name: 'Image (URL)',
|
|
307
|
-
value: 'imageUrl',
|
|
308
|
-
description: 'Process the image from the specified URL',
|
|
309
|
-
},
|
|
310
|
-
],
|
|
311
|
-
default: 'text',
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
displayName: 'Image Data Field Name',
|
|
315
|
-
name: 'binaryImageDataKey',
|
|
316
|
-
type: 'string',
|
|
317
|
-
default: 'data',
|
|
318
|
-
required: true,
|
|
319
|
-
description: 'The name of the field in the chain’s input that contains the binary image file to be processed',
|
|
320
|
-
displayOptions: {
|
|
321
|
-
show: {
|
|
322
|
-
messageType: ['imageBinary'],
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
displayName: 'Image URL',
|
|
328
|
-
name: 'imageUrl',
|
|
329
|
-
type: 'string',
|
|
330
|
-
default: '',
|
|
331
|
-
required: true,
|
|
332
|
-
description: 'URL to the image to be processed',
|
|
333
|
-
displayOptions: {
|
|
334
|
-
show: {
|
|
335
|
-
messageType: ['imageUrl'],
|
|
336
|
-
},
|
|
337
|
-
},
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
displayName: 'Image Details',
|
|
341
|
-
description: 'Control how the model processes the image and generates its textual understanding',
|
|
342
|
-
name: 'imageDetail',
|
|
343
|
-
type: 'options',
|
|
344
|
-
displayOptions: {
|
|
345
|
-
show: {
|
|
346
|
-
type: [prompts_1.HumanMessagePromptTemplate.lc_name()],
|
|
347
|
-
messageType: ['imageBinary', 'imageUrl'],
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
options: [
|
|
351
|
-
{
|
|
352
|
-
name: 'Auto',
|
|
353
|
-
value: 'auto',
|
|
354
|
-
description: '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',
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
name: 'Low',
|
|
358
|
-
value: 'low',
|
|
359
|
-
description: '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.',
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
name: 'High',
|
|
363
|
-
value: 'high',
|
|
364
|
-
description: '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.',
|
|
365
|
-
},
|
|
366
|
-
],
|
|
367
|
-
default: 'auto',
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
displayName: 'Message',
|
|
371
|
-
name: 'message',
|
|
372
|
-
type: 'string',
|
|
373
|
-
required: true,
|
|
374
|
-
displayOptions: {
|
|
375
|
-
hide: {
|
|
376
|
-
messageType: ['imageBinary', 'imageUrl'],
|
|
377
|
-
},
|
|
378
|
-
},
|
|
379
|
-
default: '',
|
|
380
|
-
},
|
|
381
|
-
],
|
|
382
|
-
},
|
|
383
|
-
],
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
displayName: `Connect an <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='${"ai_outputParser"}'>output parser</a> on the canvas to specify the output format you require`,
|
|
387
|
-
name: 'notice',
|
|
388
|
-
type: 'notice',
|
|
389
|
-
default: '',
|
|
390
|
-
displayOptions: {
|
|
391
|
-
show: {
|
|
392
|
-
hasOutputParser: [true],
|
|
393
|
-
},
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
],
|
|
40
|
+
properties: methods_1.nodeProperties,
|
|
397
41
|
};
|
|
398
42
|
}
|
|
399
43
|
async execute() {
|
|
400
|
-
this.logger.debug('Executing LLM Chain');
|
|
44
|
+
this.logger.debug('Executing Basic LLM Chain');
|
|
401
45
|
const items = this.getInputData();
|
|
402
46
|
const returnData = [];
|
|
403
47
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
|
404
48
|
try {
|
|
405
|
-
let prompt;
|
|
406
49
|
const llm = (await this.getInputConnectionData("ai_languageModel", 0));
|
|
407
|
-
const
|
|
50
|
+
const outputParser = await (0, N8nOutputParser_1.getOptionalOutputParser)(this);
|
|
51
|
+
let prompt;
|
|
408
52
|
if (this.getNode().typeVersion <= 1.3) {
|
|
409
53
|
prompt = this.getNodeParameter('prompt', itemIndex);
|
|
410
54
|
}
|
|
@@ -416,37 +60,21 @@ class ChainLlm {
|
|
|
416
60
|
promptTypeKey: 'promptType',
|
|
417
61
|
});
|
|
418
62
|
}
|
|
419
|
-
const messages = this.getNodeParameter('messages.messageValues', itemIndex, []);
|
|
420
63
|
if (prompt === undefined) {
|
|
421
64
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "The 'prompt' parameter is empty.");
|
|
422
65
|
}
|
|
423
|
-
const
|
|
66
|
+
const messages = this.getNodeParameter('messages.messageValues', itemIndex, []);
|
|
67
|
+
const responses = await (0, methods_1.executeChain)({
|
|
68
|
+
context: this,
|
|
69
|
+
itemIndex,
|
|
70
|
+
query: prompt,
|
|
71
|
+
llm,
|
|
72
|
+
outputParser,
|
|
73
|
+
messages,
|
|
74
|
+
});
|
|
424
75
|
responses.forEach((response) => {
|
|
425
|
-
let data;
|
|
426
|
-
if (typeof response === 'string') {
|
|
427
|
-
data = {
|
|
428
|
-
response: {
|
|
429
|
-
text: response.trim(),
|
|
430
|
-
},
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
else if (Array.isArray(response)) {
|
|
434
|
-
data = {
|
|
435
|
-
data: response,
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
else if (response instanceof Object) {
|
|
439
|
-
data = response;
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
data = {
|
|
443
|
-
response: {
|
|
444
|
-
text: response,
|
|
445
|
-
},
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
76
|
returnData.push({
|
|
449
|
-
json:
|
|
77
|
+
json: (0, methods_1.formatResponse)(response, this.getNode().typeVersion),
|
|
450
78
|
});
|
|
451
79
|
});
|
|
452
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChainLlm.node.js","sourceRoot":"","sources":["../../../../nodes/chains/ChainLLM/ChainLlm.node.ts"],"names":[],"mappings":";;;AAEA,uDAAwD;AACxD,qDAMiC;AACjC,0DAAiE;AACjE,8CAA+C;AAC/C,6CAA4C;AAC5C,6DAAiE;AASjE,+CAKsB;AAEtB,sDAA8E;AAC9E,4CAAsE;AAEtE,2EAAiF;AACjF,sDAA6D;AAC7D,4CAAkD;AAElD,mCAAyE;AACzE,gFAGqD;AAWrD,KAAK,UAAU,eAAe,CAC7B,OAA0B,EAC1B,SAAiB,EACjB,OAAyB;IAEzB,IAAI,OAAO,CAAC,WAAW,KA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,CAAC,CAAC;gBAGH,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;oBAC9B,UAAU,CAAC,IAAI,CAAC;wBACf,IAAI,EAAE,IAAA,wBAAc,EAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC;qBAC1D,CAAC,CAAC;gBACJ,CAAC,CAAC,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAEhB,IAAI,KAAK,YAAY,2BAAY,IAAI,IAAA,8BAAa,EAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;oBACjE,MAAM,eAAe,GAAwB,KAAK,CAAC,KAAa,CAAC,KAAK,EAAE,IAAI,CAAC;oBAC7E,IAAI,eAAe,EAAE,CAAC;wBACrB,MAAM,aAAa,GAAG,IAAA,sCAA2B,EAAC,eAAe,CAAC,CAAC;wBACnE,IAAI,aAAa,EAAE,CAAC;4BACnB,KAAK,CAAC,OAAO,GAAG,aAAa,CAAC;wBAC/B,CAAC;oBACF,CAAC;gBACF,CAAC;gBAGD,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;oBAC3B,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;oBACrF,SAAS;gBACV,CAAC;gBAED,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;QAED,OAAO,CAAC,UAAU,CAAC,CAAC;IACrB,CAAC;CACD;AAvHD,4BAuHC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
2
|
+
import type { BaseLLMOutputParser } from '@langchain/core/output_parsers';
|
|
3
|
+
import type { ChainExecutionParams } from './types';
|
|
4
|
+
export declare function isModelWithResponseFormat(llm: BaseLanguageModel): llm is BaseLanguageModel & {
|
|
5
|
+
modelKwargs: {
|
|
6
|
+
response_format: {
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare function isModelWithFormat(llm: BaseLanguageModel): llm is BaseLanguageModel & {
|
|
12
|
+
format: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function getOutputParserForLLM(llm: BaseLanguageModel): BaseLLMOutputParser<string | Record<string, unknown>>;
|
|
15
|
+
export declare function executeChain({ context, itemIndex, query, llm, outputParser, messages, }: ChainExecutionParams): Promise<unknown[]>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isModelWithResponseFormat = isModelWithResponseFormat;
|
|
4
|
+
exports.isModelWithFormat = isModelWithFormat;
|
|
5
|
+
exports.getOutputParserForLLM = getOutputParserForLLM;
|
|
6
|
+
exports.executeChain = executeChain;
|
|
7
|
+
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
8
|
+
const tracing_1 = require("../../../../utils/tracing");
|
|
9
|
+
const promptUtils_1 = require("./promptUtils");
|
|
10
|
+
function isModelWithResponseFormat(llm) {
|
|
11
|
+
return ('modelKwargs' in llm &&
|
|
12
|
+
!!llm.modelKwargs &&
|
|
13
|
+
typeof llm.modelKwargs === 'object' &&
|
|
14
|
+
'response_format' in llm.modelKwargs);
|
|
15
|
+
}
|
|
16
|
+
function isModelWithFormat(llm) {
|
|
17
|
+
return 'format' in llm && typeof llm.format !== 'undefined';
|
|
18
|
+
}
|
|
19
|
+
function getOutputParserForLLM(llm) {
|
|
20
|
+
if (isModelWithResponseFormat(llm) && llm.modelKwargs?.response_format?.type === 'json_object') {
|
|
21
|
+
return new output_parsers_1.JsonOutputParser();
|
|
22
|
+
}
|
|
23
|
+
if (isModelWithFormat(llm) && llm.format === 'json') {
|
|
24
|
+
return new output_parsers_1.JsonOutputParser();
|
|
25
|
+
}
|
|
26
|
+
return new output_parsers_1.StringOutputParser();
|
|
27
|
+
}
|
|
28
|
+
async function executeSimpleChain({ context, llm, query, prompt, }) {
|
|
29
|
+
const outputParser = getOutputParserForLLM(llm);
|
|
30
|
+
const chain = prompt.pipe(llm).pipe(outputParser).withConfig((0, tracing_1.getTracingConfig)(context));
|
|
31
|
+
const response = await chain.invoke({
|
|
32
|
+
query,
|
|
33
|
+
signal: context.getExecutionCancelSignal(),
|
|
34
|
+
});
|
|
35
|
+
return [response];
|
|
36
|
+
}
|
|
37
|
+
async function executeChain({ context, itemIndex, query, llm, outputParser, messages, }) {
|
|
38
|
+
if (!outputParser) {
|
|
39
|
+
const promptTemplate = await (0, promptUtils_1.createPromptTemplate)({
|
|
40
|
+
context,
|
|
41
|
+
itemIndex,
|
|
42
|
+
llm,
|
|
43
|
+
messages,
|
|
44
|
+
query,
|
|
45
|
+
});
|
|
46
|
+
return await executeSimpleChain({
|
|
47
|
+
context,
|
|
48
|
+
llm,
|
|
49
|
+
query,
|
|
50
|
+
prompt: promptTemplate,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const formatInstructions = outputParser.getFormatInstructions();
|
|
54
|
+
const promptWithInstructions = await (0, promptUtils_1.createPromptTemplate)({
|
|
55
|
+
context,
|
|
56
|
+
itemIndex,
|
|
57
|
+
llm,
|
|
58
|
+
messages,
|
|
59
|
+
formatInstructions,
|
|
60
|
+
query,
|
|
61
|
+
});
|
|
62
|
+
const chain = promptWithInstructions
|
|
63
|
+
.pipe(llm)
|
|
64
|
+
.pipe(outputParser)
|
|
65
|
+
.withConfig((0, tracing_1.getTracingConfig)(context));
|
|
66
|
+
const response = await chain.invoke({ query }, { signal: context.getExecutionCancelSignal() });
|
|
67
|
+
return Array.isArray(response) ? response : [response];
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=chainExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chainExecutor.js","sourceRoot":"","sources":["../../../../../nodes/chains/Ch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|
3
|
+
export declare function getInputs(parameters: IDataObject): ({
|
|
4
|
+
displayName: string;
|
|
5
|
+
type: NodeConnectionType;
|
|
6
|
+
maxConnections?: undefined;
|
|
7
|
+
required?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
displayName: string;
|
|
10
|
+
maxConnections: number;
|
|
11
|
+
type: NodeConnectionType;
|
|
12
|
+
required: boolean;
|
|
13
|
+
})[];
|
|
14
|
+
export declare const nodeProperties: INodeProperties[];
|