2024-04-12 01:23:13 +00:00
|
|
|
"""Standard LangChain interface tests"""
|
|
|
|
|
2024-05-01 17:12:44 +00:00
|
|
|
import time
|
2024-04-12 01:23:13 +00:00
|
|
|
from typing import Type
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from langchain_core.language_models import BaseChatModel
|
|
|
|
from langchain_standard_tests.integration_tests import ChatModelIntegrationTests
|
|
|
|
|
|
|
|
from langchain_ai21 import ChatAI21
|
|
|
|
|
|
|
|
|
2024-06-17 20:37:41 +00:00
|
|
|
class BaseTestAI21(ChatModelIntegrationTests):
|
2024-05-01 17:12:44 +00:00
|
|
|
def teardown(self) -> None:
|
|
|
|
# avoid getting rate limited
|
|
|
|
time.sleep(1)
|
|
|
|
|
2024-06-17 20:37:41 +00:00
|
|
|
@property
|
2024-04-12 01:23:13 +00:00
|
|
|
def chat_model_class(self) -> Type[BaseChatModel]:
|
|
|
|
return ChatAI21
|
|
|
|
|
2024-05-01 17:12:44 +00:00
|
|
|
@pytest.mark.xfail(reason="Emits AIMessage instead of AIMessageChunk.")
|
2024-06-17 20:37:41 +00:00
|
|
|
def test_stream(self, model: BaseChatModel) -> None:
|
|
|
|
super().test_stream(model)
|
2024-05-01 17:12:44 +00:00
|
|
|
|
|
|
|
@pytest.mark.xfail(reason="Emits AIMessage instead of AIMessageChunk.")
|
2024-06-17 20:37:41 +00:00
|
|
|
async def test_astream(self, model: BaseChatModel) -> None:
|
|
|
|
await super().test_astream(model)
|
2024-05-01 17:12:44 +00:00
|
|
|
|
2024-05-23 18:21:58 +00:00
|
|
|
@pytest.mark.xfail(reason="Not implemented.")
|
2024-06-17 20:37:41 +00:00
|
|
|
def test_usage_metadata(self, model: BaseChatModel) -> None:
|
|
|
|
super().test_usage_metadata(model)
|
2024-05-23 18:21:58 +00:00
|
|
|
|
2024-06-17 20:37:41 +00:00
|
|
|
|
|
|
|
class TestAI21J2(BaseTestAI21):
|
|
|
|
@property
|
2024-04-12 01:23:13 +00:00
|
|
|
def chat_model_params(self) -> dict:
|
|
|
|
return {
|
|
|
|
"model": "j2-ultra",
|
|
|
|
}
|
2024-04-23 21:14:16 +00:00
|
|
|
|
2024-05-01 17:12:44 +00:00
|
|
|
|
2024-06-17 20:37:41 +00:00
|
|
|
class TestAI21Jamba(BaseTestAI21):
|
|
|
|
@property
|
2024-05-01 17:12:44 +00:00
|
|
|
def chat_model_params(self) -> dict:
|
|
|
|
return {
|
|
|
|
"model": "jamba-instruct-preview",
|
|
|
|
}
|