Home / Function/ _get_generation_chunk_from_completion() — langchain Function Reference

_get_generation_chunk_from_completion() — langchain Function Reference

Architecture documentation for the _get_generation_chunk_from_completion() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2d1ed7ab_3dc5_34eb_9bfb_4f79c345fc6b["_get_generation_chunk_from_completion()"]
  2a683305_667b_3567_cab9_9f77e29d4afa["BaseChatOpenAI"]
  2d1ed7ab_3dc5_34eb_9bfb_4f79c345fc6b -->|defined in| 2a683305_667b_3567_cab9_9f77e29d4afa
  eee344d5_cb34_d6fa_ca18_010bbd1e6cd0["_stream()"]
  eee344d5_cb34_d6fa_ca18_010bbd1e6cd0 -->|calls| 2d1ed7ab_3dc5_34eb_9bfb_4f79c345fc6b
  47573e6b_689c_1e1b_b035_1aee9c3d3bba["_astream()"]
  47573e6b_689c_1e1b_b035_1aee9c3d3bba -->|calls| 2d1ed7ab_3dc5_34eb_9bfb_4f79c345fc6b
  64924e61_d0ac_6bbf_4818_aeb51576556d["_create_chat_result()"]
  2d1ed7ab_3dc5_34eb_9bfb_4f79c345fc6b -->|calls| 64924e61_d0ac_6bbf_4818_aeb51576556d
  style 2d1ed7ab_3dc5_34eb_9bfb_4f79c345fc6b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/chat_models/base.py lines 2239–2259

    def _get_generation_chunk_from_completion(
        self, completion: openai.BaseModel
    ) -> ChatGenerationChunk:
        """Get chunk from completion (e.g., from final completion of a stream)."""
        chat_result = self._create_chat_result(completion)
        chat_message = chat_result.generations[0].message
        if isinstance(chat_message, AIMessage):
            usage_metadata = chat_message.usage_metadata
            # Skip tool_calls, already sent as chunks
            if "tool_calls" in chat_message.additional_kwargs:
                chat_message.additional_kwargs.pop("tool_calls")
        else:
            usage_metadata = None
        message = AIMessageChunk(
            content="",
            additional_kwargs=chat_message.additional_kwargs,
            usage_metadata=usage_metadata,
        )
        return ChatGenerationChunk(
            message=message, generation_info=chat_result.llm_output
        )

Domain

Subdomains

Frequently Asked Questions

What does _get_generation_chunk_from_completion() do?
_get_generation_chunk_from_completion() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/base.py.
Where is _get_generation_chunk_from_completion() defined?
_get_generation_chunk_from_completion() is defined in libs/partners/openai/langchain_openai/chat_models/base.py at line 2239.
What does _get_generation_chunk_from_completion() call?
_get_generation_chunk_from_completion() calls 1 function(s): _create_chat_result.
What calls _get_generation_chunk_from_completion()?
_get_generation_chunk_from_completion() is called by 2 function(s): _astream, _stream.

Analyze Your Own Codebase

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

Try Supermodel Free