Home / Function/ _inherit_llm_properties() — langchain Function Reference

_inherit_llm_properties() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  4162a68a_ca20_7d28_a313_602aca692d0f["_inherit_llm_properties()"]
  8cf0d6c0_abf8_3ee2_fd00_8bfc8c02058a["ChatHuggingFace"]
  4162a68a_ca20_7d28_a313_602aca692d0f -->|defined in| 8cf0d6c0_abf8_3ee2_fd00_8bfc8c02058a
  8ac960fc_fbc0_6865_20cb_72e7b4885586["__init__()"]
  8ac960fc_fbc0_6865_20cb_72e7b4885586 -->|calls| 4162a68a_ca20_7d28_a313_602aca692d0f
  2b662de8_c3da_0d48_1bc1_b88b1d6c6022["_is_huggingface_endpoint()"]
  4162a68a_ca20_7d28_a313_602aca692d0f -->|calls| 2b662de8_c3da_0d48_1bc1_b88b1d6c6022
  style 4162a68a_ca20_7d28_a313_602aca692d0f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py lines 538–581

    def _inherit_llm_properties(self) -> None:
        """Inherit properties from the wrapped LLM instance if not explicitly set."""
        if not hasattr(self, "llm") or self.llm is None:
            return

        # Map of ChatHuggingFace properties to LLM properties
        property_mappings = {
            "temperature": "temperature",
            "max_tokens": "max_new_tokens",  # Different naming convention
            "top_p": "top_p",
            "seed": "seed",
            "streaming": "streaming",
            "stop": "stop_sequences",
        }

        # Inherit properties from LLM and not explicitly set here
        for chat_prop, llm_prop in property_mappings.items():
            if hasattr(self.llm, llm_prop):
                llm_value = getattr(self.llm, llm_prop)
                chat_value = getattr(self, chat_prop, None)
                if not chat_value and llm_value:
                    setattr(self, chat_prop, llm_value)

        # Handle special cases for HuggingFaceEndpoint
        if _is_huggingface_endpoint(self.llm):
            # Inherit additional HuggingFaceEndpoint specific properties
            endpoint_mappings = {
                "frequency_penalty": "repetition_penalty",
            }

            for chat_prop, llm_prop in endpoint_mappings.items():
                if hasattr(self.llm, llm_prop):
                    llm_value = getattr(self.llm, llm_prop)
                    chat_value = getattr(self, chat_prop, None)
                    if chat_value is None and llm_value is not None:
                        setattr(self, chat_prop, llm_value)

        # Inherit model_kwargs if not explicitly set
        if (
            not self.model_kwargs
            and hasattr(self.llm, "model_kwargs")
            and isinstance(self.llm.model_kwargs, dict)
        ):
            self.model_kwargs = self.llm.model_kwargs.copy()

Domain

Subdomains

Called By

Frequently Asked Questions

What does _inherit_llm_properties() do?
_inherit_llm_properties() is a function in the langchain codebase, defined in libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py.
Where is _inherit_llm_properties() defined?
_inherit_llm_properties() is defined in libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py at line 538.
What does _inherit_llm_properties() call?
_inherit_llm_properties() calls 1 function(s): _is_huggingface_endpoint.
What calls _inherit_llm_properties()?
_inherit_llm_properties() is called by 1 function(s): __init__.

Analyze Your Own Codebase

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

Try Supermodel Free