From cda79dbb6c87829d5cf3d6775f263f3065a6f7dd Mon Sep 17 00:00:00 2001 From: ZhangShenao <15201440436@163.com> Date: Mon, 5 Aug 2024 22:11:25 +0800 Subject: [PATCH] community[patch]: Optimize test case for `MoonshotChat` (#25050) Optimize test case for `MoonshotChat`. Use standard ChatModelIntegrationTests. --- .../chat_models/test_moonshot.py | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/libs/community/tests/integration_tests/chat_models/test_moonshot.py b/libs/community/tests/integration_tests/chat_models/test_moonshot.py index a44b4857168..58ea6de5e02 100644 --- a/libs/community/tests/integration_tests/chat_models/test_moonshot.py +++ b/libs/community/tests/integration_tests/chat_models/test_moonshot.py @@ -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)