Home / Function/ _should_stream_usage() — langchain Function Reference

_should_stream_usage() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/chat_models/base.py lines 1285–1302

    def _should_stream_usage(
        self, stream_usage: bool | None = None, **kwargs: Any
    ) -> bool:
        """Determine whether to include usage metadata in streaming output.

        For backwards compatibility, we check for `stream_options` passed
        explicitly to kwargs or in the `model_kwargs` and override `self.stream_usage`.
        """
        stream_usage_sources = [  # order of precedence
            stream_usage,
            kwargs.get("stream_options", {}).get("include_usage"),
            self.model_kwargs.get("stream_options", {}).get("include_usage"),
            self.stream_usage,
        ]
        for source in stream_usage_sources:
            if isinstance(source, bool):
                return source
        return self.stream_usage or False

Domain

Subdomains

Frequently Asked Questions

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