test_trim_messages_mixed_content_with_partial() — langchain Function Reference
Architecture documentation for the test_trim_messages_mixed_content_with_partial() function in test_utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 37a4d7cf_f06a_4e59_3f6b_4bb9c4eb6976["test_trim_messages_mixed_content_with_partial()"] 03f6a5ae_d57a_eb66_626a_b9e082b763ea["test_utils.py"] 37a4d7cf_f06a_4e59_3f6b_4bb9c4eb6976 -->|defined in| 03f6a5ae_d57a_eb66_626a_b9e082b763ea style 37a4d7cf_f06a_4e59_3f6b_4bb9c4eb6976 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/messages/test_utils.py lines 593–629
def test_trim_messages_mixed_content_with_partial() -> None:
messages = [
AIMessage(
content=[
{"type": "text", "text": "First part of text."},
{"type": "text", "text": "Second part that should be trimmed."},
]
)
]
messages_copy = [m.model_copy(deep=True) for m in messages]
# Count total length of all text parts
def count_text_length(msgs: list[BaseMessage]) -> int:
total = 0
for msg in msgs:
if isinstance(msg.content, list):
for block in msg.content:
if isinstance(block, dict) and block.get("type") == "text":
total += len(block["text"])
elif isinstance(msg.content, str):
total += len(msg.content)
return total
result = trim_messages(
messages,
max_tokens=20, # Only allow first text block
token_counter=count_text_length,
strategy="first",
allow_partial=True,
)
assert len(result) == 1
assert len(result[0].content) == 1
content = result[0].content[0]
assert isinstance(content, dict)
assert content["text"] == "First part of text."
assert messages == messages_copy
Domain
Subdomains
Source
Frequently Asked Questions
What does test_trim_messages_mixed_content_with_partial() do?
test_trim_messages_mixed_content_with_partial() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/messages/test_utils.py.
Where is test_trim_messages_mixed_content_with_partial() defined?
test_trim_messages_mixed_content_with_partial() is defined in libs/core/tests/unit_tests/messages/test_utils.py at line 593.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free