langchain.prompts.chat.HumanMessagePromptTemplate¶

class langchain.prompts.chat.HumanMessagePromptTemplate(*, prompt: StringPromptTemplate, additional_kwargs: dict = None)[source]¶

Bases: BaseStringMessagePromptTemplate

Human message prompt template. This is a message that is sent to the user.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param additional_kwargs: dict [Optional]¶

Additional keyword arguments to pass to the prompt template.

param prompt: langchain.prompts.base.StringPromptTemplate [Required]¶

String prompt template.

format(**kwargs: Any) BaseMessage[source]¶

Format the prompt template.

Parameters

**kwargs – Keyword arguments to use for formatting.

Returns

Formatted message.

format_messages(**kwargs: Any) List[BaseMessage]¶

Format messages from kwargs.

Parameters

**kwargs – Keyword arguments to use for formatting.

Returns

List of BaseMessages.

classmethod from_template(template: str, template_format: str = 'f-string', **kwargs: Any) MessagePromptTemplateT¶

Create a class from a string template.

Parameters
  • template – a template.

  • template_format – format of the template.

  • **kwargs – keyword arguments to pass to the constructor.

Returns

A new instance of this class.

classmethod from_template_file(template_file: Union[str, Path], input_variables: List[str], **kwargs: Any) MessagePromptTemplateT¶

Create a class from a template file.

Parameters
  • template_file – path to a template file. String or Path.

  • input_variables – list of input variables.

  • **kwargs – keyword arguments to pass to the constructor.

Returns

A new instance of this class.

to_json() Union[SerializedConstructor, SerializedNotImplemented]¶
to_json_not_implemented() SerializedNotImplemented¶
property input_variables: List[str]¶

Input variables for this prompt template.

Returns

List of input variable names.

property lc_attributes: Dict¶

Return a list of attribute names that should be included in the serialized kwargs. These attributes must be accepted by the constructor.

property lc_namespace: List[str]¶

Return the namespace of the langchain object. eg. [“langchain”, “llms”, “openai”]

property lc_secrets: Dict[str, str]¶

Return a map of constructor argument names to secret ids. eg. {“openai_api_key”: “OPENAI_API_KEY”}

property lc_serializable: bool¶

Whether this object should be serialized.

Returns

Whether this object should be serialized.

model Config¶

Bases: object

extra = 'ignore'¶

Examples using HumanMessagePromptTemplate¶