Home / Function/ with_config() — langchain Function Reference

with_config() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  b32190e9_dc8d_06e8_042b_1bf06cc182ad["with_config()"]
  70048a7c_06ac_54dc_f2cc_70cbfa8bcbc9["_ConfigurableModel"]
  b32190e9_dc8d_06e8_042b_1bf06cc182ad -->|defined in| 70048a7c_06ac_54dc_f2cc_70cbfa8bcbc9
  0063b450_c21c_b257_9b29_feae30b816b4["_model_params()"]
  b32190e9_dc8d_06e8_042b_1bf06cc182ad -->|calls| 0063b450_c21c_b257_9b29_feae30b816b4
  style b32190e9_dc8d_06e8_042b_1bf06cc182ad fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chat_models/base.py lines 720–750

    def with_config(
        self,
        config: RunnableConfig | None = None,
        **kwargs: Any,
    ) -> _ConfigurableModel:
        """Bind config to a `Runnable`, returning a new `Runnable`."""
        config = RunnableConfig(**(config or {}), **cast("RunnableConfig", kwargs))
        model_params = self._model_params(config)
        remaining_config = {k: v for k, v in config.items() if k != "configurable"}
        remaining_config["configurable"] = {
            k: v
            for k, v in config.get("configurable", {}).items()
            if k.removeprefix(self._config_prefix) not in model_params
        }
        queued_declarative_operations = list(self._queued_declarative_operations)
        if remaining_config:
            queued_declarative_operations.append(
                (
                    "with_config",
                    (),
                    {"config": remaining_config},
                ),
            )
        return _ConfigurableModel(
            default_config={**self._default_config, **model_params},
            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,
        )

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free