Home / Function/ _get_chat_model_creator() — langchain Function Reference

_get_chat_model_creator() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  f789b310_4d83_1f92_6308_7e4a7c84255b["_get_chat_model_creator()"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73["base.py"]
  f789b310_4d83_1f92_6308_7e4a7c84255b -->|defined in| 0dc60931_4ce3_cfa4_06b1_e0f8b1869e73
  7029a671_2a91_97a5_f6ff_7708a55ef68a["_init_chat_model_helper()"]
  7029a671_2a91_97a5_f6ff_7708a55ef68a -->|calls| f789b310_4d83_1f92_6308_7e4a7c84255b
  9afc100b_d234_fc71_f9a4_299636599405["_import_module()"]
  f789b310_4d83_1f92_6308_7e4a7c84255b -->|calls| 9afc100b_d234_fc71_f9a4_299636599405
  style f789b310_4d83_1f92_6308_7e4a7c84255b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/chat_models/base.py lines 127–167

def _get_chat_model_creator(
    provider: str,
) -> Callable[..., BaseChatModel]:
    """Return a factory function that creates a chat model for the given provider.

    This function is cached to avoid repeated module imports.

    Args:
        provider: The name of the model provider (e.g., `'openai'`, `'anthropic'`).

            Must be a key in `_BUILTIN_PROVIDERS`.

    Returns:
        A callable that accepts model kwargs and returns a `BaseChatModel` instance for
            the specified provider.

    Raises:
        ValueError: If the provider is not in `_BUILTIN_PROVIDERS`.
        ImportError: If the provider's integration package is not installed.
    """
    if provider not in _BUILTIN_PROVIDERS:
        supported = ", ".join(_BUILTIN_PROVIDERS.keys())
        msg = f"Unsupported {provider=}.\n\nSupported model providers are: {supported}"
        raise ValueError(msg)

    pkg, class_name, creator_func = _BUILTIN_PROVIDERS[provider]
    try:
        module = _import_module(pkg, class_name)
    except ImportError as e:
        if provider != "ollama":
            raise
        # For backwards compatibility
        try:
            module = _import_module("langchain_community.chat_models", class_name)
        except ImportError:
            # If both langchain-ollama and langchain-community aren't available,
            # raise an error related to langchain-ollama
            raise e from None

    cls = getattr(module, class_name)
    return functools.partial(creator_func, cls=cls)

Domain

Subdomains

Frequently Asked Questions

What does _get_chat_model_creator() do?
_get_chat_model_creator() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/chat_models/base.py.
Where is _get_chat_model_creator() defined?
_get_chat_model_creator() is defined in libs/langchain_v1/langchain/chat_models/base.py at line 127.
What does _get_chat_model_creator() call?
_get_chat_model_creator() calls 1 function(s): _import_module.
What calls _get_chat_model_creator()?
_get_chat_model_creator() 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