Home / Function/ test_astream() — langchain Function Reference

test_astream() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  3bdcc8ca_2634_ddb8_d31c_92f1ec62998f["test_astream()"]
  ec975712_a998_0a1f_0930_22940fc39a1e["test_chat_models.py"]
  3bdcc8ca_2634_ddb8_d31c_92f1ec62998f -->|defined in| ec975712_a998_0a1f_0930_22940fc39a1e
  style 3bdcc8ca_2634_ddb8_d31c_92f1ec62998f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/fireworks/tests/integration_tests/test_chat_models.py lines 60–94

async def test_astream() -> None:
    """Test streaming tokens from ChatFireworks."""
    llm = ChatFireworks(model="accounts/fireworks/models/kimi-k2-instruct-0905")

    full: BaseMessageChunk | None = None
    chunks_with_token_counts = 0
    chunks_with_response_metadata = 0
    async for token in llm.astream("I'm Pickle Rick"):
        assert isinstance(token, AIMessageChunk)
        assert isinstance(token.content, str)
        full = token if full is None else full + token
        if token.usage_metadata is not None:
            chunks_with_token_counts += 1
        if token.response_metadata and not set(token.response_metadata.keys()).issubset(
            {"model_provider", "output_version"}
        ):
            chunks_with_response_metadata += 1
    if chunks_with_token_counts != 1 or chunks_with_response_metadata != 1:
        msg = (
            "Expected exactly one chunk with token counts or response_metadata. "
            "AIMessageChunk aggregation adds / appends counts and metadata. Check that "
            "this is behaving properly."
        )
        raise AssertionError(msg)
    assert isinstance(full, AIMessageChunk)
    assert full.usage_metadata is not None
    assert full.usage_metadata["input_tokens"] > 0
    assert full.usage_metadata["output_tokens"] > 0
    assert (
        full.usage_metadata["input_tokens"] + full.usage_metadata["output_tokens"]
        == full.usage_metadata["total_tokens"]
    )
    assert isinstance(full.response_metadata["model_name"], str)
    assert full.response_metadata["model_name"]
    assert full.response_metadata["model_provider"] == "fireworks"

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free