CustomChatMessagePromptTemplate.fromTemplate constructor

CustomChatMessagePromptTemplate.fromTemplate(
  1. String template, {
  2. required String role,
  3. PartialValues? partialVariables,
  4. bool validateTemplate = true,
})

Creates a CustomChatMessagePromptTemplate from a string template. It considers the prompt a CustomChatMessage.

Example:

final msgTemplate = CustomChatMessagePromptTemplate.fromTemplate(
  "I'm an assistant. I'm {foo}. I'm {bar}.",
  role: 'assistant',
);

Alternatively, you can use ChatMessagePromptTemplate.custom to achieve the same result.

final msgTemplate = ChatMessagePromptTemplate.custom(
  "I'm an assistant. I'm {foo}. I'm {bar}.",
  role: 'assistant',
);
  • template the template string.
  • role the role of the message.
  • partialVariables the partial variables to use for the template.
  • validateTemplate whether to validate the template.

Implementation

factory CustomChatMessagePromptTemplate.fromTemplate(
  final String template, {
  required final String role,
  final PartialValues? partialVariables,
  final bool validateTemplate = true,
}) {
  return CustomChatMessagePromptTemplate(
    prompt: PromptTemplate.fromTemplate(
      template,
      partialVariables: partialVariables,
      validateTemplate: validateTemplate,
    ),
    role: role,
  );
}