Home / Class/ ChatModelUnitTests Class — langchain Architecture

ChatModelUnitTests Class — langchain Architecture

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

Entity Profile

Dependency Diagram

graph TD
  d29129aa_3fb7_7d61_5571_265b916f177b["ChatModelUnitTests"]
  39468aac_d3b1_1e4e_47c8_632f3ee4dd57["ChatModelTests"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|extends| 39468aac_d3b1_1e4e_47c8_632f3ee4dd57
  7c4bbf04_1945_a08e_31ca_a0cbf44c8755["RunnableBinding"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|extends| 7c4bbf04_1945_a08e_31ca_a0cbf44c8755
  83730711_48bf_e102_3a75_7c6b878a5182["chat_models.py"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|defined in| 83730711_48bf_e102_3a75_7c6b878a5182
  131c47d5_8f1b_3429_cb71_d94c9d2c9a2c["standard_chat_model_params()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| 131c47d5_8f1b_3429_cb71_d94c9d2c9a2c
  c52dcae8_0801_6ec0_0de7_d2e628ab3457["init_from_env_params()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| c52dcae8_0801_6ec0_0de7_d2e628ab3457
  7c30290e_cd2e_ca8a_25bb_dd4cc22786ef["test_init()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| 7c30290e_cd2e_ca8a_25bb_dd4cc22786ef
  b28eec18_0439_ccd9_e911_95b79d5a6ada["test_init_from_env()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| b28eec18_0439_ccd9_e911_95b79d5a6ada
  ee22c764_40b5_248c_de0f_be32246b8fd5["test_init_streaming()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| ee22c764_40b5_248c_de0f_be32246b8fd5
  7f06143f_8076_4eab_7459_a828c668e0d3["test_bind_tool_pydantic()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| 7f06143f_8076_4eab_7459_a828c668e0d3
  5a69738e_16d6_08b8_c36e_1628152716bb["test_with_structured_output()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| 5a69738e_16d6_08b8_c36e_1628152716bb
  f0837c14_3a93_3dae_ba45_44abbc4c1104["test_standard_params()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| f0837c14_3a93_3dae_ba45_44abbc4c1104
  713aab45_d73b_a8cc_e411_a24de141ebb6["test_serdes()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| 713aab45_d73b_a8cc_e411_a24de141ebb6
  cf5084f5_a29d_b951_efd5_758cfe377b6a["test_init_time()"]
  d29129aa_3fb7_7d61_5571_265b916f177b -->|method| cf5084f5_a29d_b951_efd5_758cfe377b6a

Relationship Graph

Source Code

libs/standard-tests/langchain_tests/unit_tests/chat_models.py lines 276–1148

class ChatModelUnitTests(ChatModelTests):
    '''Base class for chat model unit tests.

    Test subclasses must implement the `chat_model_class` and
    `chat_model_params` properties to specify what model to test and its
    initialization parameters.

    ```python
    from typing import Type

    from langchain_tests.unit_tests import ChatModelUnitTests
    from my_package.chat_models import MyChatModel


    class TestMyChatModelUnit(ChatModelUnitTests):
        @property
        def chat_model_class(self) -> Type[MyChatModel]:
            # Return the chat model class to test here
            return MyChatModel

        @property
        def chat_model_params(self) -> dict:
            # Return initialization parameters for the model.
            return {"model": "model-001", "temperature": 0}
    ```

    !!! note
        API references for individual test methods include troubleshooting tips.


    Test subclasses **must** implement the following two properties:

    `chat_model_class`: The chat model class to test, e.g., `ChatParrotLink`.

    ```python
    @property
    def chat_model_class(self) -> Type[ChatParrotLink]:
        return ChatParrotLink
    ```

    `chat_model_params`: Initialization parameters for the chat model.

    ```python
    @property
    def chat_model_params(self) -> dict:
        return {"model": "bird-brain-001", "temperature": 0}
    ```

    In addition, test subclasses can control what features are tested (such as tool
    calling or multi-modality) by selectively overriding the following properties.

    Expand to see details:

    ???+ info "`has_tool_calling`"

        Boolean property indicating whether the chat model supports tool calling.

        By default, this is determined by whether the chat model's `bind_tools` method
        is overridden. It typically does not need to be overridden on the test class.

        ```python
        @property
        def has_tool_calling(self) -> bool:
            return True
        ```

    ??? info "`has_tool_choice`"

        Boolean property indicating whether the chat model supports forcing tool
        calling via a `tool_choice` parameter.

        By default, this is determined by whether the parameter is included in the
        signature for the corresponding `bind_tools` method.

        If `True`, the minimum requirement for this feature is that
        `tool_choice='any'` will force a tool call, and `tool_choice=<tool name>`
        will force a call to a specific tool.

        ```python
        @property
        def has_tool_choice(self) -> bool:

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free