MessagesPlaceholder constructor
const
MessagesPlaceholder({
- required String variableName,
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'),
]);
Implementation
const MessagesPlaceholder({required this.variableName})
: super(prompt: const PromptTemplate(inputVariables: {}, template: ''));