Home / Function/ _parse_model_string() — langchain Function Reference

_parse_model_string() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  6736cae9_5ddc_f2a5_4634_a756a7d2c58c["_parse_model_string()"]
  76380b72_77fe_25f0_4fc9_0d116ee2433c["base.py"]
  6736cae9_5ddc_f2a5_4634_a756a7d2c58c -->|defined in| 76380b72_77fe_25f0_4fc9_0d116ee2433c
  e9cf050d_cf9c_221c_0569_7b52c7831196["_infer_model_and_provider()"]
  e9cf050d_cf9c_221c_0569_7b52c7831196 -->|calls| 6736cae9_5ddc_f2a5_4634_a756a7d2c58c
  80a66df6_2383_888c_83e7_83324720ae54["_get_provider_list()"]
  6736cae9_5ddc_f2a5_4634_a756a7d2c58c -->|calls| 80a66df6_2383_888c_83e7_83324720ae54
  style 6736cae9_5ddc_f2a5_4634_a756a7d2c58c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/embeddings/base.py lines 28–80

def _parse_model_string(model_name: str) -> tuple[str, str]:
    """Parse a model string into provider and model name components.

    The model string should be in the format 'provider:model-name', where provider
    is one of the supported providers.

    Args:
        model_name: A model string in the format 'provider:model-name'

    Returns:
        A tuple of (provider, model_name)

    ```python
    _parse_model_string("openai:text-embedding-3-small")
    # Returns: ("openai", "text-embedding-3-small")

    _parse_model_string("bedrock:amazon.titan-embed-text-v1")
    # Returns: ("bedrock", "amazon.titan-embed-text-v1")
    ```

    Raises:
        ValueError: If the model string is not in the correct format or
            the provider is unsupported

    """
    if ":" not in model_name:
        providers = _SUPPORTED_PROVIDERS
        msg = (
            f"Invalid model format '{model_name}'.\n"
            f"Model name must be in format 'provider:model-name'\n"
            f"Example valid model strings:\n"
            f"  - openai:text-embedding-3-small\n"
            f"  - bedrock:amazon.titan-embed-text-v1\n"
            f"  - cohere:embed-english-v3.0\n"
            f"Supported providers: {providers}"
        )
        raise ValueError(msg)

    provider, model = model_name.split(":", 1)
    provider = provider.lower().strip()
    model = model.strip()

    if provider not in _SUPPORTED_PROVIDERS:
        msg = (
            f"Provider '{provider}' is not supported.\n"
            f"Supported providers and their required packages:\n"
            f"{_get_provider_list()}"
        )
        raise ValueError(msg)
    if not model:
        msg = "Model name cannot be empty"
        raise ValueError(msg)
    return provider, model

Domain

Subdomains

Frequently Asked Questions

What does _parse_model_string() do?
_parse_model_string() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/embeddings/base.py.
Where is _parse_model_string() defined?
_parse_model_string() is defined in libs/langchain/langchain_classic/embeddings/base.py at line 28.
What does _parse_model_string() call?
_parse_model_string() calls 1 function(s): _get_provider_list.
What calls _parse_model_string()?
_parse_model_string() is called by 1 function(s): _infer_model_and_provider.

Analyze Your Own Codebase

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

Try Supermodel Free