test_chat_models.py — langchain Source File
Architecture documentation for test_chat_models.py, a python file in the langchain codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR d3aa2dec_5fef_73c8_892f_691289c5feaf["test_chat_models.py"] 9d14ea65_8b2e_6721_a947_acc89905651f["json"] d3aa2dec_5fef_73c8_892f_691289c5feaf --> 9d14ea65_8b2e_6721_a947_acc89905651f f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"] d3aa2dec_5fef_73c8_892f_691289c5feaf --> f69d6389_263d_68a4_7fbf_f14c0602a9ba 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] d3aa2dec_5fef_73c8_892f_691289c5feaf --> 9444498b_8066_55c7_b3a2_1d90c4162a32 ec9c75a8_46a2_f42e_cf2c_b2a56ccab463["langchain_openai.chat_models.base"] d3aa2dec_5fef_73c8_892f_691289c5feaf --> ec9c75a8_46a2_f42e_cf2c_b2a56ccab463 9a564311_d7b3_0806_54ee_4cba04694f15["langchain_xai"] d3aa2dec_5fef_73c8_892f_691289c5feaf --> 9a564311_d7b3_0806_54ee_4cba04694f15 style d3aa2dec_5fef_73c8_892f_691289c5feaf fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import json
import pytest # type: ignore[import-not-found]
from langchain_core.messages import (
AIMessage,
FunctionMessage,
HumanMessage,
SystemMessage,
ToolMessage,
)
from langchain_openai.chat_models.base import (
_convert_dict_to_message,
_convert_message_to_dict,
)
from langchain_xai import ChatXAI
MODEL_NAME = "grok-4"
def test_initialization() -> None:
"""Test chat model initialization."""
ChatXAI(model=MODEL_NAME)
def test_profile() -> None:
model = ChatXAI(model="grok-4")
assert model.profile
def test_xai_model_param() -> None:
llm = ChatXAI(model="foo")
assert llm.model_name == "foo"
llm = ChatXAI(model_name="foo") # type: ignore[call-arg]
assert llm.model_name == "foo"
ls_params = llm._get_ls_params()
assert ls_params.get("ls_provider") == "xai"
def test_chat_xai_invalid_streaming_params() -> None:
"""Test that streaming correctly invokes on_llm_new_token callback."""
with pytest.raises(ValueError):
ChatXAI(
model=MODEL_NAME,
max_tokens=10,
streaming=True,
temperature=0,
n=5,
)
def test_chat_xai_extra_kwargs() -> None:
"""Test extra kwargs to chat xai."""
# Check that foo is saved in extra_kwargs.
llm = ChatXAI(model=MODEL_NAME, foo=3, max_tokens=10) # type: ignore[call-arg]
assert llm.max_tokens == 10
assert llm.model_kwargs == {"foo": 3}
# Test that if extra_kwargs are provided, they are added to it.
llm = ChatXAI(model=MODEL_NAME, foo=3, model_kwargs={"bar": 2}) # type: ignore[call-arg]
// ... (85 more lines)
Domain
Subdomains
Functions
- test__convert_dict_to_message_human_with_name()
- test_chat_xai_extra_kwargs()
- test_chat_xai_invalid_streaming_params()
- test_convert_dict_to_message_ai()
- test_convert_dict_to_message_ai_with_name()
- test_convert_dict_to_message_human()
- test_convert_dict_to_message_system()
- test_convert_dict_to_message_system_with_name()
- test_convert_dict_to_message_tool()
- test_function_dict_to_message_function_message()
- test_initialization()
- test_profile()
- test_stream_usage_metadata()
- test_xai_model_param()
Dependencies
- json
- langchain_core.messages
- langchain_openai.chat_models.base
- langchain_xai
- pytest
Source
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 LangChainCore domain, LanguageModelBase subdomain.
What functions are defined in test_chat_models.py?
test_chat_models.py defines 14 function(s): test__convert_dict_to_message_human_with_name, test_chat_xai_extra_kwargs, test_chat_xai_invalid_streaming_params, test_convert_dict_to_message_ai, test_convert_dict_to_message_ai_with_name, test_convert_dict_to_message_human, test_convert_dict_to_message_system, test_convert_dict_to_message_system_with_name, test_convert_dict_to_message_tool, test_function_dict_to_message_function_message, and 4 more.
What does test_chat_models.py depend on?
test_chat_models.py imports 5 module(s): json, langchain_core.messages, langchain_openai.chat_models.base, langchain_xai, pytest.
Where is test_chat_models.py in the architecture?
test_chat_models.py is located at libs/partners/xai/tests/unit_tests/test_chat_models.py (domain: LangChainCore, subdomain: LanguageModelBase, directory: libs/partners/xai/tests/unit_tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free