Home / Function/ test_image_token_counting_jpeg() — langchain Function Reference

test_image_token_counting_jpeg() — langchain Function Reference

Architecture documentation for the test_image_token_counting_jpeg() function in test_base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  d085bcda_3466_1046_f74b_1db9736845d4["test_image_token_counting_jpeg()"]
  bd382a4e_442c_13ae_530c_6e34bc43623d["test_base.py"]
  d085bcda_3466_1046_f74b_1db9736845d4 -->|defined in| bd382a4e_442c_13ae_530c_6e34bc43623d
  style d085bcda_3466_1046_f74b_1db9736845d4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/tests/integration_tests/chat_models/test_base.py lines 706–735

def test_image_token_counting_jpeg() -> None:
    model = ChatOpenAI(model="gpt-4o", temperature=0)
    image_url = "https://raw.githubusercontent.com/langchain-ai/docs/9f99bb977307a1bd5efeb8dc6b67eb13904c4af1/src/oss/images/checkpoints.jpg"
    message = HumanMessage(
        content=[
            {"type": "text", "text": "describe the weather 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": "describe the weather in this image"},
            {
                "type": "image_url",
                "image_url": {"url": f"data:image/jpeg;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

Frequently Asked Questions

What does test_image_token_counting_jpeg() do?
test_image_token_counting_jpeg() 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_jpeg() defined?
test_image_token_counting_jpeg() is defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py at line 706.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free