mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 05:01:10 +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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class FewShotPromptTemplate_Prompts implements INode {
|
||||
label: 'Examples',
|
||||
name: 'examples',
|
||||
type: 'string',
|
||||
rows: 5,
|
||||
rows: 4,
|
||||
placeholder: `[
|
||||
{ "word": "happy", "antonym": "sad" },
|
||||
{ "word": "tall", "antonym": "short" },
|
||||
@@ -42,14 +42,14 @@ class FewShotPromptTemplate_Prompts implements INode {
|
||||
label: 'Prefix',
|
||||
name: 'prefix',
|
||||
type: 'string',
|
||||
rows: 3,
|
||||
rows: 4,
|
||||
placeholder: `Give the antonym of every input`
|
||||
},
|
||||
{
|
||||
label: 'Suffix',
|
||||
name: 'suffix',
|
||||
type: 'string',
|
||||
rows: 3,
|
||||
rows: 4,
|
||||
placeholder: `Word: {input}\nAntonym:`
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { ICommonObject, INode, INodeData, INodeParams, PromptTemplate } from '../../../src/Interface'
|
||||
import { getBaseClasses, getInputVariables } from '../../../src/utils'
|
||||
import { PromptTemplate, PromptTemplateInput } from 'langchain/prompts'
|
||||
import { PromptTemplateInput } from 'langchain/prompts'
|
||||
|
||||
class PromptTemplate_Prompts implements INode {
|
||||
label: string
|
||||
@@ -19,20 +19,40 @@ class PromptTemplate_Prompts implements INode {
|
||||
this.icon = 'prompt.svg'
|
||||
this.category = 'Prompts'
|
||||
this.description = 'Schema to represent a basic prompt for an LLM'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(PromptTemplate)]
|
||||
this.baseClasses = [...getBaseClasses(PromptTemplate)]
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Template',
|
||||
name: 'template',
|
||||
type: 'string',
|
||||
rows: 5,
|
||||
rows: 4,
|
||||
placeholder: `What is a good name for a company that makes {product}?`
|
||||
},
|
||||
{
|
||||
label: 'Format Prompt Values',
|
||||
name: 'promptValues',
|
||||
type: 'string',
|
||||
rows: 4,
|
||||
placeholder: `{
|
||||
"input_language": "English",
|
||||
"output_language": "French"
|
||||
}`,
|
||||
optional: true,
|
||||
acceptVariable: true,
|
||||
list: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const template = nodeData.inputs?.template as string
|
||||
const promptValuesStr = nodeData.inputs?.promptValues as string
|
||||
|
||||
let promptValues: ICommonObject = {}
|
||||
if (promptValuesStr) {
|
||||
promptValues = JSON.parse(promptValuesStr.replace(/\s/g, ''))
|
||||
}
|
||||
|
||||
const inputVariables = getInputVariables(template)
|
||||
|
||||
try {
|
||||
@@ -41,6 +61,7 @@ class PromptTemplate_Prompts implements INode {
|
||||
inputVariables
|
||||
}
|
||||
const prompt = new PromptTemplate(options)
|
||||
prompt.promptValues = promptValues
|
||||
return prompt
|
||||
} catch (e) {
|
||||
throw new Error(e)
|
||||
|
||||
Reference in New Issue
Block a user