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.
exampleslist of examples to use in the prompt.suffixstring to go after the list of examples. Should generally set up the user's input.inputVariableslist list of variable names the final prompt template will expect.exampleSeparatorthe separator to use in between examples.prefixstring that should go before any examples. Generally includes examples.validateTemplatewhether 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;
}