2023-08-30 01:20:06 +00:00
|
|
|
import pytest
|
2023-11-21 16:35:29 +00:00
|
|
|
from langchain_core.messages import (
|
2023-08-30 01:20:06 +00:00
|
|
|
AIMessage,
|
|
|
|
FunctionMessage,
|
|
|
|
HumanMessage,
|
|
|
|
SystemMessage,
|
|
|
|
)
|
2023-08-15 08:05:46 +00:00
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
from langchain_community.chat_models.ernie import _convert_message_to_dict
|
2023-11-20 21:09:30 +00:00
|
|
|
|
2023-08-15 08:05:46 +00:00
|
|
|
|
|
|
|
def test__convert_dict_to_message_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_dict_to_message_ai() -> None:
|
|
|
|
message = AIMessage(content="foo")
|
|
|
|
result = _convert_message_to_dict(message)
|
|
|
|
expected_output = {"role": "assistant", "content": "foo"}
|
|
|
|
assert result == expected_output
|
2023-08-30 01:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test__convert_dict_to_message_system() -> None:
|
|
|
|
message = SystemMessage(content="foo")
|
|
|
|
with pytest.raises(ValueError) as e:
|
|
|
|
_convert_message_to_dict(message)
|
|
|
|
assert "Got unknown type" in str(e)
|
|
|
|
|
|
|
|
|
|
|
|
def test__convert_dict_to_message_function() -> None:
|
|
|
|
message = FunctionMessage(name="foo", content="bar")
|
|
|
|
with pytest.raises(ValueError) as e:
|
|
|
|
_convert_message_to_dict(message)
|
|
|
|
assert "Got unknown type" in str(e)
|