AIMessagePromptTemplate#
- class langchain_core.prompts.chat.AIMessagePromptTemplate[source]#
Bases:
_StringImageMessagePromptTemplate
AI message prompt template. This is a message sent from the AI.
- param additional_kwargs: dict [Optional]#
Additional keyword arguments to pass to the prompt template.
- param prompt: StringPromptTemplate | list[StringPromptTemplate | ImagePromptTemplate | DictPromptTemplate] [Required]#
Prompt template.
- classmethod from_template(
- template: str | list[str | _TextTemplateParam | _ImageTemplateParam | dict[str, Any]],
- template_format: Literal['f-string', 'mustache', 'jinja2'] = 'f-string',
- *,
- partial_variables: dict[str, Any] | None = None,
- **kwargs: Any,
Create a class from a string template.
- Parameters:
template (str | list[str | _TextTemplateParam | _ImageTemplateParam | dict[str, Any]]) β a template.
template_format (Literal['f-string', 'mustache', 'jinja2']) β format of the template. Options are: βf-stringβ, βmustacheβ, βjinja2β. Defaults to βf-stringβ.
partial_variables (dict[str, Any] | None) β A dictionary of variables that can be used too partially. Defaults to None.
**kwargs (Any) β keyword arguments to pass to the constructor.
- Returns:
A new instance of this class.
- Raises:
ValueError β If the template is not a string or list of strings.
- Return type:
Self
- classmethod from_template_file(
- template_file: str | Path,
- input_variables: list[str],
- **kwargs: Any,
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:
Self
- async aformat(
- **kwargs: Any,
Async format the prompt template.
- Parameters:
**kwargs (Any) β Keyword arguments to use for formatting.
- Returns:
Formatted message.
- Return type:
- async aformat_messages(
- **kwargs: Any,
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,
Format the prompt template.
- Parameters:
**kwargs (Any) β Keyword arguments to use for formatting.
- Returns:
Formatted message.
- Return type:
- format_messages(
- **kwargs: Any,
Format messages from kwargs.
- Parameters:
**kwargs (Any) β Keyword arguments to use for formatting.
- Returns:
List of BaseMessages.
- Return type:
list[BaseMessage]
- pretty_print() None #
Print a human-readable representation.
- Return type:
None
- pretty_repr(
- html: bool = False,
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.