Home / Function/ _stream() — langchain Function Reference

_stream() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  8b0f62ae_050c_e797_302b_3cbbf84976ba["_stream()"]
  2790c9e0_a72e_5aac_c2c7_6702139c50e3["FakeListChatModel"]
  8b0f62ae_050c_e797_302b_3cbbf84976ba -->|defined in| 2790c9e0_a72e_5aac_c2c7_6702139c50e3
  576f6581_ce6e_5e34_ec34_a77e605e8814["_stream()"]
  576f6581_ce6e_5e34_ec34_a77e605e8814 -->|calls| 8b0f62ae_050c_e797_302b_3cbbf84976ba
  576f6581_ce6e_5e34_ec34_a77e605e8814["_stream()"]
  8b0f62ae_050c_e797_302b_3cbbf84976ba -->|calls| 576f6581_ce6e_5e34_ec34_a77e605e8814
  style 8b0f62ae_050c_e797_302b_3cbbf84976ba fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/language_models/fake_chat_models.py lines 95–121

    def _stream(
        self,
        messages: list[BaseMessage],
        stop: list[str] | None = None,
        run_manager: CallbackManagerForLLMRun | None = None,
        **kwargs: Any,
    ) -> Iterator[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:
                time.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

Calls

Called By

Frequently Asked Questions

What does _stream() do?
_stream() is a function in the langchain codebase, defined in libs/core/langchain_core/language_models/fake_chat_models.py.
Where is _stream() defined?
_stream() is defined in libs/core/langchain_core/language_models/fake_chat_models.py at line 95.
What does _stream() call?
_stream() calls 1 function(s): _stream.
What calls _stream()?
_stream() is called by 1 function(s): _stream.

Analyze Your Own Codebase

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

Try Supermodel Free