fix: Simplify Structured Output Parser wrapping and fix auto-fixing output parser (#8778)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
oleg
2024-03-01 08:41:45 +01:00
committed by GitHub
parent 08e2b068fb
commit 7d82dc1ea8
2 changed files with 49 additions and 27 deletions

View File

@@ -18,7 +18,7 @@ import { BaseChatMemory } from 'langchain/memory';
import type { MemoryVariables } from 'langchain/dist/memory/base';
import { BaseRetriever } from 'langchain/schema/retriever';
import type { FormatInstructionsOptions } from 'langchain/schema/output_parser';
import { BaseOutputParser } from 'langchain/schema/output_parser';
import { BaseOutputParser, OutputParserException } from 'langchain/schema/output_parser';
import { isObject } from 'lodash';
import { N8nJsonLoader } from './N8nJsonLoader';
import { N8nBinaryLoader } from './N8nBinaryLoader';
@@ -44,6 +44,10 @@ export async function callMethodAsync<T>(
try {
return await parameters.method.call(this, ...parameters.arguments);
} catch (e) {
// Langchain checks for OutputParserException to run retry chain
// for auto-fixing the output so skip wrapping in this case
if (e instanceof OutputParserException) throw e;
// Propagate errors from sub-nodes
if (e.functionality === 'configuration-node') throw e;
const connectedNode = parameters.executeFunctions.getNode();