test_count_tokens_approximately_with_image_content() — langchain Function Reference
Architecture documentation for the test_count_tokens_approximately_with_image_content() function in test_utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6a5169f6_548d_b3bb_92fa_3186a78f54f5["test_count_tokens_approximately_with_image_content()"] ea3f8d89_f44b_6738_3cb9_a740a73cfca4["test_utils.py"] 6a5169f6_548d_b3bb_92fa_3186a78f54f5 -->|defined in| ea3f8d89_f44b_6738_3cb9_a740a73cfca4 style 6a5169f6_548d_b3bb_92fa_3186a78f54f5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/messages/test_utils.py lines 2764–2780
def test_count_tokens_approximately_with_image_content() -> None:
"""Test approximate token counting with image content blocks."""
message_with_image = HumanMessage(
content=[
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": {"url": "data:image/jpeg;base64," + "A" * 100000},
},
]
)
token_count = count_tokens_approximately([message_with_image])
# Should be ~85 (image) + ~5 (text) + 3 (extra) = ~93 tokens, NOT 25,000+
assert token_count < 200, f"Expected <200 tokens, got {token_count}"
assert token_count > 80, f"Expected >80 tokens, got {token_count}"
Domain
Subdomains
Source
Frequently Asked Questions
What does test_count_tokens_approximately_with_image_content() do?
test_count_tokens_approximately_with_image_content() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/messages/test_utils.py.
Where is test_count_tokens_approximately_with_image_content() defined?
test_count_tokens_approximately_with_image_content() is defined in libs/core/tests/unit_tests/messages/test_utils.py at line 2764.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free