BaseStringMessagePromptTemplate#

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

Bases: BaseMessagePromptTemplate, ABC

Base class for message prompt templates that use a string prompt template.

param additional_kwargs: dict [Optional]#

Additional keyword arguments to pass to the prompt template.

param prompt: StringPromptTemplate [Required]#

String prompt template.

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:

BaseMessage

async aformat_messages(**kwargs: Any) β†’ list[BaseMessage][source]#

Async format messages from kwargs.

Parameters:

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

Returns:

List of BaseMessages.

Return type:

list[BaseMessage]

abstract format(**kwargs: Any) β†’ BaseMessage[source]#

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][source]#

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: Literal['f-string', 'mustache', 'jinja2'] = 'f-string', partial_variables: dict[str, Any] | None = None, **kwargs: Any) β†’ MessagePromptTemplateT[source]#

Create a class from a string template.

Parameters:
  • template (str) – a template.

  • template_format (Literal['f-string', 'mustache', 'jinja2']) – 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[source]#

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[source]#

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.