mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
add format prompt values to prompt template
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses } from '../../../src/utils'
|
||||
import { ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate } from 'langchain/prompts'
|
||||
|
||||
@@ -25,15 +25,28 @@ class ChatPromptTemplate_Prompts implements INode {
|
||||
label: 'System Message',
|
||||
name: 'systemMessagePrompt',
|
||||
type: 'string',
|
||||
rows: 3,
|
||||
rows: 4,
|
||||
placeholder: `You are a helpful assistant that translates {input_language} to {output_language}.`
|
||||
},
|
||||
{
|
||||
label: 'Human Message',
|
||||
name: 'humanMessagePrompt',
|
||||
type: 'string',
|
||||
rows: 3,
|
||||
rows: 4,
|
||||
placeholder: `{text}`
|
||||
},
|
||||
{
|
||||
label: 'Format Prompt Values',
|
||||
name: 'promptValues',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
placeholder: `{
|
||||
"input_language": "English",
|
||||
"output_language": "French"
|
||||
}`,
|
||||
optional: true,
|
||||
acceptVariable: true,
|
||||
list: true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -41,11 +54,20 @@ class ChatPromptTemplate_Prompts implements INode {
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const systemMessagePrompt = nodeData.inputs?.systemMessagePrompt as string
|
||||
const humanMessagePrompt = nodeData.inputs?.humanMessagePrompt as string
|
||||
const promptValuesStr = nodeData.inputs?.promptValues as string
|
||||
|
||||
const prompt = ChatPromptTemplate.fromPromptMessages([
|
||||
SystemMessagePromptTemplate.fromTemplate(systemMessagePrompt),
|
||||
HumanMessagePromptTemplate.fromTemplate(humanMessagePrompt)
|
||||
])
|
||||
|
||||
let promptValues: ICommonObject = {}
|
||||
if (promptValuesStr) {
|
||||
promptValues = JSON.parse(promptValuesStr.replace(/\s/g, ''))
|
||||
}
|
||||
// @ts-ignore
|
||||
prompt.promptValues = promptValues
|
||||
|
||||
return prompt
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user