add format prompt values to prompt template

This commit is contained in:
Henry
2023-04-18 23:27:05 +01:00
parent cd8a5b96eb
commit 17207e01db
13 changed files with 675 additions and 599 deletions
@@ -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)