PromptTemplate constructor
const
PromptTemplate({
- required Set<
String> inputVariables, - PartialValues? partialVariables,
- required String template,
A prompt template for a language model.
A prompt template consists of a string template. It accepts a set of parameters from the user that can be used to generate a prompt for a language model.
Example:
final promptTemplate = PromptTemplate(
inputVariables: ['product'],
template: 'What is a good name for a company that makes {product}?',
);
final prompt = promptTemplate.formatPrompt({'product': 'colorful socks'});
final res = await llm.invoke(prompt);
Note: the default constructor does not validate the template. You can use PromptTemplate.validateTemplate to validate the template.
You can also use the following convenience factory constructors to create a prompt template:
- PromptTemplate.fromTemplate creates a prompt template from a string template automatically extracting the input variables.
final promptTemplate = PromptTemplate.fromTemplate(
'What is a good name for a company that makes {product}?',
);
- PromptTemplate.fromExamples to create prompt templates from a list of examples.
- PromptTemplate.fromFile to create a prompt template from a file.
Implementation
const PromptTemplate({
required super.inputVariables,
super.partialVariables,
required this.template,
});