Home / Function/ test_trim_messages_partial_text_splitting() — langchain Function Reference

test_trim_messages_partial_text_splitting() — langchain Function Reference

Architecture documentation for the test_trim_messages_partial_text_splitting() function in test_utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  e27eada3_bbef_88de_1750_2c7d6007b5d7["test_trim_messages_partial_text_splitting()"]
  03f6a5ae_d57a_eb66_626a_b9e082b763ea["test_utils.py"]
  e27eada3_bbef_88de_1750_2c7d6007b5d7 -->|defined in| 03f6a5ae_d57a_eb66_626a_b9e082b763ea
  style e27eada3_bbef_88de_1750_2c7d6007b5d7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/messages/test_utils.py lines 568–590

def test_trim_messages_partial_text_splitting() -> None:
    messages = [HumanMessage(content="This is a long message that needs trimming")]
    messages_copy = [m.model_copy(deep=True) for m in messages]

    def count_characters(msgs: list[BaseMessage]) -> int:
        return sum(len(m.content) if isinstance(m.content, str) else 0 for m in msgs)

    # Return individual characters to test text splitting
    def char_splitter(text: str) -> list[str]:
        return list(text)

    result = trim_messages(
        messages,
        max_tokens=10,  # Only allow 10 characters
        token_counter=count_characters,
        strategy="first",
        allow_partial=True,
        text_splitter=char_splitter,
    )

    assert len(result) == 1
    assert result[0].content == "This is a "  # First 10 characters
    assert messages == messages_copy

Domain

Subdomains

Frequently Asked Questions

What does test_trim_messages_partial_text_splitting() do?
test_trim_messages_partial_text_splitting() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/messages/test_utils.py.
Where is test_trim_messages_partial_text_splitting() defined?
test_trim_messages_partial_text_splitting() is defined in libs/core/tests/unit_tests/messages/test_utils.py at line 568.

Analyze Your Own Codebase

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

Try Supermodel Free