Home / Function/ _load_chain_from_file() — langchain Function Reference

_load_chain_from_file() — langchain Function Reference

Architecture documentation for the _load_chain_from_file() function in loading.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  aa45d863_f749_1be3_f9f1_5ba87aa28e4f["_load_chain_from_file()"]
  61dd5a0b_3bf7_b973_6dac_edfd465b21fb["loading.py"]
  aa45d863_f749_1be3_f9f1_5ba87aa28e4f -->|defined in| 61dd5a0b_3bf7_b973_6dac_edfd465b21fb
  ab90e794_4e78_646b_dee9_e87a00250d94["load_chain()"]
  ab90e794_4e78_646b_dee9_e87a00250d94 -->|calls| aa45d863_f749_1be3_f9f1_5ba87aa28e4f
  7c915b91_f326_1908_9969_d0cb1f4f7e34["load_chain_from_config()"]
  aa45d863_f749_1be3_f9f1_5ba87aa28e4f -->|calls| 7c915b91_f326_1908_9969_d0cb1f4f7e34
  style aa45d863_f749_1be3_f9f1_5ba87aa28e4f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/loading.py lines 720–742

def _load_chain_from_file(file: str | Path, **kwargs: Any) -> Chain:
    """Load chain from file."""
    # Convert file to Path object.
    file_path = Path(file) if isinstance(file, str) else file
    # Load from either json or yaml.
    if file_path.suffix == ".json":
        with file_path.open() as f:
            config = json.load(f)
    elif file_path.suffix.endswith((".yaml", ".yml")):
        with file_path.open() as f:
            config = yaml.safe_load(f)
    else:
        msg = "File type must be json or yaml"
        raise ValueError(msg)

    # Override default 'verbose' and 'memory' for the chain
    if "verbose" in kwargs:
        config["verbose"] = kwargs.pop("verbose")
    if "memory" in kwargs:
        config["memory"] = kwargs.pop("memory")

    # Load the chain from the config now.
    return load_chain_from_config(config, **kwargs)

Subdomains

Called By

Frequently Asked Questions

What does _load_chain_from_file() do?
_load_chain_from_file() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/loading.py.
Where is _load_chain_from_file() defined?
_load_chain_from_file() is defined in libs/langchain/langchain_classic/chains/loading.py at line 720.
What does _load_chain_from_file() call?
_load_chain_from_file() calls 1 function(s): load_chain_from_config.
What calls _load_chain_from_file()?
_load_chain_from_file() is called by 1 function(s): load_chain.

Analyze Your Own Codebase

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

Try Supermodel Free