mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
feat(Text Classifier Node): Add output fixing parser (#10667)
This commit is contained in:
parent
81540318b4
commit
aa37c32f26
|
@ -129,7 +129,8 @@ export class SentimentAnalysis implements INodeType {
|
|||
name: 'enableAutoFixing',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether to enable auto-fixing for the output parser',
|
||||
description:
|
||||
'Whether to enable auto-fixing (may trigger an additional LLM call if output is broken)',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
@ -12,7 +12,7 @@ import { NodeConnectionType } from 'n8n-workflow';
|
|||
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||
import { HumanMessage } from '@langchain/core/messages';
|
||||
import { SystemMessagePromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';
|
||||
import { StructuredOutputParser } from 'langchain/output_parsers';
|
||||
import { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers';
|
||||
import { z } from 'zod';
|
||||
import { getTracingConfig } from '../../../utils/tracing';
|
||||
|
||||
|
@ -151,6 +151,14 @@ export class TextClassifier implements INodeType {
|
|||
rows: 6,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Enable Auto-Fixing',
|
||||
name: 'enableAutoFixing',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether to enable auto-fixing (may trigger an additional LLM call if output is broken)',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -173,6 +181,7 @@ export class TextClassifier implements INodeType {
|
|||
multiClass: boolean;
|
||||
fallback?: string;
|
||||
systemPromptTemplate?: string;
|
||||
enableAutoFixing: boolean;
|
||||
};
|
||||
const multiClass = options?.multiClass ?? false;
|
||||
const fallback = options?.fallback ?? 'discard';
|
||||
|
@ -192,7 +201,11 @@ export class TextClassifier implements INodeType {
|
|||
]);
|
||||
const schema = z.object(Object.fromEntries(schemaEntries));
|
||||
|
||||
const parser = StructuredOutputParser.fromZodSchema(schema);
|
||||
const structuredParser = StructuredOutputParser.fromZodSchema(schema);
|
||||
|
||||
const parser = options.enableAutoFixing
|
||||
? OutputFixingParser.fromLLM(llm, structuredParser)
|
||||
: structuredParser;
|
||||
|
||||
const multiClassPrompt = multiClass
|
||||
? 'Categories are not mutually exclusive, and multiple can be true'
|
||||
|
|
Loading…
Reference in a new issue