ChatMessagePromptTemplate#
- class langchain_core.prompts.chat.ChatMessagePromptTemplate[source]#
 Bases:
BaseStringMessagePromptTemplateChat message prompt template.
- param additional_kwargs: dict [Optional]#
 Additional keyword arguments to pass to the prompt template.
- param prompt: StringPromptTemplate [Required]#
 String prompt template.
- param role: str [Required]#
 Role of the message.
- async aformat(**kwargs: Any) BaseMessage[source]#
 Async format the prompt template.
- Parameters:
 **kwargs (Any) β Keyword arguments to use for formatting.
- Returns:
 Formatted message.
- Return type:
 
- async aformat_messages(**kwargs: Any) List[BaseMessage]#
 Async format messages from kwargs.
- Parameters:
 **kwargs (Any) β Keyword arguments to use for formatting.
- Returns:
 List of BaseMessages.
- Return type:
 List[BaseMessage]
- format(**kwargs: Any) BaseMessage[source]#
 Format the prompt template.
- Parameters:
 **kwargs (Any) β Keyword arguments to use for formatting.
- Returns:
 Formatted message.
- Return type:
 
- format_messages(**kwargs: Any) List[BaseMessage]#
 Format messages from kwargs.
- Parameters:
 **kwargs (Any) β Keyword arguments to use for formatting.
- Returns:
 List of BaseMessages.
- Return type:
 List[BaseMessage]
- classmethod from_template(template: str, template_format: str = 'f-string', partial_variables: Dict[str, Any] | None = None, **kwargs: Any) MessagePromptTemplateT#
 Create a class from a string template.
- Parameters:
 template (str) β a template.
template_format (str) β format of the template. Defaults to βf-stringβ.
partial_variables (Dict[str, Any] | None) β
- A dictionary of variables that can be used to partially
 fill in the template. For example, if the template is
β{variable1} {variable2}β, and partial_variables is {βvariable1β: βfooβ}, then the final prompt will be βfoo {variable2}β. Defaults to None.
**kwargs (Any) β keyword arguments to pass to the constructor.
- Returns:
 A new instance of this class.
- Return type:
 MessagePromptTemplateT
- classmethod from_template_file(template_file: str | Path, input_variables: List[str], **kwargs: Any) MessagePromptTemplateT#
 Create a class from a template file.
- Parameters:
 template_file (str | Path) β path to a template file. String or Path.
input_variables (List[str]) β list of input variables.
**kwargs (Any) β keyword arguments to pass to the constructor.
- Returns:
 A new instance of this class.
- Return type:
 MessagePromptTemplateT
- pretty_print() None#
 Print a human-readable representation.
- Return type:
 None
- pretty_repr(html: bool = False) str#
 Human-readable representation.
- Parameters:
 html (bool) β Whether to format as HTML. Defaults to False.
- Returns:
 Human-readable representation.
- Return type:
 str
- property input_variables: List[str]#
 Input variables for this prompt template.
- Returns:
 List of input variable names.