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 21 functions

Entity Profile

Dependency Diagram

graph LR
  33a6abf7_7aa2_f286_5926_12dc7307602b["test_chat_models.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  525a7d6f_f455_56e3_854a_c8a7da4a1417["unittest.mock"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> 525a7d6f_f455_56e3_854a_c8a7da4a1417
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> 120e2591_3e15_b895_72b6_cb26195e40a6
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> d758344f_537f_649e_f467_b9d7442e86df
  ac2a9b92_4484_491e_1b48_ec85e71e1d58["langchain_core.outputs"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> ac2a9b92_4484_491e_1b48_ec85e71e1d58
  43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> 43d88577_548b_2248_b01b_7987bae85dcc
  c4355b7b_ea72_11e9_eec0_d1c51f1db2ff["langchain_huggingface.chat_models"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> c4355b7b_ea72_11e9_eec0_d1c51f1db2ff
  85b6901a_39a7_3d43_ed4d_937e31c1e94e["langchain_huggingface.llms"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> 85b6901a_39a7_3d43_ed4d_937e31c1e94e
  c417363a_1c8e_ad5d_1f70_204df24f50bf["langchain.chat_models.base"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> c417363a_1c8e_ad5d_1f70_204df24f50bf
  4764ca37_d94c_f8b7_54d8_c5b326fc9488["langchain_huggingface"]
  33a6abf7_7aa2_f286_5926_12dc7307602b --> 4764ca37_d94c_f8b7_54d8_c5b326fc9488
  style 33a6abf7_7aa2_f286_5926_12dc7307602b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Any
from unittest.mock import MagicMock, Mock, patch

import pytest  # type: ignore[import-not-found]
from langchain_core.messages import (
    AIMessage,
    BaseMessage,
    FunctionMessage,
    HumanMessage,
    SystemMessage,
)
from langchain_core.outputs import ChatResult
from langchain_core.tools import BaseTool

from langchain_huggingface.chat_models import (  # type: ignore[import]
    ChatHuggingFace,
    _convert_dict_to_message,
)
from langchain_huggingface.llms import HuggingFaceEndpoint


@pytest.fixture
def mock_llm() -> Mock:
    llm = Mock(spec=HuggingFaceEndpoint)
    llm.inference_server_url = "test endpoint url"
    llm.temperature = 0.7
    llm.max_new_tokens = 512
    llm.top_p = 0.9
    llm.seed = 42
    llm.streaming = True
    llm.repetition_penalty = 1.1
    llm.stop_sequences = ["</s>", "<|end|>"]
    llm.model_kwargs = {"do_sample": True, "top_k": 50}
    llm.server_kwargs = {"timeout": 120}
    llm.repo_id = "test/model"
    llm.model = "test/model"
    return llm


@pytest.fixture
@patch(
    "langchain_huggingface.chat_models.huggingface.ChatHuggingFace._resolve_model_id"
)
def chat_hugging_face(mock_resolve_id: Any, mock_llm: Any) -> ChatHuggingFace:
    return ChatHuggingFace(llm=mock_llm, tokenizer=MagicMock())


def test_create_chat_result(chat_hugging_face: Any) -> None:
    mock_response = {
        "choices": [
            {
                "message": {"role": "assistant", "content": "test message"},
                "finish_reason": "test finish reason",
            }
        ],
        "usage": {"tokens": 420},
    }

    result = chat_hugging_face._create_chat_result(mock_response)
    assert isinstance(result, ChatResult)
// ... (332 more lines)

Subdomains

Dependencies

  • langchain.chat_models.base
  • langchain_core.messages
  • langchain_core.outputs
  • langchain_core.tools
  • langchain_huggingface
  • langchain_huggingface.chat_models
  • langchain_huggingface.llms
  • 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 21 function(s): chat_hugging_face, mock_llm, test_bind_tools, test_bind_tools_errors, test_convert_dict_to_message, test_create_chat_result, test_create_message_dicts_includes_inherited_params, test_default_params_includes_inherited_values, test_huggingface_endpoint_specific_inheritance, test_inheritance_with_empty_llm, and 11 more.
What does test_chat_models.py depend on?
test_chat_models.py imports 10 module(s): langchain.chat_models.base, langchain_core.messages, langchain_core.outputs, langchain_core.tools, langchain_huggingface, langchain_huggingface.chat_models, langchain_huggingface.llms, pytest, and 2 more.
Where is test_chat_models.py in the architecture?
test_chat_models.py is located at libs/partners/huggingface/tests/unit_tests/test_chat_models.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/partners/huggingface/tests/unit_tests).

Analyze Your Own Codebase

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

Try Supermodel Free