test__convert_dict_to_message_tool_call() — langchain Function Reference
Architecture documentation for the test__convert_dict_to_message_tool_call() function in test_chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 271c3109_adcc_d41a_341a_5db43be48fda["test__convert_dict_to_message_tool_call()"] 5bf2e477_37e0_3e98_4042_bc609f2f7f60["test_chat_models.py"] 271c3109_adcc_d41a_341a_5db43be48fda -->|defined in| 5bf2e477_37e0_3e98_4042_bc609f2f7f60 style 271c3109_adcc_d41a_341a_5db43be48fda fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/groq/tests/unit_tests/test_chat_models.py lines 70–139
def test__convert_dict_to_message_tool_call() -> None:
raw_tool_call = {
"id": "call_wm0JY6CdwOMZ4eTxHWUThDNz",
"function": {
"arguments": '{"name":"Sally","hair_color":"green"}',
"name": "GenerateUsername",
},
"type": "function",
}
message = {"role": "assistant", "content": None, "tool_calls": [raw_tool_call]}
result = _convert_dict_to_message(message)
expected_output = AIMessage(
content="",
additional_kwargs={"tool_calls": [raw_tool_call]},
tool_calls=[
ToolCall(
name="GenerateUsername",
args={"name": "Sally", "hair_color": "green"},
id="call_wm0JY6CdwOMZ4eTxHWUThDNz",
type="tool_call",
)
],
response_metadata={"model_provider": "groq"},
)
assert result == expected_output
# Test malformed tool call
raw_tool_calls = [
{
"id": "call_wm0JY6CdwOMZ4eTxHWUThDNz",
"function": {
"arguments": "oops",
"name": "GenerateUsername",
},
"type": "function",
},
{
"id": "call_abc123",
"function": {
"arguments": '{"name":"Sally","hair_color":"green"}',
"name": "GenerateUsername",
},
"type": "function",
},
]
message = {"role": "assistant", "content": None, "tool_calls": raw_tool_calls}
result = _convert_dict_to_message(message)
expected_output = AIMessage(
content="",
additional_kwargs={"tool_calls": raw_tool_calls},
invalid_tool_calls=[
InvalidToolCall(
name="GenerateUsername",
args="oops",
id="call_wm0JY6CdwOMZ4eTxHWUThDNz",
error="Function GenerateUsername arguments:\n\noops\n\nare not valid JSON. Received JSONDecodeError Expecting value: line 1 column 1 (char 0)\nFor troubleshooting, visit: https://docs.langchain.com/oss/python/langchain/errors/OUTPUT_PARSING_FAILURE ", # noqa: E501
type="invalid_tool_call",
),
],
tool_calls=[
ToolCall(
name="GenerateUsername",
args={"name": "Sally", "hair_color": "green"},
id="call_abc123",
type="tool_call",
),
],
response_metadata={"model_provider": "groq"},
)
assert result == expected_output
Domain
Subdomains
Source
Frequently Asked Questions
What does test__convert_dict_to_message_tool_call() do?
test__convert_dict_to_message_tool_call() is a function in the langchain codebase, defined in libs/partners/groq/tests/unit_tests/test_chat_models.py.
Where is test__convert_dict_to_message_tool_call() defined?
test__convert_dict_to_message_tool_call() is defined in libs/partners/groq/tests/unit_tests/test_chat_models.py at line 70.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free