PipelinePromptTemplate class final
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);
- Inheritance
-
- Object
- Runnable<
InputValues, BaseLangChainOptions, PromptValue> - BasePromptTemplate
- PipelinePromptTemplate
Constructors
-
PipelinePromptTemplate({required BasePromptTemplate finalPrompt, required List<
(String, BasePromptTemplate)> pipelinePrompts}) - A prompt template for composing multiple prompts together.
Properties
- defaultOptions → BaseLangChainOptions
-
The default options to use when invoking the Runnable.
finalinherited
- finalPrompt → BasePromptTemplate
-
The final prompt that is returned.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
inputVariables
→ Set<
String> -
A set of the names of the variables the prompt template expects.
finalinherited
- partialVariables → PartialValues?
-
Partial variables.
finalinherited
-
pipelinePrompts
→ List<
(String, BasePromptTemplate)> -
Tuples of the name of the variable and the prompt template in the
pipeline.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- type → String
-
The type of the prompt template.
no setteroverride
Methods
-
batch(
List< InputValues> inputs, {List<BaseLangChainOptions> ? options}) → Future<List< PromptValue> > -
Batches the invocation of the Runnable on the given
inputs
.inherited -
bind(
BaseLangChainOptions options) → RunnableBinding< InputValues, BaseLangChainOptions, PromptValue> -
Binds the Runnable to the given
options
.inherited -
close(
) → void -
Cleans up any resources associated with it the Runnable.
inherited
-
copyWith(
{BasePromptTemplate? finalPrompt, List< (String, BasePromptTemplate)> ? pipelinePrompts, Set<String> ? inputVariables, Map<String, dynamic> ? partialVariables}) → PipelinePromptTemplate -
Copy the prompt template with the given parameters.
override
-
format(
InputValues values) → String -
Format the prompt given the input values and return a formatted string.
override
-
formatPrompt(
InputValues values) → PromptValue -
Format the prompt given the input values and return a formatted prompt
value.
override
-
getCompatibleOptions(
RunnableOptions? options) → BaseLangChainOptions? -
Returns the given
options
if they are compatible with the Runnable, otherwise returnsnull
.inherited -
invoke(
InputValues input, {BaseLangChainOptions? options}) → Future< PromptValue> -
Format the prompt given the input values and return a formatted prompt
value.
inherited
-
mergePartialAndUserVariables(
Map< String, dynamic> userVariables) → Map<String, Object> -
Merge the partial variables with the user variables.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
partial(
PartialValues values) → BasePromptTemplate -
Return a partial of the prompt template.
inherited
-
pipe<
NewRunOutput extends Object?, NewCallOptions extends RunnableOptions> (Runnable< PromptValue, NewCallOptions, NewRunOutput> next) → RunnableSequence<InputValues, NewRunOutput> -
Pipes the output of this Runnable into another Runnable using a
RunnableSequence.
inherited
-
stream(
InputValues input, {BaseLangChainOptions? options}) → Stream< PromptValue> -
Streams the output of invoking the Runnable on the given
input
.inherited -
streamFromInputStream(
Stream< InputValues> inputStream, {BaseLangChainOptions? options}) → Stream<PromptValue> -
Streams the output of invoking the Runnable on the given
inputStream
.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
validateTemplate(
) → void -
Validate the integrity of the prompt template, checking that all the
variables are present and that the right format is used.
inherited
-
withFallbacks(
List< Runnable< fallbacks) → RunnableWithFallback<InputValues, RunnableOptions, PromptValue> >InputValues, PromptValue> -
Adds fallback runnables to be invoked if the primary runnable fails.
inherited
-
withRetry(
{int maxRetries = 3, FutureOr< bool> retryIf(Object e)?, List<Duration?> ? delayDurations, bool addJitter = false}) → RunnableRetry<InputValues, PromptValue> -
Adds retry logic to an existing runnable.
inherited
Operators
-
operator ==(
covariant BasePromptTemplate other) → bool -
The equality operator.
inherited