Flowise/packages/components/nodes/prompts/PromptTemplate/PromptTemplate.ts

52 lines
1.5 KiB
TypeScript

import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getInputVariables } from '../../../src/utils'
import { PromptTemplate, PromptTemplateInput } from 'langchain/prompts'
class PromptTemplate_Prompts implements INode {
label: string
name: string
description: string
type: string
icon: string
category: string
baseClasses: string[]
inputs: INodeParams[]
constructor() {
this.label = 'Prompt Template'
this.name = 'promptTemplate'
this.type = 'PromptTemplate'
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.inputs = [
{
label: 'Template',
name: 'template',
type: 'string',
rows: 5,
placeholder: `What is a good name for a company that makes {product}?`
}
]
}
async init(nodeData: INodeData): Promise<any> {
const template = nodeData.inputs?.template as string
const inputVariables = getInputVariables(template)
try {
const options: PromptTemplateInput = {
template,
inputVariables
}
const prompt = new PromptTemplate(options)
return prompt
} catch (e) {
throw new Error(e)
}
}
}
module.exports = { nodeClass: PromptTemplate_Prompts }