Test model if api key is available

This commit is contained in:
Guillem Borrell 2024-05-23 23:31:00 +02:00
parent 1040a18545
commit 48d2a9fc57
4 changed files with 21 additions and 5 deletions

2
requirements-test.in Normal file
View file

@ -0,0 +1,2 @@
pytest
pytest-asyncio

View file

@ -25,12 +25,12 @@ class Chat:
api_key: str = "",
temperature: float = 0.5,
):
self.model = model
self.model_name = model
self.api_key = self.raise_no_key(api_key)
self.messages = []
self.responses = []
model: ChatAnyscale = ChatAnyscale(
self.model: ChatAnyscale = ChatAnyscale(
model_name=model, temperature=temperature, anyscale_api_key=self.api_key
)
@ -42,7 +42,8 @@ class Chat:
]
)
self.responses.append(await self.model.ainvoke(self.messages[-1]))
response = await self.model.ainvoke(self.messages[-1])
self.responses.append(response)
return self
def last_response_content(self):

View file

@ -20,7 +20,7 @@ def test_dump():
def test_load():
db = DDB().load_folder_local(TEST_OUTPUT_FOLDER)
results = db.query("select * from answers").fetchall()
assert db.sheets == ("answers",)
results = db.query("select * from answers").fetchall()
assert len(results) == 2

13
test/test_query.py Normal file
View file

@ -0,0 +1,13 @@
import pytest
from hellocomputer.config import settings
from hellocomputer.models import Chat
@pytest.mark.asyncio
@pytest.mark.skipif(
settings.anyscale_api_key == "Awesome API", reason="API Key not set"
)
async def test_chat_simple():
chat = Chat(api_key=settings.anyscale_api_key, temperature=0)
chat = await chat.eval("Your're a helpful assistant", "Say literlly 'Hello'")
assert chat.last_response_content() == "Hello!"