PromptTemplate constructor

const PromptTemplate({
  1. required Set<String> inputVariables,
  2. PartialValues? partialVariables,
  3. 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:

final promptTemplate = PromptTemplate.fromTemplate(
  'What is a good name for a company that makes {product}?',
);

Implementation

const PromptTemplate({
  required super.inputVariables,
  super.partialVariables,
  required this.template,
});