ChatPromptTemplate.fromTemplate constructor
ChatPromptTemplate.fromTemplate(
- String template, {
- ChatMessageType type = ChatMessageType.human,
- String? customRole,
- PartialValues? partialVariables,
- bool validateTemplate = true,
Creates a chat prompt template with a single message from a string template.
Example:
final promptTemplate = ChatPromptTemplate.fromTemplate(
"Hello {foo}, I'm {bar}. Thanks for the {context}",
partialVariables: {'foo': 'GPT-4', 'bar': 'Gemini'},
);
final prompt = promptTemplate.formatPrompt({'context': 'competition'});
final res = await chatModel.invoke(prompt);
template
the template string.type
the type of chat message prompt template (HumanChatMessagePromptTemplate by default).customRole
the role of the message iftype
is ChatMessageType.custom.partialVariables
the partial variables to use for the template.validateTemplate
whether to validate the template.
Implementation
factory ChatPromptTemplate.fromTemplate(
final String template, {
final ChatMessageType type = ChatMessageType.human,
final String? customRole,
final PartialValues? partialVariables,
final bool validateTemplate = true,
}) {
return ChatPromptTemplate.fromTemplates(
[(type, template)],
customRole: customRole,
partialVariables: partialVariables,
validateTemplate: validateTemplate,
);
}