HumanMessagePromptTemplate#

class langchain_core.prompts.chat.HumanMessagePromptTemplate[source]#

Bases: _StringImageMessagePromptTemplate

Human message prompt template. This is a message sent from the user.

param additional_kwargs: dict [Optional]#

Additional keyword arguments to pass to the prompt template.

param prompt: StringPromptTemplate | List[StringPromptTemplate | ImagePromptTemplate] [Required]#

Prompt template.

async aformat(**kwargs: Any) β†’ BaseMessage#

Async format the prompt template.

Parameters:

**kwargs (Any) – Keyword arguments to use for formatting.

Returns:

Formatted message.

Return type:

BaseMessage

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#

Format the prompt template.

Parameters:

**kwargs (Any) – Keyword arguments to use for formatting.

Returns:

Formatted message.

Return type:

BaseMessage

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 | List[str | _TextTemplateParam | _ImageTemplateParam], template_format: str = 'f-string', *, partial_variables: Dict[str, Any] | None = None, **kwargs: Any) β†’ _StringImageMessagePromptTemplateT#

Create a class from a string template.

Parameters:
  • template (str | List[str | _TextTemplateParam | _ImageTemplateParam]) – 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 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:

_StringImageMessagePromptTemplateT

classmethod from_template_file(template_file: str | Path, input_variables: List[str], **kwargs: Any) β†’ _StringImageMessagePromptTemplateT#

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:

_StringImageMessagePromptTemplateT

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.

Examples using HumanMessagePromptTemplate