MessagePlaceholder constructor

const MessagePlaceholder({
  1. required String variableName,
})

Prompt template that assumes the variable is a ChatMessage (ChatMessageType.messagePlaceholder).

This is useful when you want to use a single ChatMessage in the prompt. For example, when you decide the type of message at runtime (e.g. HumanChatMessage or FunctionChatMessage).

If you need to add multiple messages, use MessagesPlaceholder.

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