fromTemplateFile static method

Future<ChatPromptTemplate> fromTemplateFile(
  1. String templateFile, {
  2. ChatMessageType type = ChatMessageType.human,
  3. String? customRole,
  4. PartialValues? partialVariables,
  5. bool validateTemplate = true,
})

Creates a ChatPromptTemplate with a single message from a file.

  • templateFile the path to the file containing the prompt template.
  • type the type of chat message prompt template (HumanChatMessagePromptTemplate by default).
  • customRole the role of the message if type is ChatMessageType.custom.
  • partialVariables the partial variables to use for the template.
  • validateTemplate whether to validate the template.

Implementation

static Future<ChatPromptTemplate> fromTemplateFile(
  final String templateFile, {
  final ChatMessageType type = ChatMessageType.human,
  final String? customRole,
  final PartialValues? partialVariables,
  final bool validateTemplate = true,
}) async {
  final file = XFile(templateFile);
  final template = await file.readAsString();
  return ChatPromptTemplate.fromTemplate(
    template,
    type: type,
    customRole: customRole,
    partialVariables: partialVariables,
    validateTemplate: validateTemplate,
  );
}