-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xin Liu <[email protected]>
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
"ChatHunyuan", | ||
"GigaChat", | ||
"VolcEngineMaasChat", | ||
"WasmChatService", | ||
] | ||
|
||
|
||
|
79 changes: 79 additions & 0 deletions
79
libs/community/tests/unit_tests/chat_models/test_wasmchat.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import pytest | ||
from langchain_community.chat_models.wasm_chat import ( | ||
WasmChatService, | ||
_convert_dict_to_message, | ||
_convert_message_to_dict, | ||
) | ||
from langchain_core.messages import ( | ||
AIMessage, | ||
ChatMessage, | ||
FunctionMessage, | ||
HumanMessage, | ||
SystemMessage, | ||
) | ||
|
||
|
||
def test__convert_message_to_dict_human() -> None: | ||
message = HumanMessage(content="foo") | ||
result = _convert_message_to_dict(message) | ||
expected_output = {"role": "user", "content": "foo"} | ||
assert result == expected_output | ||
|
||
|
||
def test__convert_message_to_dict_ai() -> None: | ||
message = AIMessage(content="foo") | ||
result = _convert_message_to_dict(message) | ||
expected_output = {"role": "assistant", "content": "foo"} | ||
assert result == expected_output | ||
|
||
|
||
def test__convert_message_to_dict_system() -> None: | ||
message = SystemMessage(content="foo") | ||
result = _convert_message_to_dict(message) | ||
expected_output = {"role": "system", "content": "foo"} | ||
assert result == expected_output | ||
|
||
|
||
def test__convert_message_to_dict_function() -> None: | ||
message = FunctionMessage(name="foo", content="bar") | ||
with pytest.raises(TypeError) as e: | ||
_convert_message_to_dict(message) | ||
assert "Got unknown type" in str(e) | ||
|
||
|
||
def test__convert_dict_to_message_human() -> None: | ||
message_dict = {"role": "user", "content": "foo"} | ||
result = _convert_dict_to_message(message_dict) | ||
expected_output = HumanMessage(content="foo") | ||
assert result == expected_output | ||
|
||
|
||
def test__convert_dict_to_message_ai() -> None: | ||
message_dict = {"role": "assistant", "content": "foo"} | ||
result = _convert_dict_to_message(message_dict) | ||
expected_output = AIMessage(content="foo") | ||
assert result == expected_output | ||
|
||
|
||
def test__convert_dict_to_message_other_role() -> None: | ||
message_dict = {"role": "system", "content": "foo"} | ||
result = _convert_dict_to_message(message_dict) | ||
expected_output = ChatMessage(role="system", content="foo") | ||
assert result == expected_output | ||
|
||
|
||
def test_wasm_chat_without_service_url() -> None: | ||
chat = WasmChatService() | ||
|
||
# create message sequence | ||
system_message = SystemMessage(content="You are an AI assistant") | ||
user_message = HumanMessage(content="What is the capital of France?") | ||
messages = [system_message, user_message] | ||
|
||
with pytest.raises(ValueError) as e: | ||
chat(messages) | ||
|
||
assert ( | ||
"Error code: 503, reason: The IP address or port of the chat service is incorrect." | ||
in str(e) | ||
) |