Home / Function/ test_chat_tmpl_dict_msg() — langchain Function Reference

test_chat_tmpl_dict_msg() — langchain Function Reference

Architecture documentation for the test_chat_tmpl_dict_msg() function in test_chat.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  a4685e9f_3c84_a195_f9c4_f9399dbc8a76["test_chat_tmpl_dict_msg()"]
  bf3138ca_0068_68ea_f479_35376e264d13["test_chat.py"]
  a4685e9f_3c84_a195_f9c4_f9399dbc8a76 -->|defined in| bf3138ca_0068_68ea_f479_35376e264d13
  style a4685e9f_3c84_a195_f9c4_f9399dbc8a76 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/prompts/test_chat.py lines 1270–1342

def test_chat_tmpl_dict_msg() -> None:
    template = ChatPromptTemplate(
        [
            {
                "role": "assistant",
                "content": [
                    {
                        "type": "text",
                        "text": "{text1}",
                        "cache_control": {"type": "ephemeral"},
                    },
                ],
                "name": "{name1}",
                "tool_calls": [
                    {
                        "name": "{tool_name1}",
                        "args": {"arg1": "{tool_arg1}"},
                        "id": "1",
                        "type": "tool_call",
                    }
                ],
            },
            {
                "role": "tool",
                "content": "{tool_content2}",
                "tool_call_id": "1",
                "name": "{tool_name1}",
            },
        ]
    )
    expected = [
        AIMessage(
            [
                {
                    "type": "text",
                    "text": "important message",
                    "cache_control": {"type": "ephemeral"},
                },
            ],
            name="foo",
            tool_calls=[
                {
                    "name": "do_stuff",
                    "args": {"arg1": "important arg1"},
                    "id": "1",
                    "type": "tool_call",
                }
            ],
        ),
        ToolMessage("foo", name="do_stuff", tool_call_id="1"),
    ]

    actual = template.invoke(
        {
            "text1": "important message",
            "name1": "foo",
            "tool_arg1": "important arg1",
            "tool_name1": "do_stuff",
            "tool_content2": "foo",
        }
    ).to_messages()
    assert actual == expected

    partial_ = template.partial(text1="important message")
    actual = partial_.invoke(
        {
            "name1": "foo",
            "tool_arg1": "important arg1",
            "tool_name1": "do_stuff",
            "tool_content2": "foo",
        }
    ).to_messages()
    assert actual == expected

Subdomains

Frequently Asked Questions

What does test_chat_tmpl_dict_msg() do?
test_chat_tmpl_dict_msg() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/prompts/test_chat.py.
Where is test_chat_tmpl_dict_msg() defined?
test_chat_tmpl_dict_msg() is defined in libs/core/tests/unit_tests/prompts/test_chat.py at line 1270.

Analyze Your Own Codebase

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

Try Supermodel Free