Home / Function/ test_citations() — langchain Function Reference

test_citations() — langchain Function Reference

Architecture documentation for the test_citations() function in test_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  fb81944e_671b_011d_b55c_c8a98e82a401["test_citations()"]
  f27640dd_3870_5548_d153_f9504ae1021f["test_chat_models.py"]
  fb81944e_671b_011d_b55c_c8a98e82a401 -->|defined in| f27640dd_3870_5548_d153_f9504ae1021f
  style fb81944e_671b_011d_b55c_c8a98e82a401 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/tests/integration_tests/test_chat_models.py lines 956–1002

def test_citations(output_version: Literal["v0", "v1"]) -> None:
    llm = ChatAnthropic(model=MODEL_NAME, output_version=output_version)  # type: ignore[call-arg]
    messages = [
        {
            "role": "user",
            "content": [
                {
                    "type": "document",
                    "source": {
                        "type": "content",
                        "content": [
                            {"type": "text", "text": "The grass is green"},
                            {"type": "text", "text": "The sky is blue"},
                        ],
                    },
                    "citations": {"enabled": True},
                },
                {"type": "text", "text": "What color is the grass and sky?"},
            ],
        },
    ]
    response = llm.invoke(messages)
    assert isinstance(response, AIMessage)
    assert isinstance(response.content, list)
    if output_version == "v1":
        assert any("annotations" in block for block in response.content)
    else:
        assert any("citations" in block for block in response.content)

    # Test streaming
    full: BaseMessageChunk | None = None
    for chunk in llm.stream(messages):
        full = cast("BaseMessageChunk", chunk) if full is None else full + chunk
    assert isinstance(full, AIMessageChunk)
    assert isinstance(full.content, list)
    assert not any("citation" in block for block in full.content)
    if output_version == "v1":
        assert any("annotations" in block for block in full.content)
    else:
        assert any("citations" in block for block in full.content)

    # Test pass back in
    next_message = {
        "role": "user",
        "content": "Can you comment on the citations you just made?",
    }
    _ = llm.invoke([*messages, full, next_message])

Domain

Subdomains

Frequently Asked Questions

What does test_citations() do?
test_citations() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py.
Where is test_citations() defined?
test_citations() is defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py at line 956.

Analyze Your Own Codebase

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

Try Supermodel Free