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
  52d9a76c_826c_e2cd_136c_f0f928571807["_astream()"]
  1a5cd25a_9420_c6b2_ec8d_2b53c6427514["ChatFireworks"]
  52d9a76c_826c_e2cd_136c_f0f928571807 -->|defined in| 1a5cd25a_9420_c6b2_ec8d_2b53c6427514
  55737e4f_058c_81d8_55a7_4c05e4e31524["_agenerate()"]
  55737e4f_058c_81d8_55a7_4c05e4e31524 -->|calls| 52d9a76c_826c_e2cd_136c_f0f928571807
  db2ab649_5bf1_261f_34a0_aed78a625fdf["_create_message_dicts()"]
  52d9a76c_826c_e2cd_136c_f0f928571807 -->|calls| db2ab649_5bf1_261f_34a0_aed78a625fdf
  def2bd88_9f61_77d1_2fcb_e9dad1281a22["_convert_chunk_to_message_chunk()"]
  52d9a76c_826c_e2cd_136c_f0f928571807 -->|calls| def2bd88_9f61_77d1_2fcb_e9dad1281a22
  style 52d9a76c_826c_e2cd_136c_f0f928571807 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/fireworks/langchain_fireworks/chat_models.py lines 579–614

    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
        async for chunk in self.async_client.acreate(messages=message_dicts, **params):
            if not isinstance(chunk, dict):
                chunk = chunk.model_dump()
            if len(chunk["choices"]) == 0:
                continue
            choice = chunk["choices"][0]
            message_chunk = _convert_chunk_to_message_chunk(chunk, default_chunk_class)
            generation_info = {}
            if finish_reason := choice.get("finish_reason"):
                generation_info["finish_reason"] = finish_reason
                generation_info["model_name"] = self.model_name
            logprobs = choice.get("logprobs")
            if logprobs:
                generation_info["logprobs"] = logprobs
            default_chunk_class = message_chunk.__class__
            generation_chunk = ChatGenerationChunk(
                message=message_chunk, generation_info=generation_info or None
            )
            if run_manager:
                await run_manager.on_llm_new_token(
                    token=generation_chunk.text,
                    chunk=generation_chunk,
                    logprobs=logprobs,
                )
            yield generation_chunk

Domain

Subdomains

Called By

Frequently Asked Questions

What does _astream() do?
_astream() is a function in the langchain codebase, defined in libs/partners/fireworks/langchain_fireworks/chat_models.py.
Where is _astream() defined?
_astream() is defined in libs/partners/fireworks/langchain_fireworks/chat_models.py at line 579.
What does _astream() call?
_astream() calls 2 function(s): _convert_chunk_to_message_chunk, _create_message_dicts.
What calls _astream()?
_astream() is called by 1 function(s): _agenerate.

Analyze Your Own Codebase

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

Try Supermodel Free