Home / Function/ _parse_model() — langchain Function Reference

_parse_model() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  7eee68b5_5eb8_bdd5_5fba_6ec2582ed403["_parse_model()"]
  1391827b_23f8_70f5_0b4d_987b860931b3["base.py"]
  7eee68b5_5eb8_bdd5_5fba_6ec2582ed403 -->|defined in| 1391827b_23f8_70f5_0b4d_987b860931b3
  7e83c5c7_e60c_4905_0c8c_4645f8596e5b["_init_chat_model_helper()"]
  7e83c5c7_e60c_4905_0c8c_4645f8596e5b -->|calls| 7eee68b5_5eb8_bdd5_5fba_6ec2582ed403
  87c2364a_8089_4489_2068_be483553a48a["_attempt_infer_model_provider()"]
  7eee68b5_5eb8_bdd5_5fba_6ec2582ed403 -->|calls| 87c2364a_8089_4489_2068_be483553a48a
  style 7eee68b5_5eb8_bdd5_5fba_6ec2582ed403 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chat_models/base.py lines 603–630

def _parse_model(model: str, model_provider: str | None) -> tuple[str, str]:
    """Parse model name and provider, inferring provider if necessary."""
    if not model_provider and ":" in model:
        prefix, suffix = model.split(":", 1)
        if prefix in _SUPPORTED_PROVIDERS:
            model_provider = prefix
            model = suffix
        else:
            inferred = _attempt_infer_model_provider(prefix)
            if inferred:
                model_provider = inferred
                model = suffix

    model_provider = model_provider or _attempt_infer_model_provider(model)
    if not model_provider:
        supported_list = ", ".join(sorted(_SUPPORTED_PROVIDERS))
        msg = (
            f"Unable to infer model provider for {model=}. "
            f"Please specify 'model_provider' directly.\n\n"
            f"Supported providers: {supported_list}\n\n"
            f"For help with specific providers, see: "
            f"https://docs.langchain.com/oss/python/integrations/providers"
        )
        raise ValueError(msg)

    # Normalize provider name
    model_provider = model_provider.replace("-", "_").lower()
    return model, model_provider

Domain

Subdomains

Frequently Asked Questions

What does _parse_model() do?
_parse_model() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chat_models/base.py.
Where is _parse_model() defined?
_parse_model() is defined in libs/langchain/langchain_classic/chat_models/base.py at line 603.
What does _parse_model() call?
_parse_model() calls 1 function(s): _attempt_infer_model_provider.
What calls _parse_model()?
_parse_model() is called by 1 function(s): _init_chat_model_helper.

Analyze Your Own Codebase

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

Try Supermodel Free