Home / Class/ ChatModelTests Class — langchain Architecture

ChatModelTests Class — langchain Architecture

Architecture documentation for the ChatModelTests class in chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57["ChatModelTests"]
  2d95e59f_5168_1366_c8c2_e21e157938b5["BaseStandardTests"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|extends| 2d95e59f_5168_1366_c8c2_e21e157938b5
  83730711_48bf_e102_3a75_7c6b878a5182["chat_models.py"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|defined in| 83730711_48bf_e102_3a75_7c6b878a5182
  b7802923_b565_52b6_8468_6ef1e24c99e9["chat_model_class()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| b7802923_b565_52b6_8468_6ef1e24c99e9
  8b2c7c39_e38a_c891_6bfc_737d4cb7c180["chat_model_params()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| 8b2c7c39_e38a_c891_6bfc_737d4cb7c180
  31b43772_cf89_6270_4bb7_0de943882df9["standard_chat_model_params()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| 31b43772_cf89_6270_4bb7_0de943882df9
  1b3ba698_f2b7_897b_d919_e460fcc63412["model()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| 1b3ba698_f2b7_897b_d919_e460fcc63412
  666f2ab6_8558_e113_b4e8_a8dc6bf90388["my_adder_tool()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| 666f2ab6_8558_e113_b4e8_a8dc6bf90388
  59749c66_06be_8668_661e_4817505205d9["has_tool_calling()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| 59749c66_06be_8668_661e_4817505205d9
  6be72fed_7d70_c07d_73b4_a94caa3c1ca7["has_tool_choice()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| 6be72fed_7d70_c07d_73b4_a94caa3c1ca7
  faa99ff0_b39f_4a98_0cdb_b1b7eb840d2b["has_structured_output()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| faa99ff0_b39f_4a98_0cdb_b1b7eb840d2b
  260e4c78_db32_54af_4827_1b82c60475f8["structured_output_kwargs()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| 260e4c78_db32_54af_4827_1b82c60475f8
  f33452a9_7eb2_a646_693c_7158548c45aa["supports_json_mode()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| f33452a9_7eb2_a646_693c_7158548c45aa
  e30a79ab_5961_d0b4_0d03_050227b07b32["supports_image_inputs()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| e30a79ab_5961_d0b4_0d03_050227b07b32
  805b6d7a_6132_527e_51d0_50c9da3d4272["supports_image_urls()"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57 -->|method| 805b6d7a_6132_527e_51d0_50c9da3d4272

Relationship Graph

Source Code

libs/standard-tests/langchain_tests/unit_tests/chat_models.py lines 42–273

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,
            "max_tokens": 100,
            "timeout": 60,
            "stop": [],
            "max_retries": 2,
        }

    @pytest.fixture
    def model(self, request: Any) -> BaseChatModel:
        """Model fixture."""
        extra_init_params = getattr(request, "param", None) or {}
        return self.chat_model_class(
            **{
                **self.standard_chat_model_params,
                **self.chat_model_params,
                **extra_init_params,
            },
        )

    @pytest.fixture
    def my_adder_tool(self) -> BaseTool:
        """Adder tool fixture."""

        @tool
        def my_adder_tool(a: int, b: int) -> int:
            """Tool that adds two integers.

            Takes two integers, a and b, and returns their sum.
            """
            return a + b

        return my_adder_tool

    @property
    def has_tool_calling(self) -> bool:
        """Whether the model supports tool calling."""
        return self.chat_model_class.bind_tools is not BaseChatModel.bind_tools

    @property
    def has_tool_choice(self) -> bool:
        """Whether the model supports tool calling."""
        bind_tools_params = inspect.signature(
            self.chat_model_class.bind_tools
        ).parameters
        return "tool_choice" in bind_tools_params

    @property
    def has_structured_output(self) -> bool:
        """Whether the chat model supports structured output."""
        return (
            self.chat_model_class.with_structured_output
            is not BaseChatModel.with_structured_output
        ) or self.has_tool_calling

    @property
    def structured_output_kwargs(self) -> dict[str, Any]:
        """Additional kwargs to pass to `with_structured_output()` in tests.

        Override this property to customize how structured output is generated
        for your model. The most common use case is specifying the `method`
        parameter, which controls the mechanism used to enforce structured output:

        - `'function_calling'`: Uses tool/function calling to enforce the schema.

Frequently Asked Questions

What is the ChatModelTests class?
ChatModelTests is a class in the langchain codebase, defined in libs/standard-tests/langchain_tests/unit_tests/chat_models.py.
Where is ChatModelTests defined?
ChatModelTests is defined in libs/standard-tests/langchain_tests/unit_tests/chat_models.py at line 42.
What does ChatModelTests extend?
ChatModelTests extends BaseStandardTests.

Analyze Your Own Codebase

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

Try Supermodel Free