Spaces:
Configuration error
Configuration error
Fedir Zadniprovskyi
commited on
Commit
·
14812fd
1
Parent(s):
5aa421e
chore: update model(s) route tests
Browse files- tests/api_model_test.py +7 -20
tests/api_model_test.py
CHANGED
@@ -1,35 +1,22 @@
|
|
1 |
-
|
2 |
from openai import OpenAI
|
3 |
-
|
4 |
-
from faster_whisper_server.server_models import ModelObject
|
5 |
|
6 |
MODEL_THAT_EXISTS = "Systran/faster-whisper-tiny.en"
|
7 |
MODEL_THAT_DOES_NOT_EXIST = "i-do-not-exist"
|
8 |
MIN_EXPECTED_NUMBER_OF_MODELS = 70 # At the time of the test creation there are 89 models
|
9 |
|
10 |
|
11 |
-
# HACK: because ModelObject(**data) doesn't work
|
12 |
-
def model_dict_to_object(model_dict: dict) -> ModelObject:
|
13 |
-
return ModelObject(
|
14 |
-
id=model_dict["id"],
|
15 |
-
created=model_dict["created"],
|
16 |
-
object_=model_dict["object"],
|
17 |
-
owned_by=model_dict["owned_by"],
|
18 |
-
)
|
19 |
-
|
20 |
-
|
21 |
def test_list_models(openai_client: OpenAI) -> None:
|
22 |
models = openai_client.models.list().data
|
23 |
assert len(models) > MIN_EXPECTED_NUMBER_OF_MODELS
|
24 |
|
25 |
|
26 |
-
def test_model_exists(
|
27 |
-
|
28 |
-
data = response.json()
|
29 |
-
model = model_dict_to_object(data)
|
30 |
assert model.id == MODEL_THAT_EXISTS
|
31 |
|
32 |
|
33 |
-
def test_model_does_not_exist(
|
34 |
-
|
35 |
-
|
|
|
1 |
+
import openai
|
2 |
from openai import OpenAI
|
3 |
+
import pytest
|
|
|
4 |
|
5 |
MODEL_THAT_EXISTS = "Systran/faster-whisper-tiny.en"
|
6 |
MODEL_THAT_DOES_NOT_EXIST = "i-do-not-exist"
|
7 |
MIN_EXPECTED_NUMBER_OF_MODELS = 70 # At the time of the test creation there are 89 models
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def test_list_models(openai_client: OpenAI) -> None:
|
11 |
models = openai_client.models.list().data
|
12 |
assert len(models) > MIN_EXPECTED_NUMBER_OF_MODELS
|
13 |
|
14 |
|
15 |
+
def test_model_exists(openai_client: OpenAI) -> None:
|
16 |
+
model = openai_client.models.retrieve(MODEL_THAT_EXISTS)
|
|
|
|
|
17 |
assert model.id == MODEL_THAT_EXISTS
|
18 |
|
19 |
|
20 |
+
def test_model_does_not_exist(openai_client: OpenAI) -> None:
|
21 |
+
with pytest.raises(openai.NotFoundError):
|
22 |
+
openai_client.models.retrieve(MODEL_THAT_DOES_NOT_EXIST)
|