Home / Function/ _astream() — langchain Function Reference

_astream() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  2a12b41b_5f2f_1d13_ac98_5c73c67a29ff["_astream()"]
  24cf3ac3_ed46_66ab_27f4_5b5d67f0b7f0["ChatMistralAI"]
  2a12b41b_5f2f_1d13_ac98_5c73c67a29ff -->|defined in| 24cf3ac3_ed46_66ab_27f4_5b5d67f0b7f0
  ef431007_0264_4d4c_0b4c_b5b637d2ca3e["_create_message_dicts()"]
  2a12b41b_5f2f_1d13_ac98_5c73c67a29ff -->|calls| ef431007_0264_4d4c_0b4c_b5b637d2ca3e
  8db35ed5_08a5_0e78_5859_838dd98768d9["acompletion_with_retry()"]
  2a12b41b_5f2f_1d13_ac98_5c73c67a29ff -->|calls| 8db35ed5_08a5_0e78_5859_838dd98768d9
  9cea4c61_6da2_2189_e0c5_dded567deba4["_convert_chunk_to_message_chunk()"]
  2a12b41b_5f2f_1d13_ac98_5c73c67a29ff -->|calls| 9cea4c61_6da2_2189_e0c5_dded567deba4
  style 2a12b41b_5f2f_1d13_ac98_5c73c67a29ff fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/mistralai/langchain_mistralai/chat_models.py lines 739–767

    async def _astream(
        self,
        messages: list[BaseMessage],
        stop: list[str] | None = None,
        run_manager: AsyncCallbackManagerForLLMRun | None = None,
        **kwargs: Any,
    ) -> AsyncIterator[ChatGenerationChunk]:
        message_dicts, params = self._create_message_dicts(messages, stop)
        params = {**params, **kwargs, "stream": True}

        default_chunk_class: type[BaseMessageChunk] = AIMessageChunk
        index = -1
        index_type = ""
        async for chunk in await acompletion_with_retry(
            self, messages=message_dicts, run_manager=run_manager, **params
        ):
            if len(chunk.get("choices", [])) == 0:
                continue
            new_chunk, index, index_type = _convert_chunk_to_message_chunk(
                chunk, default_chunk_class, index, index_type, self.output_version
            )
            # make future chunks same type as first chunk
            default_chunk_class = new_chunk.__class__
            gen_chunk = ChatGenerationChunk(message=new_chunk)
            if run_manager:
                await run_manager.on_llm_new_token(
                    token=cast("str", new_chunk.content), chunk=gen_chunk
                )
            yield gen_chunk

Domain

Subdomains

Frequently Asked Questions

What does _astream() do?
_astream() is a function in the langchain codebase, defined in libs/partners/mistralai/langchain_mistralai/chat_models.py.
Where is _astream() defined?
_astream() is defined in libs/partners/mistralai/langchain_mistralai/chat_models.py at line 739.
What does _astream() call?
_astream() calls 3 function(s): _convert_chunk_to_message_chunk, _create_message_dicts, acompletion_with_retry.

Analyze Your Own Codebase

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

Try Supermodel Free