Home / File/ chat_models.py — langchain Source File

chat_models.py — langchain Source File

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

File python CoreAbstractions MessageSchema 14 imports 2 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  83730711_48bf_e102_3a75_7c6b878a5182["chat_models.py"]
  614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 614e7b9f_ed51_0780_749c_ff40b74963fc
  9e98f0a7_ec6e_708f_4f1b_e9428b316e1c["os"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> cccbe73e_4644_7211_4d55_e8fb133a8014
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  6ebcaae2_3bc1_badf_b751_e164ff2776c4["unittest"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 6ebcaae2_3bc1_badf_b751_e164ff2776c4
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> ba43b74d_3099_7e1c_aac3_cf594720469e
  36cce5da_d805_04c3_7e86_e1b4dd49b497["langchain_core.load"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 36cce5da_d805_04c3_7e86_e1b4dd49b497
  2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c
  43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 43d88577_548b_2248_b01b_7987bae85dcc
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  86e12e47_abd3_7376_ceed_f0108db0965a["langchain_tests.base"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 86e12e47_abd3_7376_ceed_f0108db0965a
  e85cc09a_55c8_b775_4454_f3a6771761b9["pytest_benchmark.fixture"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> e85cc09a_55c8_b775_4454_f3a6771761b9
  66d6194f_d8c1_55b6_f522_311fdad57877["syrupy.assertion"]
  83730711_48bf_e102_3a75_7c6b878a5182 --> 66d6194f_d8c1_55b6_f522_311fdad57877
  style 83730711_48bf_e102_3a75_7c6b878a5182 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Chat model unit tests."""

from __future__ import annotations

import inspect
import os
from abc import abstractmethod
from typing import TYPE_CHECKING, Any, Literal
from unittest import mock

import pytest
from langchain_core.language_models import BaseChatModel
from langchain_core.load import dumpd, load
from langchain_core.runnables import RunnableBinding
from langchain_core.tools import BaseTool, tool
from pydantic import BaseModel, Field, SecretStr, ValidationError

from langchain_tests.base import BaseStandardTests

if TYPE_CHECKING:
    from pytest_benchmark.fixture import (
        BenchmarkFixture,
    )
    from syrupy.assertion import SnapshotAssertion


def generate_schema_pydantic() -> Any:
    """Works with either pydantic 1 or 2."""

    class PersonA(BaseModel):
        """Record attributes of a person."""

        name: str = Field(..., description="The name of the person.")
        age: int = Field(..., description="The age of the person.")

    return PersonA


TEST_PYDANTIC_MODELS = [generate_schema_pydantic()]


class ChatModelTests(BaseStandardTests):
    """Base class for chat model tests."""

    @property
    @abstractmethod
    def chat_model_class(self) -> type[BaseChatModel]:
        """The chat model class to test, e.g., `ChatParrotLink`."""
        ...

    @property
    def chat_model_params(self) -> dict[str, Any]:
        """Initialization parameters for the chat model."""
        return {}

    @property
    def standard_chat_model_params(self) -> dict[str, Any]:
        """Standard chat model parameters."""
        return {
            "temperature": 0,
// ... (1089 more lines)

Subdomains

Dependencies

  • abc
  • inspect
  • langchain_core.language_models
  • langchain_core.load
  • langchain_core.runnables
  • langchain_core.tools
  • langchain_tests.base
  • os
  • pydantic
  • pytest
  • pytest_benchmark.fixture
  • syrupy.assertion
  • typing
  • unittest

Frequently Asked Questions

What does chat_models.py do?
chat_models.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in chat_models.py?
chat_models.py defines 2 function(s): generate_schema_pydantic, pytest_benchmark.
What does chat_models.py depend on?
chat_models.py imports 14 module(s): abc, inspect, langchain_core.language_models, langchain_core.load, langchain_core.runnables, langchain_core.tools, langchain_tests.base, os, and 6 more.
Where is chat_models.py in the architecture?
chat_models.py is located at libs/standard-tests/langchain_tests/unit_tests/chat_models.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/standard-tests/langchain_tests/unit_tests).

Analyze Your Own Codebase

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

Try Supermodel Free