PipelinePromptTemplate constructor
PipelinePromptTemplate({
- required BasePromptTemplate finalPrompt,
- required List<
(String, BasePromptTemplate)> pipelinePrompts,
A prompt template for composing multiple prompts together.
This can be useful when you want to reuse parts of prompts. A PipelinePromptTemplate consists of two main parts:
- finalPrompt This is the final prompt that is returned.
- pipelinePrompts This is a list of records, consisting of a string
(
name
) and a BasePromptTemplate. Each BasePromptTemplate will be formatted and then passed to future prompt templates as a variable with the same name asname
.
Example:
final promptA = PromptTemplate.fromTemplate('{foo}');
final promptB = PromptTemplate.fromTemplate('{bar}');
final pipelinePromptTemplate = PipelinePromptTemplate(
finalPrompt: promptB,
pipelinePrompts: [('bar', promptA)],
);
final prompt = pipelinePromptTemplate.formatPrompt({'foo': 'jim'});
final res = await llm.invoke(prompt);
Implementation
PipelinePromptTemplate({
required this.finalPrompt,
required this.pipelinePrompts,
}) : super(
inputVariables: _computeInputValues(finalPrompt, pipelinePrompts),
);