feat(Structured Output Parser Node): Refactor Output Parsers and Improve Error Handling (#11148)

This commit is contained in:
oleg
2024-10-22 10:46:58 +02:00
committed by GitHub
parent 4dde772814
commit 45274f2e7f
20 changed files with 1061 additions and 383 deletions

View File

@@ -1,12 +1,12 @@
import { NodeConnectionType, NodeOperationError, jsonStringify } from 'n8n-workflow';
import type { AiEvent, IDataObject, IExecuteFunctions, IWebhookFunctions } from 'n8n-workflow';
import type { BaseChatMessageHistory } from '@langchain/core/chat_history';
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
import type { BaseOutputParser } from '@langchain/core/output_parsers';
import type { BaseLLM } from '@langchain/core/language_models/llms';
import type { BaseMessage } from '@langchain/core/messages';
import type { Tool } from '@langchain/core/tools';
import type { BaseLLM } from '@langchain/core/language_models/llms';
import type { BaseChatMemory } from 'langchain/memory';
import type { BaseChatMessageHistory } from '@langchain/core/chat_history';
import { NodeConnectionType, NodeOperationError, jsonStringify } from 'n8n-workflow';
import type { AiEvent, IDataObject, IExecuteFunctions, IWebhookFunctions } from 'n8n-workflow';
import { N8nTool } from './N8nTool';
function hasMethods<T>(obj: unknown, ...methodNames: Array<string | symbol>): obj is T {
@@ -66,21 +66,6 @@ export function isToolsInstance(model: unknown): model is Tool {
return namespace.includes('tools');
}
export async function getOptionalOutputParsers(
ctx: IExecuteFunctions,
): Promise<Array<BaseOutputParser<unknown>>> {
let outputParsers: BaseOutputParser[] = [];
if (ctx.getNodeParameter('hasOutputParser', 0, true) === true) {
outputParsers = (await ctx.getInputConnectionData(
NodeConnectionType.AiOutputParser,
0,
)) as BaseOutputParser[];
}
return outputParsers;
}
export function getPromptInputByType(options: {
ctx: IExecuteFunctions;
i: number;