PromptTemplate.fromExamples constructor
PromptTemplate.fromExamples({})
Take examples in list format with prefix and suffix to create a prompt.
Intended to be used a a way to dynamically create a prompt from examples.
examples
list of examples to use in the prompt.suffix
string to go after the list of examples. Should generally set up the user's input.inputVariables
list list of variable names the final prompt template will expect.exampleSeparator
the separator to use in between examples.prefix
string that should go before any examples. Generally includes examples.validateTemplate
whether to validate the template.
Implementation
factory PromptTemplate.fromExamples({
required final List<String> examples,
required final String suffix,
required final Set<String> inputVariables,
final String exampleSeparator = '\n\n',
final String prefix = '',
final bool validateTemplate = true,
}) {
final template = [prefix, ...examples, suffix].join(exampleSeparator);
final t = PromptTemplate(
inputVariables: inputVariables,
template: template,
);
if (validateTemplate) {
t.validateTemplate();
}
return t;
}