Spaces:
Running
on
T4
Running
on
T4
Fedir Zadniprovskyi
commited on
Commit
•
b8804a6
1
Parent(s):
a5d2e48
test: switch to async openai client
Browse files- tests/api_model_test.py +10 -7
- tests/conftest.py +4 -4
tests/api_model_test.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import openai
|
2 |
-
from openai import
|
3 |
import pytest
|
4 |
|
5 |
MODEL_THAT_EXISTS = "Systran/faster-whisper-tiny.en"
|
@@ -7,16 +7,19 @@ 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 |
-
|
11 |
-
|
|
|
12 |
assert len(models) > MIN_EXPECTED_NUMBER_OF_MODELS
|
13 |
|
14 |
|
15 |
-
|
16 |
-
|
|
|
17 |
assert model.id == MODEL_THAT_EXISTS
|
18 |
|
19 |
|
20 |
-
|
|
|
21 |
with pytest.raises(openai.NotFoundError):
|
22 |
-
openai_client.models.retrieve(MODEL_THAT_DOES_NOT_EXIST)
|
|
|
1 |
import openai
|
2 |
+
from openai import AsyncOpenAI
|
3 |
import pytest
|
4 |
|
5 |
MODEL_THAT_EXISTS = "Systran/faster-whisper-tiny.en"
|
|
|
7 |
MIN_EXPECTED_NUMBER_OF_MODELS = 70 # At the time of the test creation there are 89 models
|
8 |
|
9 |
|
10 |
+
@pytest.mark.asyncio()
|
11 |
+
async def test_list_models(openai_client: AsyncOpenAI) -> None:
|
12 |
+
models = (await openai_client.models.list()).data
|
13 |
assert len(models) > MIN_EXPECTED_NUMBER_OF_MODELS
|
14 |
|
15 |
|
16 |
+
@pytest.mark.asyncio()
|
17 |
+
async def test_model_exists(openai_client: AsyncOpenAI) -> None:
|
18 |
+
model = await openai_client.models.retrieve(MODEL_THAT_EXISTS)
|
19 |
assert model.id == MODEL_THAT_EXISTS
|
20 |
|
21 |
|
22 |
+
@pytest.mark.asyncio()
|
23 |
+
async def test_model_does_not_exist(openai_client: AsyncOpenAI) -> None:
|
24 |
with pytest.raises(openai.NotFoundError):
|
25 |
+
await openai_client.models.retrieve(MODEL_THAT_DOES_NOT_EXIST)
|
tests/conftest.py
CHANGED
@@ -5,7 +5,7 @@ import os
|
|
5 |
from fastapi.testclient import TestClient
|
6 |
from faster_whisper_server.main import create_app
|
7 |
from httpx import ASGITransport, AsyncClient
|
8 |
-
from openai import AsyncOpenAI
|
9 |
import pytest
|
10 |
import pytest_asyncio
|
11 |
|
@@ -32,9 +32,9 @@ async def aclient() -> AsyncGenerator[AsyncClient, None]:
|
|
32 |
yield aclient
|
33 |
|
34 |
|
35 |
-
@
|
36 |
-
def openai_client(
|
37 |
-
return
|
38 |
|
39 |
|
40 |
@pytest.fixture()
|
|
|
5 |
from fastapi.testclient import TestClient
|
6 |
from faster_whisper_server.main import create_app
|
7 |
from httpx import ASGITransport, AsyncClient
|
8 |
+
from openai import AsyncOpenAI
|
9 |
import pytest
|
10 |
import pytest_asyncio
|
11 |
|
|
|
32 |
yield aclient
|
33 |
|
34 |
|
35 |
+
@pytest_asyncio.fixture()
|
36 |
+
def openai_client(aclient: AsyncClient) -> AsyncOpenAI:
|
37 |
+
return AsyncOpenAI(api_key="cant-be-empty", http_client=aclient)
|
38 |
|
39 |
|
40 |
@pytest.fixture()
|