openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/test_edits.py
95lines · modeblame
08b8179aDavid Schnurr2 years ago | 1 | # File generated from our OpenAPI spec by Stainless. |
| 2 | | |
| 3 | from __future__ import annotations | |
| 4 | | |
| 5 | import os | |
| 6 | | |
| 7 | import pytest | |
| 8 | | |
| 9 | from openai import OpenAI, AsyncOpenAI | |
| 10 | from tests.utils import assert_matches_type | |
| 11 | from openai.types import Edit | |
| 12 | from openai._client import OpenAI, AsyncOpenAI | |
| 13 | | |
| 14 | # pyright: reportDeprecated=false | |
| 15 | | |
| 16 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") | |
| 17 | api_key = "My API Key" | |
| 18 | | |
| 19 | | |
| 20 | class TestEdits: | |
| 21 | strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) | |
| 22 | loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) | |
| 23 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) | |
| 24 | | |
| 25 | @parametrize | |
| 26 | def test_method_create(self, client: OpenAI) -> None: | |
| 27 | with pytest.warns(DeprecationWarning): | |
| 28 | edit = client.edits.create( | |
| 29 | instruction="Fix the spelling mistakes.", | |
| 30 | model="text-davinci-edit-001", | |
| 31 | ) | |
| 32 | assert_matches_type(Edit, edit, path=["response"]) | |
| 33 | | |
| 34 | @parametrize | |
| 35 | def test_method_create_with_all_params(self, client: OpenAI) -> None: | |
| 36 | with pytest.warns(DeprecationWarning): | |
| 37 | edit = client.edits.create( | |
| 38 | instruction="Fix the spelling mistakes.", | |
| 39 | model="text-davinci-edit-001", | |
| 40 | input="What day of the wek is it?", | |
| 41 | n=1, | |
| 42 | temperature=1, | |
| 43 | top_p=1, | |
| 44 | ) | |
| 45 | assert_matches_type(Edit, edit, path=["response"]) | |
| 46 | | |
| 47 | @parametrize | |
| 48 | def test_raw_response_create(self, client: OpenAI) -> None: | |
| 49 | with pytest.warns(DeprecationWarning): | |
| 50 | response = client.edits.with_raw_response.create( | |
| 51 | instruction="Fix the spelling mistakes.", | |
| 52 | model="text-davinci-edit-001", | |
| 53 | ) | |
| 54 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 55 | edit = response.parse() | |
| 56 | assert_matches_type(Edit, edit, path=["response"]) | |
| 57 | | |
| 58 | | |
| 59 | class TestAsyncEdits: | |
| 60 | strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) | |
| 61 | loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) | |
| 62 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) | |
| 63 | | |
| 64 | @parametrize | |
| 65 | async def test_method_create(self, client: AsyncOpenAI) -> None: | |
| 66 | with pytest.warns(DeprecationWarning): | |
| 67 | edit = await client.edits.create( | |
| 68 | instruction="Fix the spelling mistakes.", | |
| 69 | model="text-davinci-edit-001", | |
| 70 | ) | |
| 71 | assert_matches_type(Edit, edit, path=["response"]) | |
| 72 | | |
| 73 | @parametrize | |
| 74 | async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None: | |
| 75 | with pytest.warns(DeprecationWarning): | |
| 76 | edit = await client.edits.create( | |
| 77 | instruction="Fix the spelling mistakes.", | |
| 78 | model="text-davinci-edit-001", | |
| 79 | input="What day of the wek is it?", | |
| 80 | n=1, | |
| 81 | temperature=1, | |
| 82 | top_p=1, | |
| 83 | ) | |
| 84 | assert_matches_type(Edit, edit, path=["response"]) | |
| 85 | | |
| 86 | @parametrize | |
| 87 | async def test_raw_response_create(self, client: AsyncOpenAI) -> None: | |
| 88 | with pytest.warns(DeprecationWarning): | |
| 89 | response = await client.edits.with_raw_response.create( | |
| 90 | instruction="Fix the spelling mistakes.", | |
| 91 | model="text-davinci-edit-001", | |
| 92 | ) | |
| 93 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 94 | edit = response.parse() | |
| 95 | assert_matches_type(Edit, edit, path=["response"]) |