Home / Function/ _should_stream_usage() — langchain Function Reference

_should_stream_usage() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  9722f3bb_f150_918c_aa80_b6c7608bdffa["_should_stream_usage()"]
  8cf0d6c0_abf8_3ee2_fd00_8bfc8c02058a["ChatHuggingFace"]
  9722f3bb_f150_918c_aa80_b6c7608bdffa -->|defined in| 8cf0d6c0_abf8_3ee2_fd00_8bfc8c02058a
  ced9b52f_7bf4_4dc3_bc59_a48a9563d9bc["_stream()"]
  ced9b52f_7bf4_4dc3_bc59_a48a9563d9bc -->|calls| 9722f3bb_f150_918c_aa80_b6c7608bdffa
  5b8bd0f7_fb8d_1d6b_224f_9245b077cec2["_astream()"]
  5b8bd0f7_fb8d_1d6b_224f_9245b077cec2 -->|calls| 9722f3bb_f150_918c_aa80_b6c7608bdffa
  style 9722f3bb_f150_918c_aa80_b6c7608bdffa fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py lines 803–820

    def _should_stream_usage(
        self, *, stream_usage: bool | None = None, **kwargs: Any
    ) -> bool | None:
        """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

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/huggingface/langchain_huggingface/chat_models/huggingface.py.
Where is _should_stream_usage() defined?
_should_stream_usage() is defined in libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py at line 803.
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