openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/test_edits.py

95lines · modeblame

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