mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
fix(Text Classifier Node): Default system prompt template (#11018)
This commit is contained in:
parent
3ff3e05e75
commit
77fec195d9
|
@ -1,3 +1,8 @@
|
||||||
|
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
||||||
|
import { HumanMessage } from '@langchain/core/messages';
|
||||||
|
import { SystemMessagePromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';
|
||||||
|
import { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers';
|
||||||
|
import { NodeOperationError, NodeConnectionType } from 'n8n-workflow';
|
||||||
import type {
|
import type {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
|
@ -6,14 +11,8 @@ import type {
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
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 { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers';
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { getTracingConfig } from '../../../utils/tracing';
|
import { getTracingConfig } from '../../../utils/tracing';
|
||||||
|
|
||||||
const SYSTEM_PROMPT_TEMPLATE =
|
const SYSTEM_PROMPT_TEMPLATE =
|
||||||
|
@ -172,11 +171,15 @@ export class TextClassifier implements INodeType {
|
||||||
0,
|
0,
|
||||||
)) as BaseLanguageModel;
|
)) as BaseLanguageModel;
|
||||||
|
|
||||||
const categories = this.getNodeParameter('categories.categories', 0) as Array<{
|
const categories = this.getNodeParameter('categories.categories', 0, []) as Array<{
|
||||||
category: string;
|
category: string;
|
||||||
description: string;
|
description: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
if (categories.length === 0) {
|
||||||
|
throw new NodeOperationError(this.getNode(), 'At least one category must be defined');
|
||||||
|
}
|
||||||
|
|
||||||
const options = this.getNodeParameter('options', 0, {}) as {
|
const options = this.getNodeParameter('options', 0, {}) as {
|
||||||
multiClass: boolean;
|
multiClass: boolean;
|
||||||
fallback?: string;
|
fallback?: string;
|
||||||
|
@ -229,6 +232,7 @@ export class TextClassifier implements INodeType {
|
||||||
const systemPromptTemplateOpt = this.getNodeParameter(
|
const systemPromptTemplateOpt = this.getNodeParameter(
|
||||||
'options.systemPromptTemplate',
|
'options.systemPromptTemplate',
|
||||||
itemIdx,
|
itemIdx,
|
||||||
|
SYSTEM_PROMPT_TEMPLATE,
|
||||||
) as string;
|
) as string;
|
||||||
const systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(
|
const systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(
|
||||||
`${systemPromptTemplateOpt ?? SYSTEM_PROMPT_TEMPLATE}
|
`${systemPromptTemplateOpt ?? SYSTEM_PROMPT_TEMPLATE}
|
||||||
|
|
Loading…
Reference in a new issue