test_output_version_stream() — langchain Function Reference
Architecture documentation for the test_output_version_stream() function in test_base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 7502de38_bb9d_1ace_8c9f_d6e4643d4d39["test_output_version_stream()"] 8830054d_ac1e_daa9_c6c5_ff55b10d0bf3["test_base.py"] 7502de38_bb9d_1ace_8c9f_d6e4643d4d39 -->|defined in| 8830054d_ac1e_daa9_c6c5_ff55b10d0bf3 style 7502de38_bb9d_1ace_8c9f_d6e4643d4d39 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/language_models/chat_models/test_base.py lines 965–1060
def test_output_version_stream(monkeypatch: Any) -> None:
messages = [AIMessage("foo bar")]
# v0
llm = GenericFakeChatModel(messages=iter(messages))
full = None
for chunk in llm.stream("hello"):
assert isinstance(chunk, AIMessageChunk)
assert isinstance(chunk.content, str)
assert chunk.content
full = chunk if full is None else full + chunk
assert isinstance(full, AIMessageChunk)
assert full.content == "foo bar"
# v1
llm = GenericFakeChatModel(messages=iter(messages), output_version="v1")
full_v1: AIMessageChunk | None = None
for chunk in llm.stream("hello"):
assert isinstance(chunk, AIMessageChunk)
assert isinstance(chunk.content, list)
assert len(chunk.content) == 1
block = chunk.content[0]
assert isinstance(block, dict)
assert block["type"] == "text"
assert block["text"]
full_v1 = chunk if full_v1 is None else full_v1 + chunk
assert isinstance(full_v1, AIMessageChunk)
assert full_v1.response_metadata["output_version"] == "v1"
assert full_v1.content == [{"type": "text", "text": "foo bar", "index": 0}]
# Test text blocks
llm_with_rich_content = _AnotherFakeChatModel(
responses=iter([]),
chunks=iter(
[
AIMessageChunk(content="foo "),
AIMessageChunk(content="bar"),
]
),
output_version="v1",
)
full_v1 = None
for chunk in llm_with_rich_content.stream("hello"):
full_v1 = chunk if full_v1 is None else full_v1 + chunk
assert isinstance(full_v1, AIMessageChunk)
assert full_v1.content_blocks == [{"type": "text", "text": "foo bar", "index": 0}]
# Test content blocks of different types
chunks = [
AIMessageChunk(content="", additional_kwargs={"reasoning_content": "<rea"}),
AIMessageChunk(content="", additional_kwargs={"reasoning_content": "soning>"}),
AIMessageChunk(content="<some "),
AIMessageChunk(content="text>"),
]
llm_with_rich_content = _AnotherFakeChatModel(
responses=iter([]),
chunks=iter(chunks),
output_version="v1",
)
full_v1 = None
for chunk in llm_with_rich_content.stream("hello"):
full_v1 = chunk if full_v1 is None else full_v1 + chunk
assert isinstance(full_v1, AIMessageChunk)
assert full_v1.content_blocks == [
{"type": "reasoning", "reasoning": "<reasoning>", "index": 0},
{"type": "text", "text": "<some text>", "index": 1},
]
# Test invoke with stream=True
llm_with_rich_content = _AnotherFakeChatModel(
responses=iter([]),
chunks=iter(chunks),
output_version="v1",
)
response_v1 = llm_with_rich_content.invoke("hello", stream=True)
assert response_v1.content_blocks == [
{"type": "reasoning", "reasoning": "<reasoning>", "index": 0},
{"type": "text", "text": "<some text>", "index": 1},
]
Domain
Subdomains
Source
Frequently Asked Questions
What does test_output_version_stream() do?
test_output_version_stream() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/language_models/chat_models/test_base.py.
Where is test_output_version_stream() defined?
test_output_version_stream() is defined in libs/core/tests/unit_tests/language_models/chat_models/test_base.py at line 965.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free