test_chat_models.py — langchain Source File
Architecture documentation for test_chat_models.py, a python file in the langchain codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 5bf2e477_37e0_3e98_4042_bc609f2f7f60["test_chat_models.py"] 9d14ea65_8b2e_6721_a947_acc89905651f["json"] 5bf2e477_37e0_3e98_4042_bc609f2f7f60 --> 9d14ea65_8b2e_6721_a947_acc89905651f 0029f612_c503_ebcf_a452_a0fae8c9f2c3["os"] 5bf2e477_37e0_3e98_4042_bc609f2f7f60 --> 0029f612_c503_ebcf_a452_a0fae8c9f2c3 feec1ec4_6917_867b_d228_b134d0ff8099["typing"] 5bf2e477_37e0_3e98_4042_bc609f2f7f60 --> feec1ec4_6917_867b_d228_b134d0ff8099 23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"] 5bf2e477_37e0_3e98_4042_bc609f2f7f60 --> 23cb242e_1754_041d_200a_553fcb8abe1b 86d015d7_8a78_acc2_abd6_9cb22b0ae1aa["langchain_core.load"] 5bf2e477_37e0_3e98_4042_bc609f2f7f60 --> 86d015d7_8a78_acc2_abd6_9cb22b0ae1aa f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"] 5bf2e477_37e0_3e98_4042_bc609f2f7f60 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] 5bf2e477_37e0_3e98_4042_bc609f2f7f60 --> 9444498b_8066_55c7_b3a2_1d90c4162a32 ece82521_5d64_8b17_634a_01a39ad4bdea["langchain_groq.chat_models"] 5bf2e477_37e0_3e98_4042_bc609f2f7f60 --> ece82521_5d64_8b17_634a_01a39ad4bdea style 5bf2e477_37e0_3e98_4042_bc609f2f7f60 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Test Groq Chat API wrapper."""
import json
import os
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
import langchain_core.load as lc_load
import pytest
from langchain_core.messages import (
AIMessage,
AIMessageChunk,
FunctionMessage,
HumanMessage,
InvalidToolCall,
SystemMessage,
ToolCall,
)
from langchain_groq.chat_models import (
ChatGroq,
_convert_chunk_to_message_chunk,
_convert_dict_to_message,
_create_usage_metadata,
_format_message_content,
)
if "GROQ_API_KEY" not in os.environ:
os.environ["GROQ_API_KEY"] = "fake-key"
def test_groq_model_param() -> None:
llm = ChatGroq(model="foo") # type: ignore[call-arg]
assert llm.model_name == "foo"
llm = ChatGroq(model_name="foo") # type: ignore[call-arg]
assert llm.model_name == "foo"
def test_function_message_dict_to_function_message() -> None:
content = json.dumps({"result": "Example #1"})
name = "test_function"
result = _convert_dict_to_message(
{
"role": "function",
"name": name,
"content": content,
}
)
assert isinstance(result, FunctionMessage)
assert result.name == name
assert result.content == content
def test__convert_dict_to_message_human() -> None:
message = {"role": "user", "content": "foo"}
result = _convert_dict_to_message(message)
expected_output = HumanMessage(content="foo")
assert result == expected_output
// ... (950 more lines)
Domain
Subdomains
Functions
- mock_completion()
- os()
- test__convert_dict_to_message_ai()
- test__convert_dict_to_message_human()
- test__convert_dict_to_message_system()
- test__convert_dict_to_message_tool_call()
- test_chat_groq_extra_kwargs()
- test_chat_groq_invalid_streaming_params()
- test_chat_groq_secret()
- test_chat_result_backward_compatibility()
- test_chat_result_with_cached_and_reasoning_tokens()
- test_chat_result_with_reasoning_tokens()
- test_chat_result_with_usage_metadata()
- test_combine_llm_outputs_with_missing_details()
- test_combine_llm_outputs_with_token_details()
- test_create_usage_metadata_basic()
- test_create_usage_metadata_chat_completions_with_details()
- test_create_usage_metadata_empty_completion_details()
- test_create_usage_metadata_empty_details()
- test_create_usage_metadata_missing_total_tokens()
- test_create_usage_metadata_responses_api_format()
- test_create_usage_metadata_with_all_details()
- test_create_usage_metadata_with_cached_and_reasoning_tokens()
- test_create_usage_metadata_with_cached_tokens()
- test_create_usage_metadata_with_reasoning_tokens()
- test_create_usage_metadata_zero_cached_tokens()
- test_create_usage_metadata_zero_reasoning_tokens()
- test_format_message_content_empty_list()
- test_format_message_content_langchain_image_base64()
- test_format_message_content_langchain_image_url()
- test_format_message_content_mixed()
- test_format_message_content_none()
- test_format_message_content_string()
- test_format_message_content_text_and_image_url()
- test_function_message_dict_to_function_message()
- test_groq_ainvoke()
- test_groq_invoke()
- test_groq_model_param()
- test_groq_serialization()
- test_profile()
- test_streaming_with_cached_and_reasoning_tokens()
- test_streaming_with_reasoning_tokens()
- test_streaming_with_usage_metadata()
- test_streaming_without_usage_metadata()
Dependencies
- json
- langchain_core.load
- langchain_core.messages
- langchain_groq.chat_models
- os
- pytest
- typing
- unittest.mock
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 44 function(s): mock_completion, os, test__convert_dict_to_message_ai, test__convert_dict_to_message_human, test__convert_dict_to_message_system, test__convert_dict_to_message_tool_call, test_chat_groq_extra_kwargs, test_chat_groq_invalid_streaming_params, test_chat_groq_secret, test_chat_result_backward_compatibility, and 34 more.
What does test_chat_models.py depend on?
test_chat_models.py imports 8 module(s): json, langchain_core.load, langchain_core.messages, langchain_groq.chat_models, os, pytest, typing, unittest.mock.
Where is test_chat_models.py in the architecture?
test_chat_models.py is located at libs/partners/groq/tests/unit_tests/test_chat_models.py (domain: LangChainCore, subdomain: LanguageModelBase, directory: libs/partners/groq/tests/unit_tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free