fix: Continue on fail / error output support for chains and agents (#9078)

This commit is contained in:
Michael Kret 2024-04-09 15:06:12 +03:00 committed by GitHub
parent 8c2622549b
commit f62800cd72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 469 additions and 388 deletions

View file

@ -79,6 +79,7 @@ export async function conversationalAgentExecute(
const items = this.getInputData(); const items = this.getInputData();
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
let input; let input;
if (this.getNode().typeVersion <= 1.2) { if (this.getNode().typeVersion <= 1.2) {
@ -109,6 +110,14 @@ export async function conversationalAgentExecute(
} }
returnData.push({ json: response }); returnData.push({ json: response });
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
continue;
}
throw error;
}
} }
return await this.prepareOutputData(returnData); return await this.prepareOutputData(returnData);

View file

@ -85,6 +85,7 @@ export async function openAiFunctionsAgentExecute(
const items = this.getInputData(); const items = this.getInputData();
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
let input; let input;
if (this.getNode().typeVersion <= 1.2) { if (this.getNode().typeVersion <= 1.2) {
input = this.getNodeParameter('text', itemIndex) as string; input = this.getNodeParameter('text', itemIndex) as string;
@ -114,6 +115,14 @@ export async function openAiFunctionsAgentExecute(
} }
returnData.push({ json: response }); returnData.push({ json: response });
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
continue;
}
throw error;
}
} }
return await this.prepareOutputData(returnData); return await this.prepareOutputData(returnData);

View file

@ -60,6 +60,7 @@ export async function planAndExecuteAgentExecute(
const items = this.getInputData(); const items = this.getInputData();
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
let input; let input;
if (this.getNode().typeVersion <= 1.2) { if (this.getNode().typeVersion <= 1.2) {
input = this.getNodeParameter('text', itemIndex) as string; input = this.getNodeParameter('text', itemIndex) as string;
@ -89,6 +90,14 @@ export async function planAndExecuteAgentExecute(
} }
returnData.push({ json: response }); returnData.push({ json: response });
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
continue;
}
throw error;
}
} }
return await this.prepareOutputData(returnData); return await this.prepareOutputData(returnData);

View file

@ -80,6 +80,7 @@ export async function reActAgentAgentExecute(
const items = this.getInputData(); const items = this.getInputData();
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
let input; let input;
if (this.getNode().typeVersion <= 1.2) { if (this.getNode().typeVersion <= 1.2) {
@ -110,6 +111,14 @@ export async function reActAgentAgentExecute(
} }
returnData.push({ json: response }); returnData.push({ json: response });
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
continue;
}
throw error;
}
} }
return await this.prepareOutputData(returnData); return await this.prepareOutputData(returnData);

View file

@ -41,6 +41,7 @@ export async function sqlAgentAgentExecute(
const returnData: INodeExecutionData[] = []; const returnData: INodeExecutionData[] = [];
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
try {
const item = items[i]; const item = items[i];
let input; let input;
if (this.getNode().typeVersion <= 1.2) { if (this.getNode().typeVersion <= 1.2) {
@ -141,6 +142,14 @@ export async function sqlAgentAgentExecute(
} }
returnData.push({ json: response }); returnData.push({ json: response });
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: i } });
continue;
}
throw error;
}
} }
return await this.prepareOutputData(returnData); return await this.prepareOutputData(returnData);

View file

@ -320,6 +320,7 @@ export class OpenAiAssistant implements INodeType {
const returnData: INodeExecutionData[] = []; const returnData: INodeExecutionData[] = [];
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
const input = this.getNodeParameter('text', itemIndex) as string; const input = this.getNodeParameter('text', itemIndex) as string;
const assistantId = this.getNodeParameter('assistantId', itemIndex, '') as string; const assistantId = this.getNodeParameter('assistantId', itemIndex, '') as string;
const nativeTools = this.getNodeParameter('nativeTools', itemIndex, []) as Array< const nativeTools = this.getNodeParameter('nativeTools', itemIndex, []) as Array<
@ -381,6 +382,14 @@ export class OpenAiAssistant implements INodeType {
}); });
returnData.push({ json: response }); returnData.push({ json: response });
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
continue;
}
throw error;
}
} }
return await this.prepareOutputData(returnData); return await this.prepareOutputData(returnData);

View file

@ -519,6 +519,7 @@ export class ChainLlm implements INodeType {
const outputParsers = await getOptionalOutputParsers(this); const outputParsers = await getOptionalOutputParsers(this);
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
let prompt: string; let prompt: string;
if (this.getNode().typeVersion <= 1.3) { if (this.getNode().typeVersion <= 1.3) {
prompt = this.getNodeParameter('prompt', itemIndex) as string; prompt = this.getNodeParameter('prompt', itemIndex) as string;
@ -537,7 +538,7 @@ export class ChainLlm implements INodeType {
) as MessagesTemplate[]; ) as MessagesTemplate[];
if (prompt === undefined) { if (prompt === undefined) {
throw new NodeOperationError(this.getNode(), 'The prompt parameter is empty.'); throw new NodeOperationError(this.getNode(), "The 'prompt' parameter is empty.");
} }
const responses = await getChain(this, itemIndex, prompt, llm, outputParsers, messages); const responses = await getChain(this, itemIndex, prompt, llm, outputParsers, messages);
@ -568,6 +569,14 @@ export class ChainLlm implements INodeType {
json: data, json: data,
}); });
}); });
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
continue;
}
throw error;
}
} }
return [returnData]; return [returnData];

View file

@ -160,6 +160,7 @@ export class ChainRetrievalQa implements INodeType {
// Run for each item // Run for each item
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
let query; let query;
if (this.getNode().typeVersion <= 1.2) { if (this.getNode().typeVersion <= 1.2) {
@ -179,6 +180,14 @@ export class ChainRetrievalQa implements INodeType {
const response = await chain.withConfig(getTracingConfig(this)).invoke({ query }); const response = await chain.withConfig(getTracingConfig(this)).invoke({ query });
returnData.push({ json: { response } }); returnData.push({ json: { response } });
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
continue;
}
throw error;
}
} }
return await this.prepareOutputData(returnData); return await this.prepareOutputData(returnData);
} }

View file

@ -329,6 +329,7 @@ export class ChainSummarizationV2 implements INodeType {
const returnData: INodeExecutionData[] = []; const returnData: INodeExecutionData[] = [];
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
const summarizationMethodAndPrompts = this.getNodeParameter( const summarizationMethodAndPrompts = this.getNodeParameter(
'options.summarizationMethodAndPrompts.values', 'options.summarizationMethodAndPrompts.values',
itemIndex, itemIndex,
@ -414,6 +415,14 @@ export class ChainSummarizationV2 implements INodeType {
}); });
returnData.push({ json: { response } }); returnData.push({ json: { response } });
} }
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
continue;
}
throw error;
}
} }
return await this.prepareOutputData(returnData); return await this.prepareOutputData(returnData);