test_count_tokens_approximately_mixed_content_types() — langchain Function Reference
Architecture documentation for the test_count_tokens_approximately_mixed_content_types() function in test_utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9e1bfa37_cfc2_c90d_a324_5dcf6f9cd372["test_count_tokens_approximately_mixed_content_types()"] 03f6a5ae_d57a_eb66_626a_b9e082b763ea["test_utils.py"] 9e1bfa37_cfc2_c90d_a324_5dcf6f9cd372 -->|defined in| 03f6a5ae_d57a_eb66_626a_b9e082b763ea style 9e1bfa37_cfc2_c90d_a324_5dcf6f9cd372 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/messages/test_utils.py lines 1577–1595
def test_count_tokens_approximately_mixed_content_types() -> None:
# Test with a variety of content types in the same message list
tool_calls = [{"name": "test_tool", "args": {"foo": "bar"}, "id": "1"}]
messages = [
# 13 chars + 6 role chars -> 5 + 3 = 8 tokens
SystemMessage(content="System prompt"),
# '[{"foo": "bar"}]' -> 16 chars + 4 role chars -> 5 + 3 = 8 tokens
HumanMessage(content=[{"foo": "bar"}]),
# tool calls json -> 79 chars + 9 role chars -> 22 + 3 = 25 tokens
AIMessage(content="", tool_calls=tool_calls),
# 13 chars + 4 role chars + 9 name chars + 1 tool call ID char ->
# 7 + 3 = 10 tokens
ToolMessage(content="Tool response", name="test_tool", tool_call_id="1"),
]
token_count = count_tokens_approximately(messages)
assert token_count == 51
# Ensure that count is consistent if we do one message at a time
assert sum(count_tokens_approximately([m]) for m in messages) == token_count
Domain
Subdomains
Source
Frequently Asked Questions
What does test_count_tokens_approximately_mixed_content_types() do?
test_count_tokens_approximately_mixed_content_types() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/messages/test_utils.py.
Where is test_count_tokens_approximately_mixed_content_types() defined?
test_count_tokens_approximately_mixed_content_types() is defined in libs/core/tests/unit_tests/messages/test_utils.py at line 1577.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free