Home / Function/ _init_chat_model_helper() — langchain Function Reference

_init_chat_model_helper() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  7e83c5c7_e60c_4905_0c8c_4645f8596e5b["_init_chat_model_helper()"]
  1391827b_23f8_70f5_0b4d_987b860931b3["base.py"]
  7e83c5c7_e60c_4905_0c8c_4645f8596e5b -->|defined in| 1391827b_23f8_70f5_0b4d_987b860931b3
  b52e4630_a9ff_cc79_c4f8_5c0914c73656["init_chat_model()"]
  b52e4630_a9ff_cc79_c4f8_5c0914c73656 -->|calls| 7e83c5c7_e60c_4905_0c8c_4645f8596e5b
  1ec96341_0cad_d4df_0b5f_401dfd4ccd5a["_model()"]
  1ec96341_0cad_d4df_0b5f_401dfd4ccd5a -->|calls| 7e83c5c7_e60c_4905_0c8c_4645f8596e5b
  7eee68b5_5eb8_bdd5_5fba_6ec2582ed403["_parse_model()"]
  7e83c5c7_e60c_4905_0c8c_4645f8596e5b -->|calls| 7eee68b5_5eb8_bdd5_5fba_6ec2582ed403
  598db547_be59_757f_1f1a_e1ba3ef6e690["_check_pkg()"]
  7e83c5c7_e60c_4905_0c8c_4645f8596e5b -->|calls| 598db547_be59_757f_1f1a_e1ba3ef6e690
  style 7e83c5c7_e60c_4905_0c8c_4645f8596e5b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chat_models/base.py lines 372–506

def _init_chat_model_helper(
    model: str,
    *,
    model_provider: str | None = None,
    **kwargs: Any,
) -> BaseChatModel:
    model, model_provider = _parse_model(model, model_provider)
    if model_provider == "openai":
        _check_pkg("langchain_openai", "ChatOpenAI")
        from langchain_openai import ChatOpenAI

        return ChatOpenAI(model=model, **kwargs)
    if model_provider == "anthropic":
        _check_pkg("langchain_anthropic", "ChatAnthropic")
        from langchain_anthropic import ChatAnthropic

        return ChatAnthropic(model=model, **kwargs)  # type: ignore[call-arg,unused-ignore]
    if model_provider == "azure_openai":
        _check_pkg("langchain_openai", "AzureChatOpenAI")
        from langchain_openai import AzureChatOpenAI

        return AzureChatOpenAI(model=model, **kwargs)
    if model_provider == "azure_ai":
        _check_pkg("langchain_azure_ai", "AzureAIChatCompletionsModel")
        from langchain_azure_ai.chat_models import AzureAIChatCompletionsModel

        return AzureAIChatCompletionsModel(model=model, **kwargs)
    if model_provider == "cohere":
        _check_pkg("langchain_cohere", "ChatCohere")
        from langchain_cohere import ChatCohere

        return ChatCohere(model=model, **kwargs)
    if model_provider == "google_vertexai":
        _check_pkg("langchain_google_vertexai", "ChatVertexAI")
        from langchain_google_vertexai import ChatVertexAI

        return ChatVertexAI(model=model, **kwargs)
    if model_provider == "google_genai":
        _check_pkg("langchain_google_genai", "ChatGoogleGenerativeAI")
        from langchain_google_genai import ChatGoogleGenerativeAI

        return ChatGoogleGenerativeAI(model=model, **kwargs)
    if model_provider == "fireworks":
        _check_pkg("langchain_fireworks", "ChatFireworks")
        from langchain_fireworks import ChatFireworks

        return ChatFireworks(model=model, **kwargs)
    if model_provider == "ollama":
        try:
            _check_pkg("langchain_ollama", "ChatOllama")
            from langchain_ollama import ChatOllama
        except ImportError:
            # For backwards compatibility
            try:
                _check_pkg("langchain_community", "ChatOllama")
                from langchain_community.chat_models import ChatOllama
            except ImportError:
                # If both langchain-ollama and langchain-community aren't available,
                # raise an error related to langchain-ollama
                _check_pkg("langchain_ollama", "ChatOllama")

        return ChatOllama(model=model, **kwargs)
    if model_provider == "together":
        _check_pkg("langchain_together", "ChatTogether")
        from langchain_together import ChatTogether

        return ChatTogether(model=model, **kwargs)
    if model_provider == "mistralai":
        _check_pkg("langchain_mistralai", "ChatMistralAI")
        from langchain_mistralai import ChatMistralAI

        return ChatMistralAI(model=model, **kwargs)  # type: ignore[call-arg,unused-ignore]

    if model_provider == "huggingface":
        _check_pkg("langchain_huggingface", "ChatHuggingFace")
        from langchain_huggingface import ChatHuggingFace

        return ChatHuggingFace.from_model_id(model_id=model, **kwargs)

    if model_provider == "groq":
        _check_pkg("langchain_groq", "ChatGroq")

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free