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);
templatethe template string.typethe type of chat message prompt template (HumanChatMessagePromptTemplate by default).customRolethe role of the message iftypeis ChatMessageType.custom.partialVariablesthe partial variables to use for the template.validateTemplatewhether 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,
);
}