Home / Function/ test_token_costs_are_zeroed_out() — langchain Function Reference

test_token_costs_are_zeroed_out() — langchain Function Reference

Architecture documentation for the test_token_costs_are_zeroed_out() function in test_cache.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  34eef0e3_039c_3a78_0eff_293455892bdd["test_token_costs_are_zeroed_out()"]
  51f634bf_713d_3f19_d694_5c6ef3e59c57["test_cache.py"]
  34eef0e3_039c_3a78_0eff_293455892bdd -->|defined in| 51f634bf_713d_3f19_d694_5c6ef3e59c57
  style 34eef0e3_039c_3a78_0eff_293455892bdd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/language_models/chat_models/test_cache.py lines 460–477

def test_token_costs_are_zeroed_out() -> None:
    # We zero-out token costs for cache hits
    local_cache = InMemoryCache()
    messages = [
        AIMessage(
            content="Hello, how are you?",
            usage_metadata={"input_tokens": 5, "output_tokens": 10, "total_tokens": 15},
        ),
    ]
    model = GenericFakeChatModel(messages=iter(messages), cache=local_cache)
    first_response = model.invoke("Hello")
    assert isinstance(first_response, AIMessage)
    assert first_response.usage_metadata

    second_response = model.invoke("Hello")
    assert isinstance(second_response, AIMessage)
    assert second_response.usage_metadata
    assert second_response.usage_metadata["total_cost"] == 0  # type: ignore[typeddict-item]

Subdomains

Frequently Asked Questions

What does test_token_costs_are_zeroed_out() do?
test_token_costs_are_zeroed_out() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/language_models/chat_models/test_cache.py.
Where is test_token_costs_are_zeroed_out() defined?
test_token_costs_are_zeroed_out() is defined in libs/core/tests/unit_tests/language_models/chat_models/test_cache.py at line 460.

Analyze Your Own Codebase

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

Try Supermodel Free