_astream() — langchain Function Reference
Architecture documentation for the _astream() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD eeec016b_d16e_6911_a23c_361548b5728f["_astream()"] 48aa29b8_65e7_522f_a445_a441eeb6baff["BaseChatModel"] eeec016b_d16e_6911_a23c_361548b5728f -->|defined in| 48aa29b8_65e7_522f_a445_a441eeb6baff 9d211053_b2a3_2915_b514_1f332955694a["astream()"] 9d211053_b2a3_2915_b514_1f332955694a -->|calls| eeec016b_d16e_6911_a23c_361548b5728f d2cd58bb_554b_a407_049a_8aaad431d049["_agenerate_with_cache()"] d2cd58bb_554b_a407_049a_8aaad431d049 -->|calls| eeec016b_d16e_6911_a23c_361548b5728f style eeec016b_d16e_6911_a23c_361548b5728f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/language_models/chat_models.py lines 1455–1491
async def _astream(
self,
messages: list[BaseMessage],
stop: list[str] | None = None,
run_manager: AsyncCallbackManagerForLLMRun | None = None,
**kwargs: Any,
) -> AsyncIterator[ChatGenerationChunk]:
"""Stream the output of the model.
Args:
messages: The messages to generate from.
stop: Optional list of stop words to use when generating.
run_manager: Optional callback manager to use for this call.
**kwargs: Additional keyword arguments to pass to the model.
Yields:
The chat generation chunks.
"""
iterator = await run_in_executor(
None,
self._stream,
messages,
stop,
run_manager.get_sync() if run_manager else None,
**kwargs,
)
done = object()
while True:
item = await run_in_executor(
None,
next,
iterator,
done,
)
if item is done:
break
yield item # type: ignore[misc]
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _astream() do?
_astream() is a function in the langchain codebase, defined in libs/core/langchain_core/language_models/chat_models.py.
Where is _astream() defined?
_astream() is defined in libs/core/langchain_core/language_models/chat_models.py at line 1455.
What calls _astream()?
_astream() is called by 2 function(s): _agenerate_with_cache, astream.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free