Home / Function/ _stream_response_to_generation_chunk() — langchain Function Reference

_stream_response_to_generation_chunk() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  15d3c1cb_a282_c6f2_5db8_1d781bb37535["_stream_response_to_generation_chunk()"]
  bcd5af42_a82b_f85e_ed42_ee1d1f435ba0["base.py"]
  15d3c1cb_a282_c6f2_5db8_1d781bb37535 -->|defined in| bcd5af42_a82b_f85e_ed42_ee1d1f435ba0
  9a3f8476_ed23_4017_8e21_6ee0b6176365["_stream()"]
  9a3f8476_ed23_4017_8e21_6ee0b6176365 -->|calls| 15d3c1cb_a282_c6f2_5db8_1d781bb37535
  58b8669b_d421_b6e5_b179_03394129fd02["_astream()"]
  58b8669b_d421_b6e5_b179_03394129fd02 -->|calls| 15d3c1cb_a282_c6f2_5db8_1d781bb37535
  style 15d3c1cb_a282_c6f2_5db8_1d781bb37535 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/llms/base.py lines 38–50

def _stream_response_to_generation_chunk(
    stream_response: dict[str, Any],
) -> GenerationChunk:
    """Convert a stream response to a generation chunk."""
    if not stream_response["choices"]:
        return GenerationChunk(text="")
    return GenerationChunk(
        text=stream_response["choices"][0]["text"] or "",
        generation_info={
            "finish_reason": stream_response["choices"][0].get("finish_reason", None),
            "logprobs": stream_response["choices"][0].get("logprobs", None),
        },
    )

Domain

Subdomains

Frequently Asked Questions

What does _stream_response_to_generation_chunk() do?
_stream_response_to_generation_chunk() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/llms/base.py.
Where is _stream_response_to_generation_chunk() defined?
_stream_response_to_generation_chunk() is defined in libs/partners/openai/langchain_openai/llms/base.py at line 38.
What calls _stream_response_to_generation_chunk()?
_stream_response_to_generation_chunk() 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