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 CoreAbstractions MessageSchema 10 imports 19 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  59a89d44_d527_f17d_feb7_892b1fab5277["test_chat_models.py"]
  9e98f0a7_ec6e_708f_4f1b_e9428b316e1c["os"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  525a7d6f_f455_56e3_854a_c8a7da4a1417["unittest.mock"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> 525a7d6f_f455_56e3_854a_c8a7da4a1417
  1803c8c1_a347_1256_1454_9f04c3553d93["httpx"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> 1803c8c1_a347_1256_1454_9f04c3553d93
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  7e64d143_ea36_1c73_4897_1d0ae1757b5b["langchain_core.callbacks.base"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> 7e64d143_ea36_1c73_4897_1d0ae1757b5b
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> d758344f_537f_649e_f467_b9d7442e86df
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  eb8fd6a3_6bb0_28f8_43e4_2c1277e95823["langchain_mistralai.chat_models"]
  59a89d44_d527_f17d_feb7_892b1fab5277 --> eb8fd6a3_6bb0_28f8_43e4_2c1277e95823
  style 59a89d44_d527_f17d_feb7_892b1fab5277 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test MistralAI Chat API wrapper."""

import os
from collections.abc import AsyncGenerator, Generator
from typing import Any, cast
from unittest.mock import MagicMock, patch

import httpx
import pytest
from langchain_core.callbacks.base import BaseCallbackHandler
from langchain_core.messages import (
    AIMessage,
    BaseMessage,
    ChatMessage,
    HumanMessage,
    InvalidToolCall,
    SystemMessage,
    ToolCall,
)
from pydantic import SecretStr

from langchain_mistralai.chat_models import (  # type: ignore[import]
    ChatMistralAI,
    _convert_message_to_mistral_chat_message,
    _convert_mistral_chat_message_to_message,
    _convert_tool_call_id_to_mistral_compatible,
    _is_valid_mistral_tool_call_id,
)

os.environ["MISTRAL_API_KEY"] = "foo"


def test_mistralai_model_param() -> None:
    llm = ChatMistralAI(model="foo")  # type: ignore[call-arg]
    assert llm.model == "foo"


def test_mistralai_initialization() -> None:
    """Test ChatMistralAI initialization."""
    # Verify that ChatMistralAI can be initialized using a secret key provided
    # as a parameter rather than an environment variable.
    for model in [
        ChatMistralAI(model="test", mistral_api_key="test"),  # type: ignore[call-arg, call-arg]
        ChatMistralAI(model="test", api_key="test"),  # type: ignore[call-arg, arg-type]
    ]:
        assert cast("SecretStr", model.mistral_api_key).get_secret_value() == "test"


@pytest.mark.parametrize(
    ("model", "expected_url"),
    [
        (ChatMistralAI(model="test"), "https://api.mistral.ai/v1"),  # type: ignore[call-arg, arg-type]
        (ChatMistralAI(model="test", endpoint="baz"), "baz"),  # type: ignore[call-arg, arg-type]
    ],
)
def test_mistralai_initialization_baseurl(
    model: ChatMistralAI, expected_url: str
) -> None:
    """Test ChatMistralAI initialization."""
    # Verify that ChatMistralAI can be initialized providing endpoint, but also
// ... (350 more lines)

Subdomains

Classes

Dependencies

  • collections.abc
  • httpx
  • langchain_core.callbacks.base
  • langchain_core.messages
  • langchain_mistralai.chat_models
  • os
  • pydantic
  • pytest
  • typing
  • unittest.mock

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 CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_chat_models.py?
test_chat_models.py defines 19 function(s): _make_completion_response_from_token, mock_chat_astream, mock_chat_stream, test__convert_dict_to_message_tool_call, test__convert_dict_to_message_tool_call_with_null_content, test__convert_dict_to_message_with_missing_content, test_astream_with_callback, test_convert_message_to_mistral_chat_message, test_custom_token_counting, test_extra_kwargs, and 9 more.
What does test_chat_models.py depend on?
test_chat_models.py imports 10 module(s): collections.abc, httpx, langchain_core.callbacks.base, langchain_core.messages, langchain_mistralai.chat_models, os, pydantic, pytest, and 2 more.
Where is test_chat_models.py in the architecture?
test_chat_models.py is located at libs/partners/mistralai/tests/unit_tests/test_chat_models.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/partners/mistralai/tests/unit_tests).

Analyze Your Own Codebase

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

Try Supermodel Free