Home / Function/ test_on_llm_end_no_usage_metadata_when_not_present() — langchain Function Reference

test_on_llm_end_no_usage_metadata_when_not_present() — langchain Function Reference

Architecture documentation for the test_on_llm_end_no_usage_metadata_when_not_present() function in test_langchain.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2ff8abdd_f55a_40e3_576f_b2d7092f4a44["test_on_llm_end_no_usage_metadata_when_not_present()"]
  6ee6ed10_3ff3_3d50_08bc_311ea99250db["test_langchain.py"]
  2ff8abdd_f55a_40e3_576f_b2d7092f4a44 -->|defined in| 6ee6ed10_3ff3_3d50_08bc_311ea99250db
  style 2ff8abdd_f55a_40e3_576f_b2d7092f4a44 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/tracers/test_langchain.py lines 288–313

def test_on_llm_end_no_usage_metadata_when_not_present() -> None:
    """Test that no `usage_metadata` is added when not present in outputs."""
    client = unittest.mock.MagicMock(spec=Client)
    client.tracing_queue = None
    tracer = LangChainTracer(client=client)

    run_id = UUID("9d878ab3-e5ca-4218-aef6-44cbdc90160a")
    tracer.on_llm_start({"name": "test_llm"}, ["foo"], run_id=run_id)

    run = tracer.run_map[str(run_id)]
    run.outputs = {
        "generations": [[{"text": "Hello!", "message": {"content": "Hello!"}}]]
    }

    captured_run = None

    def capture_run(r: Run) -> None:
        nonlocal captured_run
        captured_run = r

    with unittest.mock.patch.object(tracer, "_update_run_single", capture_run):
        tracer._on_llm_end(run)

    assert captured_run is not None
    extra_metadata = captured_run.extra.get("metadata", {})
    assert "usage_metadata" not in extra_metadata

Domain

Subdomains

Frequently Asked Questions

What does test_on_llm_end_no_usage_metadata_when_not_present() do?
test_on_llm_end_no_usage_metadata_when_not_present() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/tracers/test_langchain.py.
Where is test_on_llm_end_no_usage_metadata_when_not_present() defined?
test_on_llm_end_no_usage_metadata_when_not_present() is defined in libs/core/tests/unit_tests/tracers/test_langchain.py at line 288.

Analyze Your Own Codebase

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

Try Supermodel Free