Home / Function/ __init__() — langchain Function Reference

__init__() — langchain Function Reference

Architecture documentation for the __init__() function in model_laboratory.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  faa83a0b_d5b8_28b7_b07c_725dc6ca4594["__init__()"]
  ddc55513_8bea_9f0f_9a07_33c17a0d376f["ModelLaboratory"]
  faa83a0b_d5b8_28b7_b07c_725dc6ca4594 -->|defined in| ddc55513_8bea_9f0f_9a07_33c17a0d376f
  962bae77_5dd8_f194_e1d3_68d9fbeb473e["from_llms()"]
  faa83a0b_d5b8_28b7_b07c_725dc6ca4594 -->|calls| 962bae77_5dd8_f194_e1d3_68d9fbeb473e
  style faa83a0b_d5b8_28b7_b07c_725dc6ca4594 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/model_laboratory.py lines 18–59

    def __init__(self, chains: Sequence[Chain], names: list[str] | None = None):
        """Initialize the ModelLaboratory with chains to experiment with.

        Args:
            chains: A sequence of chains to experiment with.
                Each chain must have exactly one input and one output variable.
            names: Optional list of names corresponding to each chain.
                If provided, its length must match the number of chains.


        Raises:
            ValueError: If any chain is not an instance of `Chain`.
            ValueError: If a chain does not have exactly one input variable.
            ValueError: If a chain does not have exactly one output variable.
            ValueError: If the length of `names` does not match the number of chains.
        """
        for chain in chains:
            if not isinstance(chain, Chain):
                msg = (  # type: ignore[unreachable]
                    "ModelLaboratory should now be initialized with Chains. "
                    "If you want to initialize with LLMs, use the `from_llms` method "
                    "instead (`ModelLaboratory.from_llms(...)`)"
                )
                raise ValueError(msg)  # noqa: TRY004
            if len(chain.input_keys) != 1:
                msg = (
                    "Currently only support chains with one input variable, "
                    f"got {chain.input_keys}"
                )
                raise ValueError(msg)
            if len(chain.output_keys) != 1:
                msg = (
                    "Currently only support chains with one output variable, "
                    f"got {chain.output_keys}"
                )
        if names is not None and len(names) != len(chains):
            msg = "Length of chains does not match length of names."
            raise ValueError(msg)
        self.chains = chains
        chain_range = [str(i) for i in range(len(self.chains))]
        self.chain_colors = get_color_mapping(chain_range)
        self.names = names

Domain

Subdomains

Calls

Frequently Asked Questions

What does __init__() do?
__init__() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/model_laboratory.py.
Where is __init__() defined?
__init__() is defined in libs/langchain/langchain_classic/model_laboratory.py at line 18.
What does __init__() call?
__init__() calls 1 function(s): from_llms.

Analyze Your Own Codebase

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

Try Supermodel Free