2024-03-19 11:49:15 -04:00
|
|
|
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2023-11-06 08:19:00 -08:00
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import os
|
2024-01-15 09:11:27 -05:00
|
|
|
from typing import Any, cast
|
2023-11-06 08:19:00 -08:00
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from openai import OpenAI, AsyncOpenAI
|
|
|
|
|
from tests.utils import assert_matches_type
|
2024-04-26 09:48:35 -04:00
|
|
|
from openai.types import Model, ModelDeleted
|
2023-11-06 08:19:00 -08:00
|
|
|
from openai.pagination import SyncPage, AsyncPage
|
|
|
|
|
|
|
|
|
|
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestModels:
|
2024-01-18 11:41:33 -05:00
|
|
|
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
|
2023-11-06 08:19:00 -08:00
|
|
|
|
|
|
|
|
@parametrize
|
|
|
|
|
def test_method_retrieve(self, client: OpenAI) -> None:
|
|
|
|
|
model = client.models.retrieve(
|
2024-08-06 17:29:45 +00:00
|
|
|
"gpt-4o-mini",
|
2023-11-06 08:19:00 -08:00
|
|
|
)
|
|
|
|
|
assert_matches_type(Model, model, path=["response"])
|
|
|
|
|
|
|
|
|
|
@parametrize
|
|
|
|
|
def test_raw_response_retrieve(self, client: OpenAI) -> None:
|
|
|
|
|
response = client.models.with_raw_response.retrieve(
|
2024-08-06 17:29:45 +00:00
|
|
|
"gpt-4o-mini",
|
2023-11-06 08:19:00 -08:00
|
|
|
)
|
2024-01-15 09:11:27 -05:00
|
|
|
|
|
|
|
|
assert response.is_closed is True
|
2023-11-06 08:19:00 -08:00
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
model = response.parse()
|
|
|
|
|
assert_matches_type(Model, model, path=["response"])
|
|
|
|
|
|
2024-01-15 09:11:27 -05:00
|
|
|
@parametrize
|
|
|
|
|
def test_streaming_response_retrieve(self, client: OpenAI) -> None:
|
|
|
|
|
with client.models.with_streaming_response.retrieve(
|
2024-08-06 17:29:45 +00:00
|
|
|
"gpt-4o-mini",
|
2024-01-15 09:11:27 -05:00
|
|
|
) as response:
|
|
|
|
|
assert not response.is_closed
|
|
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
|
|
|
|
|
model = response.parse()
|
|
|
|
|
assert_matches_type(Model, model, path=["response"])
|
|
|
|
|
|
|
|
|
|
assert cast(Any, response.is_closed) is True
|
|
|
|
|
|
2024-01-16 05:50:40 -05:00
|
|
|
@parametrize
|
|
|
|
|
def test_path_params_retrieve(self, client: OpenAI) -> None:
|
|
|
|
|
with pytest.raises(ValueError, match=r"Expected a non-empty value for `model` but received ''"):
|
|
|
|
|
client.models.with_raw_response.retrieve(
|
|
|
|
|
"",
|
|
|
|
|
)
|
|
|
|
|
|
2023-11-06 08:19:00 -08:00
|
|
|
@parametrize
|
|
|
|
|
def test_method_list(self, client: OpenAI) -> None:
|
|
|
|
|
model = client.models.list()
|
|
|
|
|
assert_matches_type(SyncPage[Model], model, path=["response"])
|
|
|
|
|
|
|
|
|
|
@parametrize
|
|
|
|
|
def test_raw_response_list(self, client: OpenAI) -> None:
|
|
|
|
|
response = client.models.with_raw_response.list()
|
2024-01-15 09:11:27 -05:00
|
|
|
|
|
|
|
|
assert response.is_closed is True
|
2023-11-06 08:19:00 -08:00
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
model = response.parse()
|
|
|
|
|
assert_matches_type(SyncPage[Model], model, path=["response"])
|
|
|
|
|
|
2024-01-15 09:11:27 -05:00
|
|
|
@parametrize
|
|
|
|
|
def test_streaming_response_list(self, client: OpenAI) -> None:
|
|
|
|
|
with client.models.with_streaming_response.list() as response:
|
|
|
|
|
assert not response.is_closed
|
|
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
|
|
|
|
|
model = response.parse()
|
|
|
|
|
assert_matches_type(SyncPage[Model], model, path=["response"])
|
|
|
|
|
|
|
|
|
|
assert cast(Any, response.is_closed) is True
|
|
|
|
|
|
2023-11-06 08:19:00 -08:00
|
|
|
@parametrize
|
|
|
|
|
def test_method_delete(self, client: OpenAI) -> None:
|
|
|
|
|
model = client.models.delete(
|
2024-08-06 17:29:45 +00:00
|
|
|
"ft:gpt-4o-mini:acemeco:suffix:abc123",
|
2023-11-06 08:19:00 -08:00
|
|
|
)
|
|
|
|
|
assert_matches_type(ModelDeleted, model, path=["response"])
|
|
|
|
|
|
|
|
|
|
@parametrize
|
|
|
|
|
def test_raw_response_delete(self, client: OpenAI) -> None:
|
|
|
|
|
response = client.models.with_raw_response.delete(
|
2024-08-06 17:29:45 +00:00
|
|
|
"ft:gpt-4o-mini:acemeco:suffix:abc123",
|
2023-11-06 08:19:00 -08:00
|
|
|
)
|
2024-01-15 09:11:27 -05:00
|
|
|
|
|
|
|
|
assert response.is_closed is True
|
2023-11-06 08:19:00 -08:00
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
model = response.parse()
|
|
|
|
|
assert_matches_type(ModelDeleted, model, path=["response"])
|
|
|
|
|
|
2024-01-15 09:11:27 -05:00
|
|
|
@parametrize
|
|
|
|
|
def test_streaming_response_delete(self, client: OpenAI) -> None:
|
|
|
|
|
with client.models.with_streaming_response.delete(
|
2024-08-06 17:29:45 +00:00
|
|
|
"ft:gpt-4o-mini:acemeco:suffix:abc123",
|
2024-01-15 09:11:27 -05:00
|
|
|
) as response:
|
|
|
|
|
assert not response.is_closed
|
|
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
|
|
|
|
|
model = response.parse()
|
|
|
|
|
assert_matches_type(ModelDeleted, model, path=["response"])
|
|
|
|
|
|
|
|
|
|
assert cast(Any, response.is_closed) is True
|
|
|
|
|
|
2024-01-16 05:50:40 -05:00
|
|
|
@parametrize
|
|
|
|
|
def test_path_params_delete(self, client: OpenAI) -> None:
|
|
|
|
|
with pytest.raises(ValueError, match=r"Expected a non-empty value for `model` but received ''"):
|
|
|
|
|
client.models.with_raw_response.delete(
|
|
|
|
|
"",
|
|
|
|
|
)
|
|
|
|
|
|
2023-11-06 08:19:00 -08:00
|
|
|
|
|
|
|
|
class TestAsyncModels:
|
2025-06-20 18:00:13 +00:00
|
|
|
parametrize = pytest.mark.parametrize(
|
|
|
|
|
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
|
|
|
|
|
)
|
2023-11-06 08:19:00 -08:00
|
|
|
|
|
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
|
|
|
|
|
model = await async_client.models.retrieve(
|
2024-08-06 17:29:45 +00:00
|
|
|
"gpt-4o-mini",
|
2023-11-06 08:19:00 -08:00
|
|
|
)
|
|
|
|
|
assert_matches_type(Model, model, path=["response"])
|
|
|
|
|
|
|
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
|
|
|
|
|
response = await async_client.models.with_raw_response.retrieve(
|
2024-08-06 17:29:45 +00:00
|
|
|
"gpt-4o-mini",
|
2023-11-06 08:19:00 -08:00
|
|
|
)
|
2024-01-15 09:11:27 -05:00
|
|
|
|
|
|
|
|
assert response.is_closed is True
|
2023-11-06 08:19:00 -08:00
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
model = response.parse()
|
|
|
|
|
assert_matches_type(Model, model, path=["response"])
|
|
|
|
|
|
2024-01-15 09:11:27 -05:00
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
|
|
|
|
|
async with async_client.models.with_streaming_response.retrieve(
|
2024-08-06 17:29:45 +00:00
|
|
|
"gpt-4o-mini",
|
2024-01-15 09:11:27 -05:00
|
|
|
) as response:
|
|
|
|
|
assert not response.is_closed
|
|
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
|
|
|
|
|
model = await response.parse()
|
|
|
|
|
assert_matches_type(Model, model, path=["response"])
|
|
|
|
|
|
|
|
|
|
assert cast(Any, response.is_closed) is True
|
|
|
|
|
|
2024-01-16 05:50:40 -05:00
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
|
2024-01-16 05:50:40 -05:00
|
|
|
with pytest.raises(ValueError, match=r"Expected a non-empty value for `model` but received ''"):
|
2024-01-18 11:41:33 -05:00
|
|
|
await async_client.models.with_raw_response.retrieve(
|
2024-01-16 05:50:40 -05:00
|
|
|
"",
|
|
|
|
|
)
|
|
|
|
|
|
2023-11-06 08:19:00 -08:00
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_method_list(self, async_client: AsyncOpenAI) -> None:
|
|
|
|
|
model = await async_client.models.list()
|
2023-11-06 08:19:00 -08:00
|
|
|
assert_matches_type(AsyncPage[Model], model, path=["response"])
|
|
|
|
|
|
|
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
|
|
|
|
|
response = await async_client.models.with_raw_response.list()
|
2024-01-15 09:11:27 -05:00
|
|
|
|
|
|
|
|
assert response.is_closed is True
|
2023-11-06 08:19:00 -08:00
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
model = response.parse()
|
|
|
|
|
assert_matches_type(AsyncPage[Model], model, path=["response"])
|
|
|
|
|
|
2024-01-15 09:11:27 -05:00
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
|
|
|
|
|
async with async_client.models.with_streaming_response.list() as response:
|
2024-01-15 09:11:27 -05:00
|
|
|
assert not response.is_closed
|
|
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
|
|
|
|
|
model = await response.parse()
|
|
|
|
|
assert_matches_type(AsyncPage[Model], model, path=["response"])
|
|
|
|
|
|
|
|
|
|
assert cast(Any, response.is_closed) is True
|
|
|
|
|
|
2023-11-06 08:19:00 -08:00
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
|
|
|
|
|
model = await async_client.models.delete(
|
2024-08-06 17:29:45 +00:00
|
|
|
"ft:gpt-4o-mini:acemeco:suffix:abc123",
|
2023-11-06 08:19:00 -08:00
|
|
|
)
|
|
|
|
|
assert_matches_type(ModelDeleted, model, path=["response"])
|
|
|
|
|
|
|
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
|
|
|
|
|
response = await async_client.models.with_raw_response.delete(
|
2024-08-06 17:29:45 +00:00
|
|
|
"ft:gpt-4o-mini:acemeco:suffix:abc123",
|
2023-11-06 08:19:00 -08:00
|
|
|
)
|
2024-01-15 09:11:27 -05:00
|
|
|
|
|
|
|
|
assert response.is_closed is True
|
2023-11-06 08:19:00 -08:00
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
model = response.parse()
|
|
|
|
|
assert_matches_type(ModelDeleted, model, path=["response"])
|
2024-01-15 09:11:27 -05:00
|
|
|
|
|
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
|
|
|
|
|
async with async_client.models.with_streaming_response.delete(
|
2024-08-06 17:29:45 +00:00
|
|
|
"ft:gpt-4o-mini:acemeco:suffix:abc123",
|
2024-01-15 09:11:27 -05:00
|
|
|
) as response:
|
|
|
|
|
assert not response.is_closed
|
|
|
|
|
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
|
|
|
|
|
|
|
|
|
model = await response.parse()
|
|
|
|
|
assert_matches_type(ModelDeleted, model, path=["response"])
|
|
|
|
|
|
|
|
|
|
assert cast(Any, response.is_closed) is True
|
2024-01-16 05:50:40 -05:00
|
|
|
|
|
|
|
|
@parametrize
|
2024-01-18 11:41:33 -05:00
|
|
|
async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
|
2024-01-16 05:50:40 -05:00
|
|
|
with pytest.raises(ValueError, match=r"Expected a non-empty value for `model` but received ''"):
|
2024-01-18 11:41:33 -05:00
|
|
|
await async_client.models.with_raw_response.delete(
|
2024-01-16 05:50:40 -05:00
|
|
|
"",
|
|
|
|
|
)
|