mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Structured Output Parser Node): Refactor Output Parsers and Improve Error Handling (#11148)
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
||||
import { HumanMessage } from '@langchain/core/messages';
|
||||
import {
|
||||
ApplicationError,
|
||||
NodeApiError,
|
||||
NodeConnectionType,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
AIMessagePromptTemplate,
|
||||
PromptTemplate,
|
||||
SystemMessagePromptTemplate,
|
||||
HumanMessagePromptTemplate,
|
||||
ChatPromptTemplate,
|
||||
} from '@langchain/core/prompts';
|
||||
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
||||
import { ChatOllama } from '@langchain/ollama';
|
||||
import { LLMChain } from 'langchain/chains';
|
||||
import { CombiningOutputParser } from 'langchain/output_parsers';
|
||||
import type {
|
||||
IBinaryData,
|
||||
IDataObject,
|
||||
@@ -12,28 +20,17 @@ import type {
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
ApplicationError,
|
||||
NodeApiError,
|
||||
NodeConnectionType,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import {
|
||||
AIMessagePromptTemplate,
|
||||
PromptTemplate,
|
||||
SystemMessagePromptTemplate,
|
||||
HumanMessagePromptTemplate,
|
||||
ChatPromptTemplate,
|
||||
} from '@langchain/core/prompts';
|
||||
import type { BaseOutputParser } from '@langchain/core/output_parsers';
|
||||
import { CombiningOutputParser } from 'langchain/output_parsers';
|
||||
import { LLMChain } from 'langchain/chains';
|
||||
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
||||
import { HumanMessage } from '@langchain/core/messages';
|
||||
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
||||
import { ChatOllama } from '@langchain/ollama';
|
||||
import { getPromptInputByType, isChatInstance } from '../../../utils/helpers';
|
||||
import type { N8nOutputParser } from '../../../utils/output_parsers/N8nOutputParser';
|
||||
import { getOptionalOutputParsers } from '../../../utils/output_parsers/N8nOutputParser';
|
||||
import { getTemplateNoticeField } from '../../../utils/sharedFields';
|
||||
import {
|
||||
getOptionalOutputParsers,
|
||||
getPromptInputByType,
|
||||
isChatInstance,
|
||||
} from '../../../utils/helpers';
|
||||
import { getTracingConfig } from '../../../utils/tracing';
|
||||
import {
|
||||
getCustomErrorMessage as getCustomOpenAiErrorMessage,
|
||||
@@ -189,7 +186,7 @@ async function getChain(
|
||||
itemIndex: number,
|
||||
query: string,
|
||||
llm: BaseLanguageModel,
|
||||
outputParsers: BaseOutputParser[],
|
||||
outputParsers: N8nOutputParser[],
|
||||
messages?: MessagesTemplate[],
|
||||
): Promise<unknown[]> {
|
||||
const chatTemplate: ChatPromptTemplate | PromptTemplate = await getChainPromptTemplate(
|
||||
|
||||
Reference in New Issue
Block a user