Home / Function/ from_template() — langchain Function Reference

from_template() — langchain Function Reference

Architecture documentation for the from_template() function in chat.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6966af16_ade2_de3e_4f06_f97eca43d8e0["from_template()"]
  4766cfc7_f772_eccc_6561_2122efd2c5e8["BaseStringMessagePromptTemplate"]
  6966af16_ade2_de3e_4f06_f97eca43d8e0 -->|defined in| 4766cfc7_f772_eccc_6561_2122efd2c5e8
  48373769_1ea6_b4a1_72e7_07082679631b["from_template()"]
  48373769_1ea6_b4a1_72e7_07082679631b -->|calls| 6966af16_ade2_de3e_4f06_f97eca43d8e0
  fb7525a5_49cc_cee5_9a12_dffafec8f35b["from_template()"]
  fb7525a5_49cc_cee5_9a12_dffafec8f35b -->|calls| 6966af16_ade2_de3e_4f06_f97eca43d8e0
  2d45b52a_4608_cd37_32ee_8262977a52f4["from_template_file()"]
  2d45b52a_4608_cd37_32ee_8262977a52f4 -->|calls| 6966af16_ade2_de3e_4f06_f97eca43d8e0
  05fbd76f_5319_5d90_fd32_8ae595f01924["__add__()"]
  05fbd76f_5319_5d90_fd32_8ae595f01924 -->|calls| 6966af16_ade2_de3e_4f06_f97eca43d8e0
  dee074bd_3404_de66_dbc9_422f215993ec["_create_template_from_message_type()"]
  dee074bd_3404_de66_dbc9_422f215993ec -->|calls| 6966af16_ade2_de3e_4f06_f97eca43d8e0
  0a946d27_710a_f7ff_e9e4_87561079dc25["_convert_to_message_template()"]
  0a946d27_710a_f7ff_e9e4_87561079dc25 -->|calls| 6966af16_ade2_de3e_4f06_f97eca43d8e0
  48373769_1ea6_b4a1_72e7_07082679631b["from_template()"]
  6966af16_ade2_de3e_4f06_f97eca43d8e0 -->|calls| 48373769_1ea6_b4a1_72e7_07082679631b
  style 6966af16_ade2_de3e_4f06_f97eca43d8e0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/prompts/chat.py lines 235–264

    def from_template(
        cls,
        template: str,
        template_format: PromptTemplateFormat = "f-string",
        partial_variables: dict[str, Any] | None = None,
        **kwargs: Any,
    ) -> Self:
        """Create a class from a string template.

        Args:
            template: a template.
            template_format: format of the template.
            partial_variables: 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}"`.

            **kwargs: Keyword arguments to pass to the constructor.

        Returns:
            A new instance of this class.
        """
        prompt = PromptTemplate.from_template(
            template,
            template_format=template_format,
            partial_variables=partial_variables,
        )
        return cls(prompt=prompt, **kwargs)

Subdomains

Frequently Asked Questions

What does from_template() do?
from_template() is a function in the langchain codebase, defined in libs/core/langchain_core/prompts/chat.py.
Where is from_template() defined?
from_template() is defined in libs/core/langchain_core/prompts/chat.py at line 235.
What does from_template() call?
from_template() calls 1 function(s): from_template.
What calls from_template()?
from_template() is called by 6 function(s): __add__, _convert_to_message_template, _create_template_from_message_type, from_template, from_template, from_template_file.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free