ChatPromptTemplate.fromPromptMessages constructor
ChatPromptTemplate.fromPromptMessages(
- List<
ChatMessagePromptTemplate> promptMessages, { - bool validateTemplate = true,
Creates a ChatPromptTemplate with a list of template messages.
promptMessages
the list of template messages. The list can contain:- SystemChatMessagePromptTemplate (for system messages)
- HumanChatMessagePromptTemplate (for human messages)
- AIChatMessagePromptTemplate (for AI messages)
- CustomChatMessagePromptTemplate (for custom role messages)
validateTemplate
whether to validate the template.
Implementation
factory ChatPromptTemplate.fromPromptMessages(
final List<ChatMessagePromptTemplate> promptMessages, {
final bool validateTemplate = true,
}) {
final inputVariables = promptMessages
.map((final m) => m.inputVariables)
.expand((final i) => i)
.toSet();
final partialVariables = {
for (final m in promptMessages) ...?m.partialVariables,
};
final t = ChatPromptTemplate(
inputVariables: inputVariables,
partialVariables: partialVariables.isEmpty ? null : partialVariables,
promptMessages: promptMessages,
);
if (validateTemplate) {
t.validateTemplate();
}
return t;
}