Home / File/ test_chat_models.py — langchain Source File

test_chat_models.py — langchain Source File

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

File python LangChainCore LanguageModelBase 10 imports 9 functions

Entity Profile

Dependency Diagram

graph LR
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8["test_chat_models.py"]
  0029f612_c503_ebcf_a452_a0fae8c9f2c3["os"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> 0029f612_c503_ebcf_a452_a0fae8c9f2c3
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> feec1ec4_6917_867b_d228_b134d0ff8099
  0b0de9e1_5259_4f11_33ed_8e5834038690["unittest"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> 0b0de9e1_5259_4f11_33ed_8e5834038690
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  435e49bf_bb2e_2016_ead7_0afb9d57ad71["langchain_core.prompts"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> 435e49bf_bb2e_2016_ead7_0afb9d57ad71
  31eab4ab_7281_1e6c_b17d_12e6ad9de07a["langchain_core.runnables"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> 31eab4ab_7281_1e6c_b17d_12e6ad9de07a
  dd5e7909_a646_84f1_497b_cae69735550e["pydantic"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> dd5e7909_a646_84f1_497b_cae69735550e
  86772f84_002d_6acf_1cd7_c03ca452c4b1["langchain.chat_models"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> 86772f84_002d_6acf_1cd7_c03ca452c4b1
  65f05002_bc3f_fe76_ba95_ad1efdcfcc42["langchain.chat_models.base"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> 65f05002_bc3f_fe76_ba95_ad1efdcfcc42
  e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"]
  29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 --> e929cf21_6ab8_6ff3_3765_0d35a099a053
  style 29aaa9ad_8f95_7e3c_f947_66f656fbb0e8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import os
from typing import TYPE_CHECKING
from unittest import mock

import pytest
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableConfig, RunnableSequence
from pydantic import SecretStr

from langchain.chat_models import __all__, init_chat_model
from langchain.chat_models.base import _BUILTIN_PROVIDERS, _attempt_infer_model_provider

if TYPE_CHECKING:
    from langchain_core.language_models import BaseChatModel

EXPECTED_ALL = [
    "init_chat_model",
    "BaseChatModel",
]


def test_all_imports() -> None:
    """Test that all expected imports are present in the module's __all__."""
    assert set(__all__) == set(EXPECTED_ALL)


@pytest.mark.requires(
    "langchain_openai",
    "langchain_anthropic",
    "langchain_fireworks",
    "langchain_groq",
)
@pytest.mark.parametrize(
    ("model_name", "model_provider"),
    [
        ("gpt-4o", "openai"),
        ("claude-opus-4-1", "anthropic"),
        ("accounts/fireworks/models/mixtral-8x7b-instruct", "fireworks"),
        ("mixtral-8x7b-32768", "groq"),
    ],
)
def test_init_chat_model(model_name: str, model_provider: str | None) -> None:
    llm1: BaseChatModel = init_chat_model(
        model_name,
        model_provider=model_provider,
        api_key="foo",
    )
    llm2: BaseChatModel = init_chat_model(
        f"{model_provider}:{model_name}",
        api_key="foo",
    )
    assert llm1.dict() == llm2.dict()


def test_init_missing_dep() -> None:
    with pytest.raises(ImportError):
        init_chat_model("mixtral-8x7b-32768", model_provider="groq")


def test_init_unknown_provider() -> None:
// ... (278 more lines)

Domain

Subdomains

Dependencies

  • langchain.chat_models
  • langchain.chat_models.base
  • langchain_core.language_models
  • langchain_core.prompts
  • langchain_core.runnables
  • os
  • pydantic
  • pytest
  • typing
  • unittest

Frequently Asked Questions

What does test_chat_models.py do?
test_chat_models.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 test_chat_models.py?
test_chat_models.py defines 9 function(s): langchain_core, test_all_imports, test_attempt_infer_model_provider, test_configurable, test_configurable_with_default, test_init_chat_model, test_init_missing_dep, test_init_unknown_provider, test_supported_providers_is_sorted.
What does test_chat_models.py depend on?
test_chat_models.py imports 10 module(s): langchain.chat_models, langchain.chat_models.base, langchain_core.language_models, langchain_core.prompts, langchain_core.runnables, os, pydantic, pytest, and 2 more.
Where is test_chat_models.py in the architecture?
test_chat_models.py is located at libs/langchain_v1/tests/unit_tests/chat_models/test_chat_models.py (domain: LangChainCore, subdomain: LanguageModelBase, directory: libs/langchain_v1/tests/unit_tests/chat_models).

Analyze Your Own Codebase

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

Try Supermodel Free