test_image_token_counting_png() — langchain Function Reference
Architecture documentation for the test_image_token_counting_png() function in test_base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 48a2b3d9_e4a1_f378_c03f_8999dd8fdf31["test_image_token_counting_png()"] bd382a4e_442c_13ae_530c_6e34bc43623d["test_base.py"] 48a2b3d9_e4a1_f378_c03f_8999dd8fdf31 -->|defined in| bd382a4e_442c_13ae_530c_6e34bc43623d style 48a2b3d9_e4a1_f378_c03f_8999dd8fdf31 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/tests/integration_tests/chat_models/test_base.py lines 738–767
def test_image_token_counting_png() -> None:
model = ChatOpenAI(model="gpt-4o", temperature=0)
image_url = "https://raw.githubusercontent.com/langchain-ai/docs/4d11d08b6b0e210bd456943f7a22febbd168b543/src/images/agentic-rag-output.png"
message = HumanMessage(
content=[
{"type": "text", "text": "how many dice are in this image"},
{"type": "image_url", "image_url": {"url": image_url}},
]
)
expected = cast(AIMessage, model.invoke([message])).usage_metadata[ # type: ignore[index]
"input_tokens"
]
actual = model.get_num_tokens_from_messages([message])
assert expected == actual
image_data = base64.b64encode(httpx.get(image_url).content).decode("utf-8")
message = HumanMessage(
content=[
{"type": "text", "text": "how many dice are in this image"},
{
"type": "image_url",
"image_url": {"url": f"data:image/png;base64,{image_data}"},
},
]
)
expected = cast(AIMessage, model.invoke([message])).usage_metadata[ # type: ignore[index]
"input_tokens"
]
actual = model.get_num_tokens_from_messages([message])
assert expected == actual
Domain
Subdomains
Source
Frequently Asked Questions
What does test_image_token_counting_png() do?
test_image_token_counting_png() is a function in the langchain codebase, defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py.
Where is test_image_token_counting_png() defined?
test_image_token_counting_png() is defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py at line 738.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free