community[patch]: Add ToolMessage for ChatZhipuAI (#25547)

- **Description:** Add ToolMessage for `ChatZhipuAI` to solve the issue
#25490
This commit is contained in:
maang-h
2024-08-19 23:26:38 +08:00
committed by GitHub
parent 5a3aaae6dc
commit 015ab91b83
2 changed files with 34 additions and 1 deletions

View File

@@ -1,8 +1,12 @@
"""Test ZhipuAI Chat API wrapper"""
import pytest
from langchain_core.messages import ToolMessage
from langchain_community.chat_models.zhipuai import ChatZhipuAI
from langchain_community.chat_models.zhipuai import (
ChatZhipuAI,
_convert_message_to_dict,
)
@pytest.mark.requires("httpx", "httpx_sse", "jwt")
@@ -11,3 +15,15 @@ def test_zhipuai_model_param() -> None:
assert llm.model_name == "foo"
llm = ChatZhipuAI(api_key="test", model_name="foo") # type: ignore[call-arg]
assert llm.model_name == "foo"
def test__convert_message_to_dict_with_tool() -> None:
message = ToolMessage(name="foo", content="bar", tool_call_id="abc123")
result = _convert_message_to_dict(message)
expected_output = {
"name": "foo",
"content": "bar",
"tool_call_id": "abc123",
"role": "tool",
}
assert result == expected_output