test_event_stream_with_simple_chain() — langchain Function Reference
Architecture documentation for the test_event_stream_with_simple_chain() function in test_runnable_events_v1.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5afb8c1f_95cf_1de6_8a84_86e359af0582["test_event_stream_with_simple_chain()"] 8ff41f3c_f250_f8de_8094_4f24860a10e0["test_runnable_events_v1.py"] 5afb8c1f_95cf_1de6_8a84_86e359af0582 -->|defined in| 8ff41f3c_f250_f8de_8094_4f24860a10e0 aac0453e_34cd_4dce_c7fa_f176ab20140b["_collect_events()"] 5afb8c1f_95cf_1de6_8a84_86e359af0582 -->|calls| aac0453e_34cd_4dce_c7fa_f176ab20140b 6ebe7fde_6e8f_dae5_d42f_9cea181617f5["_assert_events_equal_allow_superset_metadata()"] 5afb8c1f_95cf_1de6_8a84_86e359af0582 -->|calls| 6ebe7fde_6e8f_dae5_d42f_9cea181617f5 style 5afb8c1f_95cf_1de6_8a84_86e359af0582 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/runnables/test_runnable_events_v1.py lines 818–1061
async def test_event_stream_with_simple_chain() -> None:
"""Test as event stream."""
template = ChatPromptTemplate.from_messages(
[
("system", "You are Cat Agent 007"),
("human", "{question}"),
]
).with_config({"run_name": "my_template", "tags": ["my_template"]})
infinite_cycle = cycle(
[
AIMessage(content="hello world!", id="ai1"),
AIMessage(content="goodbye world!", id="ai2"),
]
)
# When streaming GenericFakeChatModel breaks AIMessage into chunks based on spaces
model = (
GenericFakeChatModel(messages=infinite_cycle)
.with_config(
{
"metadata": {"a": "b"},
"tags": ["my_model"],
"run_name": "my_model",
}
)
.bind(stop="<stop_token>")
)
chain = (template | model).with_config(
{
"metadata": {"foo": "bar"},
"tags": ["my_chain"],
"run_name": "my_chain",
}
)
events = await _collect_events(
chain.astream_events({"question": "hello"}, version="v1")
)
_assert_events_equal_allow_superset_metadata(
events,
[
{
"data": {"input": {"question": "hello"}},
"event": "on_chain_start",
"metadata": {"foo": "bar"},
"name": "my_chain",
"run_id": "",
"parent_ids": [],
"tags": ["my_chain"],
},
{
"data": {"input": {"question": "hello"}},
"event": "on_prompt_start",
"metadata": {"foo": "bar"},
"name": "my_template",
"run_id": "",
"parent_ids": [],
"tags": ["my_chain", "my_template", "seq:step:1"],
},
{
"data": {
"input": {"question": "hello"},
"output": ChatPromptValue(
messages=[
SystemMessage(content="You are Cat Agent 007"),
HumanMessage(content="hello"),
]
),
},
"event": "on_prompt_end",
"metadata": {"foo": "bar"},
"name": "my_template",
"run_id": "",
"parent_ids": [],
"tags": ["my_chain", "my_template", "seq:step:1"],
},
{
"data": {
"input": {
"messages": [
Domain
Subdomains
Source
Frequently Asked Questions
What does test_event_stream_with_simple_chain() do?
test_event_stream_with_simple_chain() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable_events_v1.py.
Where is test_event_stream_with_simple_chain() defined?
test_event_stream_with_simple_chain() is defined in libs/core/tests/unit_tests/runnables/test_runnable_events_v1.py at line 818.
What does test_event_stream_with_simple_chain() call?
test_event_stream_with_simple_chain() calls 2 function(s): _assert_events_equal_allow_superset_metadata, _collect_events.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free