Home / File/ base.py — langchain Source File

base.py — langchain Source File

Architecture documentation for base.py, a python file in the langchain codebase. 15 imports, 0 dependents.

File python LangChainCore LanguageModelBase 15 imports 9 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73["base.py"]
  f46e1812_79f8_1bd0_7815_2ba4471dc470["functools"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> f46e1812_79f8_1bd0_7815_2ba4471dc470
  3b5ab66f_4fcb_ca7c_bc35_2244b5f521fc["importlib"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> 3b5ab66f_4fcb_ca7c_bc35_2244b5f521fc
  f3365e3c_fb7a_bb9a_bc79_059b06cb7024["warnings"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> f3365e3c_fb7a_bb9a_bc79_059b06cb7024
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> feec1ec4_6917_867b_d228_b134d0ff8099
  e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> e929cf21_6ab8_6ff3_3765_0d35a099a053
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  b9f9a99f_aaea_6efd_1322_fc2c11bdc4b4["langchain_core.prompt_values"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> b9f9a99f_aaea_6efd_1322_fc2c11bdc4b4
  31eab4ab_7281_1e6c_b17d_12e6ad9de07a["langchain_core.runnables"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> 31eab4ab_7281_1e6c_b17d_12e6ad9de07a
  f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> f85fae70_1011_eaec_151c_4083140ae9e5
  2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> 2bf6d401_816d_d011_3b05_a6114f55ff58
  8322cf04_5861_9d4a_4ee9_a22829f66390["types"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> 8322cf04_5861_9d4a_4ee9_a22829f66390
  af90fc2c_3c61_2df1_8872_39a3a5dd6661["langchain_core.runnables.schema"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> af90fc2c_3c61_2df1_8872_39a3a5dd6661
  121262a1_0bd6_d637_bce3_307ab6b3ecd4["langchain_core.tools"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> 121262a1_0bd6_d637_bce3_307ab6b3ecd4
  a97731eb_2687_2ded_3d3a_a8c897824c1f["langchain_core.tracers"]
  0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 --> a97731eb_2687_2ded_3d3a_a8c897824c1f
  style 0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Factory functions for chat models."""

from __future__ import annotations

import functools
import importlib
import warnings
from typing import (
    TYPE_CHECKING,
    Any,
    Literal,
    TypeAlias,
    cast,
    overload,
)

from langchain_core.language_models import BaseChatModel, LanguageModelInput
from langchain_core.messages import AIMessage, AnyMessage
from langchain_core.prompt_values import ChatPromptValueConcrete, StringPromptValue
from langchain_core.runnables import Runnable, RunnableConfig, ensure_config
from typing_extensions import override

if TYPE_CHECKING:
    from collections.abc import AsyncIterator, Callable, Iterator, Sequence
    from types import ModuleType

    from langchain_core.runnables.schema import StreamEvent
    from langchain_core.tools import BaseTool
    from langchain_core.tracers import RunLog, RunLogPatch
    from pydantic import BaseModel


def _call(cls: type[BaseChatModel], **kwargs: Any) -> BaseChatModel:
    # TODO: replace with operator.call when lower bounding to Python 3.11
    return cls(**kwargs)


_BUILTIN_PROVIDERS: dict[str, tuple[str, str, Callable[..., BaseChatModel]]] = {
    "anthropic": ("langchain_anthropic", "ChatAnthropic", _call),
    "azure_ai": ("langchain_azure_ai.chat_models", "AzureAIChatCompletionsModel", _call),
    "azure_openai": ("langchain_openai", "AzureChatOpenAI", _call),
    "bedrock": ("langchain_aws", "ChatBedrock", _call),
    "bedrock_converse": ("langchain_aws", "ChatBedrockConverse", _call),
    "cohere": ("langchain_cohere", "ChatCohere", _call),
    "deepseek": ("langchain_deepseek", "ChatDeepSeek", _call),
    "fireworks": ("langchain_fireworks", "ChatFireworks", _call),
    "google_anthropic_vertex": (
        "langchain_google_vertexai.model_garden",
        "ChatAnthropicVertex",
        _call,
    ),
    "google_genai": ("langchain_google_genai", "ChatGoogleGenerativeAI", _call),
    "google_vertexai": ("langchain_google_vertexai", "ChatVertexAI", _call),
    "groq": ("langchain_groq", "ChatGroq", _call),
    "huggingface": (
        "langchain_huggingface",
        "ChatHuggingFace",
        lambda cls, model, **kwargs: cls.from_model_id(model_id=model, **kwargs),
    ),
    "ibm": (
// ... (935 more lines)

Domain

Subdomains

Dependencies

  • collections.abc
  • functools
  • importlib
  • langchain_core.language_models
  • langchain_core.messages
  • langchain_core.prompt_values
  • langchain_core.runnables
  • langchain_core.runnables.schema
  • langchain_core.tools
  • langchain_core.tracers
  • pydantic
  • types
  • typing
  • typing_extensions
  • warnings

Frequently Asked Questions

What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, LanguageModelBase subdomain.
What functions are defined in base.py?
base.py defines 9 function(s): _attempt_infer_model_provider, _call, _get_chat_model_creator, _import_module, _init_chat_model_helper, _parse_model, _remove_prefix, collections, init_chat_model.
What does base.py depend on?
base.py imports 15 module(s): collections.abc, functools, importlib, langchain_core.language_models, langchain_core.messages, langchain_core.prompt_values, langchain_core.runnables, langchain_core.runnables.schema, and 7 more.
Where is base.py in the architecture?
base.py is located at libs/langchain_v1/langchain/chat_models/base.py (domain: LangChainCore, subdomain: LanguageModelBase, directory: libs/langchain_v1/langchain/chat_models).

Analyze Your Own Codebase

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

Try Supermodel Free