Home / Function/ _astream() — langchain Function Reference

_astream() — langchain Function Reference

Architecture documentation for the _astream() function in fake_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4aca5160_857e_b75e_f95a_9c6c1a4db44a["_astream()"]
  2790c9e0_a72e_5aac_c2c7_6702139c50e3["FakeListChatModel"]
  4aca5160_857e_b75e_f95a_9c6c1a4db44a -->|defined in| 2790c9e0_a72e_5aac_c2c7_6702139c50e3
  style 4aca5160_857e_b75e_f95a_9c6c1a4db44a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/language_models/fake_chat_models.py lines 124–149

    async def _astream(
        self,
        messages: list[BaseMessage],
        stop: list[str] | None = None,
        run_manager: AsyncCallbackManagerForLLMRun | None = None,
        **kwargs: Any,
    ) -> AsyncIterator[ChatGenerationChunk]:
        response = self.responses[self.i]
        if self.i < len(self.responses) - 1:
            self.i += 1
        else:
            self.i = 0
        for i_c, c in enumerate(response):
            if self.sleep is not None:
                await asyncio.sleep(self.sleep)
            if (
                self.error_on_chunk_number is not None
                and i_c == self.error_on_chunk_number
            ):
                raise FakeListChatModelError
            chunk_position: Literal["last"] | None = (
                "last" if i_c == len(response) - 1 else None
            )
            yield ChatGenerationChunk(
                message=AIMessageChunk(content=c, chunk_position=chunk_position)
            )

Domain

Subdomains

Frequently Asked Questions

What does _astream() do?
_astream() is a function in the langchain codebase, defined in libs/core/langchain_core/language_models/fake_chat_models.py.
Where is _astream() defined?
_astream() is defined in libs/core/langchain_core/language_models/fake_chat_models.py at line 124.

Analyze Your Own Codebase

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

Try Supermodel Free