Home / Function/ test_message_text() — langchain Function Reference

test_message_text() — langchain Function Reference

Architecture documentation for the test_message_text() function in test_messages.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  1e1b7a17_5010_1dc8_0495_0982e2cd1b8f["test_message_text()"]
  1c821c4f_25a2_9606_a15f_b3df054105ac["test_messages.py"]
  1e1b7a17_5010_1dc8_0495_0982e2cd1b8f -->|defined in| 1c821c4f_25a2_9606_a15f_b3df054105ac
  style 1e1b7a17_5010_1dc8_0495_0982e2cd1b8f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/test_messages.py lines 1053–1107

def test_message_text() -> None:
    # partitions:
    # message types: [ai], [human], [system], [tool]
    # content types: [str], [list[str]], [list[dict]], [list[str | dict]]
    # content: [empty], [single element], [multiple elements]
    # content dict types: [text], [not text], [no type]

    assert HumanMessage(content="foo").text == "foo"
    assert AIMessage(content=[]).text == ""
    assert AIMessage(content=["foo", "bar"]).text == "foobar"
    assert (
        AIMessage(
            content=[
                {"type": "text", "text": "<thinking>thinking...</thinking>"},
                {
                    "type": "tool_use",
                    "id": "toolu_01A09q90qw90lq917835lq9",
                    "name": "get_weather",
                    "input": {"location": "San Francisco, CA"},
                },
            ]
        ).text
        == "<thinking>thinking...</thinking>"
    )
    assert (
        SystemMessage(content=[{"type": "text", "text": "foo"}, "bar"]).text == "foobar"
    )
    assert (
        ToolMessage(
            content=[
                {"type": "text", "text": "15 degrees"},
                {
                    "type": "image",
                    "source": {
                        "type": "base64",
                        "media_type": "image/jpeg",
                        "data": "/9j/4AAQSkZJRg...",
                    },
                },
            ],
            tool_call_id="1",
        ).text
        == "15 degrees"
    )
    assert (
        AIMessage(content=[{"text": "hi there"}, "hi"]).text == "hi"
    )  # missing type: text
    assert AIMessage(content=[{"type": "nottext", "text": "hi"}]).text == ""
    assert AIMessage(content=[]).text == ""
    assert (
        AIMessage(
            content="", tool_calls=[create_tool_call(name="a", args={"b": 1}, id=None)]
        ).text
        == ""
    )

Domain

Subdomains

Frequently Asked Questions

What does test_message_text() do?
test_message_text() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/test_messages.py.
Where is test_message_text() defined?
test_message_text() is defined in libs/core/tests/unit_tests/test_messages.py at line 1053.

Analyze Your Own Codebase

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

Try Supermodel Free