Home / Function/ _attempt_infer_model_provider() — langchain Function Reference

_attempt_infer_model_provider() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/langchain/langchain_classic/chat_models/base.py lines 534–600

def _attempt_infer_model_provider(model_name: str) -> str | None:
    """Attempt to infer model provider from model name.

    Args:
        model_name: The name of the model to infer provider for.

    Returns:
        The inferred provider name, or `None` if no provider could be inferred.
    """
    model_lower = model_name.lower()

    # OpenAI models (including newer models and aliases)
    if any(
        model_lower.startswith(pre)
        for pre in (
            "gpt-",
            "o1",
            "o3",
            "chatgpt",
            "text-davinci",
        )
    ):
        return "openai"

    # Anthropic models
    if model_lower.startswith("claude"):
        return "anthropic"

    # Cohere models
    if model_lower.startswith("command"):
        return "cohere"

    # Fireworks models
    if model_name.startswith("accounts/fireworks"):
        return "fireworks"

    # Google models
    if model_lower.startswith("gemini"):
        return "google_vertexai"

    # AWS Bedrock models
    if model_name.startswith("amazon.") or model_lower.startswith(
        ("anthropic.", "meta.")
    ):
        return "bedrock"

    # Mistral models
    if model_lower.startswith(("mistral", "mixtral")):
        return "mistralai"

    # DeepSeek models
    if model_lower.startswith("deepseek"):
        return "deepseek"

    # xAI models
    if model_lower.startswith("grok"):
        return "xai"

    # Perplexity models
    if model_lower.startswith("sonar"):
        return "perplexity"

    # Upstage models
    if model_lower.startswith("solar"):
        return "upstage"

    return None

Domain

Subdomains

Called By

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free