community[patch]: Optimize test case for MoonshotChat (#25050)

Optimize test case for `MoonshotChat`. Use standard
ChatModelIntegrationTests.
This commit is contained in:
ZhangShenao 2024-08-05 22:11:25 +08:00 committed by GitHub
parent cea3f72485
commit cda79dbb6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,36 +1,23 @@
"""Test Moonshot Chat Model."""
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
from typing import Type
import pytest
from langchain_core.language_models import BaseChatModel
from langchain_standard_tests.integration_tests import ChatModelIntegrationTests
from langchain_community.chat_models.moonshot import MoonshotChat
def test_default_call() -> None:
"""Test default model call."""
chat = MoonshotChat() # type: ignore[call-arg]
response = chat.invoke([HumanMessage(content="How are you?")])
assert isinstance(response, BaseMessage)
assert isinstance(response.content, str)
class TestMoonshotChat(ChatModelIntegrationTests):
@property
def chat_model_class(self) -> Type[BaseChatModel]:
return MoonshotChat
@property
def chat_model_params(self) -> dict:
return {"model": "moonshot-v1-8k"}
def test_model() -> None:
"""Test model kwarg works."""
chat = MoonshotChat(model="moonshot-v1-32k") # type: ignore[call-arg]
response = chat.invoke([HumanMessage(content="How are you?")])
assert isinstance(response, BaseMessage)
assert isinstance(response.content, str)
def test_multiple_history() -> None:
"""Tests multiple history works."""
chat = MoonshotChat() # type: ignore[call-arg]
response = chat.invoke(
[
HumanMessage(content="How are you?"),
AIMessage(content="I'm fine, and you?"),
HumanMessage(content="Not bad!"),
]
)
assert isinstance(response, BaseMessage)
assert isinstance(response.content, str)
@pytest.mark.xfail(reason="Not yet implemented.")
def test_usage_metadata(self, model: BaseChatModel) -> None:
super().test_usage_metadata(model)