test_count_tokens_approximately_with_custom_image_penalty() — langchain Function Reference
Architecture documentation for the test_count_tokens_approximately_with_custom_image_penalty() function in test_utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 8955e9da_c5c6_376e_67ed_e46cfe41e331["test_count_tokens_approximately_with_custom_image_penalty()"] ea3f8d89_f44b_6738_3cb9_a740a73cfca4["test_utils.py"] 8955e9da_c5c6_376e_67ed_e46cfe41e331 -->|defined in| ea3f8d89_f44b_6738_3cb9_a740a73cfca4 style 8955e9da_c5c6_376e_67ed_e46cfe41e331 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/messages/test_utils.py lines 2813–2826
def test_count_tokens_approximately_with_custom_image_penalty() -> None:
"""Test custom tokens_per_image parameter."""
message = HumanMessage(
content=[
{"type": "text", "text": "test"},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,XYZ"}},
]
)
# Using custom image penalty (e.g., for Anthropic models)
token_count = count_tokens_approximately([message], tokens_per_image=1600)
# Should be ~1600 (image) + ~1 (text) + 3 (extra) = ~1604 tokens
assert 1600 < token_count < 1610
Domain
Subdomains
Source
Frequently Asked Questions
What does test_count_tokens_approximately_with_custom_image_penalty() do?
test_count_tokens_approximately_with_custom_image_penalty() 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_custom_image_penalty() defined?
test_count_tokens_approximately_with_custom_image_penalty() is defined in libs/core/tests/unit_tests/messages/test_utils.py at line 2813.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free