Home / Function/ __getattr__() — langchain Function Reference

__getattr__() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  a151b267_f487_21b9_9e45_d63f30a41994["__getattr__()"]
  70048a7c_06ac_54dc_f2cc_70cbfa8bcbc9["_ConfigurableModel"]
  a151b267_f487_21b9_9e45_d63f30a41994 -->|defined in| 70048a7c_06ac_54dc_f2cc_70cbfa8bcbc9
  1ec96341_0cad_d4df_0b5f_401dfd4ccd5a["_model()"]
  a151b267_f487_21b9_9e45_d63f30a41994 -->|calls| 1ec96341_0cad_d4df_0b5f_401dfd4ccd5a
  style a151b267_f487_21b9_9e45_d63f30a41994 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chat_models/base.py lines 670–698

    def __getattr__(self, name: str) -> Any:
        if name in _DECLARATIVE_METHODS:
            # Declarative operations that cannot be applied until after an actual model
            # object is instantiated. So instead of returning the actual operation,
            # we record the operation and its arguments in a queue. This queue is
            # then applied in order whenever we actually instantiate the model (in
            # self._model()).
            def queue(*args: Any, **kwargs: Any) -> _ConfigurableModel:
                queued_declarative_operations = list(
                    self._queued_declarative_operations,
                )
                queued_declarative_operations.append((name, args, kwargs))
                return _ConfigurableModel(
                    default_config=dict(self._default_config),
                    configurable_fields=list(self._configurable_fields)
                    if isinstance(self._configurable_fields, list)
                    else self._configurable_fields,
                    config_prefix=self._config_prefix,
                    queued_declarative_operations=queued_declarative_operations,
                )

            return queue
        if self._default_config and (model := self._model()) and hasattr(model, name):
            return getattr(model, name)
        msg = f"{name} is not a BaseChatModel attribute"
        if self._default_config:
            msg += " and is not implemented on the default model"
        msg += "."
        raise AttributeError(msg)

Domain

Subdomains

Calls

Frequently Asked Questions

What does __getattr__() do?
__getattr__() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chat_models/base.py.
Where is __getattr__() defined?
__getattr__() is defined in libs/langchain/langchain_classic/chat_models/base.py at line 670.
What does __getattr__() call?
__getattr__() calls 1 function(s): _model.

Analyze Your Own Codebase

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

Try Supermodel Free