MessagesPlaceholder class final
Prompt template that assumes the variable is a list of ChatMessage (ChatMessageType.messagesPlaceholder).
This is useful for when you want to use a list of messages in the prompt. For example, after retrieving them from memory.
If you need to add a single message, use MessagePlaceholder.
Example:
ChatPromptTemplate.fromPromptMessages([
ChatMessagePromptTemplate.system('You are a helpful AI assistant'),
ChatMessagePromptTemplate.messagesPlaceholder('history'),
ChatMessagePromptTemplate.messagePlaceholder('input'),
]);
Alternatively, you can use ChatPromptTemplate.fromTemplates to achieve the same result.
final promptTemplate = ChatPromptTemplate.fromTemplates([
(ChatMessageType.system, 'You are a helpful AI assistant'),
(ChatMessageType.messagesPlaceholder, 'history'),
(ChatMessageType.messagePlaceholder, 'input'),
]);
- Inheritance
-
- Object
- Runnable<
InputValues, BaseLangChainOptions, List< ChatMessage> > - ChatMessagePromptTemplate
- MessagesPlaceholder
- Annotations
-
- @immutable
Constructors
- MessagesPlaceholder({required String variableName})
-
Prompt template that assumes the variable is a list of ChatMessage (ChatMessageType.messagesPlaceholder).
const
Properties
- defaultOptions → BaseLangChainOptions
-
The default options to use when invoking the Runnable.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
inputVariables
→ Set<
String> -
Input variables of all the messages in the prompt template.
no setteroverride
- partialVariables → PartialValues?
-
Partial variables.
no setteroverride
- prompt → BasePromptTemplate
-
The prompt template for the message.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- variableName → String
-
The name of the placeholder variable.
final
Methods
-
batch(
List< InputValues> inputs, {List<BaseLangChainOptions> ? options}) → Future<List< List< >ChatMessage> > -
Batches the invocation of the Runnable on the given
inputs
.inherited -
bind(
BaseLangChainOptions options) → RunnableBinding< InputValues, BaseLangChainOptions, List< ChatMessage> > -
Binds the Runnable to the given
options
.inherited -
close(
) → void -
Cleans up any resources associated with it the Runnable.
inherited
-
copyWith(
{BasePromptTemplate? prompt, String? variableName}) → ChatMessagePromptTemplate -
Return a new ChatMessagePromptTemplate instance with the given
values.
override
-
formatMessages(
[Map< String, dynamic> values = const {}]) → List<ChatMessage> -
Format the prompt with the inputs returning a list of messages.
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< List< ChatMessage> > -
Format the prompt with the inputs returning a list of messages.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pipe<
NewRunOutput extends Object?, NewCallOptions extends RunnableOptions> (Runnable< List< next) → RunnableSequence<ChatMessage> , NewCallOptions, NewRunOutput>InputValues, NewRunOutput> -
Pipes the output of this Runnable into another Runnable using a
RunnableSequence.
inherited
-
stream(
InputValues input, {BaseLangChainOptions? options}) → Stream< List< ChatMessage> > -
Streams the output of invoking the Runnable on the given
input
.inherited -
streamFromInputStream(
Stream< InputValues> inputStream, {BaseLangChainOptions? options}) → Stream<List< ChatMessage> > -
Streams the output of invoking the Runnable on the given
inputStream
.inherited -
toString(
) → String -
A string representation of this object.
override
-
withFallbacks(
List< Runnable< fallbacks) → RunnableWithFallback<InputValues, RunnableOptions, List< >ChatMessage> >InputValues, List< ChatMessage> > -
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, List< ChatMessage> > -
Adds retry logic to an existing runnable.
inherited
Operators
-
operator ==(
covariant ChatMessagePromptTemplate other) → bool -
The equality operator.
inherited