openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/test_fine_tunes.py

274lines · 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 FineTune, FineTuneEventsListResponse
12from openai._client import OpenAI, AsyncOpenAI
13from openai.pagination import SyncPage, AsyncPage
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestFineTunes:
20strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
21loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
22parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
23
24@parametrize
25def test_method_create(self, client: OpenAI) -> None:
26fine_tune = client.fine_tunes.create(
27training_file="file-abc123",
28)
29assert_matches_type(FineTune, fine_tune, path=["response"])
30
31@parametrize
32def test_method_create_with_all_params(self, client: OpenAI) -> None:
33fine_tune = client.fine_tunes.create(
34training_file="file-abc123",
35batch_size=0,
36classification_betas=[0.6, 1, 1.5, 2],
37classification_n_classes=0,
38classification_positive_class="string",
39compute_classification_metrics=True,
40hyperparameters={"n_epochs": "auto"},
41learning_rate_multiplier=0,
42model="curie",
43prompt_loss_weight=0,
44suffix="x",
45validation_file="file-abc123",
46)
47assert_matches_type(FineTune, fine_tune, path=["response"])
48
49@parametrize
50def test_raw_response_create(self, client: OpenAI) -> None:
51response = client.fine_tunes.with_raw_response.create(
52training_file="file-abc123",
53)
54assert response.http_request.headers.get("X-Stainless-Lang") == "python"
55fine_tune = response.parse()
56assert_matches_type(FineTune, fine_tune, path=["response"])
57
58@parametrize
59def test_method_retrieve(self, client: OpenAI) -> None:
60fine_tune = client.fine_tunes.retrieve(
61"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
62)
63assert_matches_type(FineTune, fine_tune, path=["response"])
64
65@parametrize
66def test_raw_response_retrieve(self, client: OpenAI) -> None:
67response = client.fine_tunes.with_raw_response.retrieve(
68"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
69)
70assert response.http_request.headers.get("X-Stainless-Lang") == "python"
71fine_tune = response.parse()
72assert_matches_type(FineTune, fine_tune, path=["response"])
73
74@parametrize
75def test_method_list(self, client: OpenAI) -> None:
76fine_tune = client.fine_tunes.list()
77assert_matches_type(SyncPage[FineTune], fine_tune, path=["response"])
78
79@parametrize
80def test_raw_response_list(self, client: OpenAI) -> None:
81response = client.fine_tunes.with_raw_response.list()
82assert response.http_request.headers.get("X-Stainless-Lang") == "python"
83fine_tune = response.parse()
84assert_matches_type(SyncPage[FineTune], fine_tune, path=["response"])
85
86@parametrize
87def test_method_cancel(self, client: OpenAI) -> None:
88fine_tune = client.fine_tunes.cancel(
89"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
90)
91assert_matches_type(FineTune, fine_tune, path=["response"])
92
93@parametrize
94def test_raw_response_cancel(self, client: OpenAI) -> None:
95response = client.fine_tunes.with_raw_response.cancel(
96"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
97)
98assert response.http_request.headers.get("X-Stainless-Lang") == "python"
99fine_tune = response.parse()
100assert_matches_type(FineTune, fine_tune, path=["response"])
101
102@pytest.mark.skip(reason="Prism chokes on this")
103@parametrize
104def test_method_list_events_overload_1(self, client: OpenAI) -> None:
105fine_tune = client.fine_tunes.list_events(
106"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
107)
108assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
109
110@pytest.mark.skip(reason="Prism chokes on this")
111@parametrize
112def test_method_list_events_with_all_params_overload_1(self, client: OpenAI) -> None:
113fine_tune = client.fine_tunes.list_events(
114"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
115stream=False,
116)
117assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
118
119@pytest.mark.skip(reason="Prism chokes on this")
120@parametrize
121def test_raw_response_list_events_overload_1(self, client: OpenAI) -> None:
122response = client.fine_tunes.with_raw_response.list_events(
123"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
124)
125assert response.http_request.headers.get("X-Stainless-Lang") == "python"
126fine_tune = response.parse()
127assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
128
129@pytest.mark.skip(reason="Prism chokes on this")
130@parametrize
131def test_method_list_events_overload_2(self, client: OpenAI) -> None:
132client.fine_tunes.list_events(
133"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
134stream=True,
135)
136
137@pytest.mark.skip(reason="Prism chokes on this")
138@parametrize
139def test_raw_response_list_events_overload_2(self, client: OpenAI) -> None:
140response = client.fine_tunes.with_raw_response.list_events(
141"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
142stream=True,
143)
144assert response.http_request.headers.get("X-Stainless-Lang") == "python"
145response.parse()
146
147
148class TestAsyncFineTunes:
149strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
150loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
151parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
152
153@parametrize
154async def test_method_create(self, client: AsyncOpenAI) -> None:
155fine_tune = await client.fine_tunes.create(
156training_file="file-abc123",
157)
158assert_matches_type(FineTune, fine_tune, path=["response"])
159
160@parametrize
161async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
162fine_tune = await client.fine_tunes.create(
163training_file="file-abc123",
164batch_size=0,
165classification_betas=[0.6, 1, 1.5, 2],
166classification_n_classes=0,
167classification_positive_class="string",
168compute_classification_metrics=True,
169hyperparameters={"n_epochs": "auto"},
170learning_rate_multiplier=0,
171model="curie",
172prompt_loss_weight=0,
173suffix="x",
174validation_file="file-abc123",
175)
176assert_matches_type(FineTune, fine_tune, path=["response"])
177
178@parametrize
179async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
180response = await client.fine_tunes.with_raw_response.create(
181training_file="file-abc123",
182)
183assert response.http_request.headers.get("X-Stainless-Lang") == "python"
184fine_tune = response.parse()
185assert_matches_type(FineTune, fine_tune, path=["response"])
186
187@parametrize
188async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
189fine_tune = await client.fine_tunes.retrieve(
190"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
191)
192assert_matches_type(FineTune, fine_tune, path=["response"])
193
194@parametrize
195async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
196response = await client.fine_tunes.with_raw_response.retrieve(
197"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
198)
199assert response.http_request.headers.get("X-Stainless-Lang") == "python"
200fine_tune = response.parse()
201assert_matches_type(FineTune, fine_tune, path=["response"])
202
203@parametrize
204async def test_method_list(self, client: AsyncOpenAI) -> None:
205fine_tune = await client.fine_tunes.list()
206assert_matches_type(AsyncPage[FineTune], fine_tune, path=["response"])
207
208@parametrize
209async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
210response = await client.fine_tunes.with_raw_response.list()
211assert response.http_request.headers.get("X-Stainless-Lang") == "python"
212fine_tune = response.parse()
213assert_matches_type(AsyncPage[FineTune], fine_tune, path=["response"])
214
215@parametrize
216async def test_method_cancel(self, client: AsyncOpenAI) -> None:
217fine_tune = await client.fine_tunes.cancel(
218"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
219)
220assert_matches_type(FineTune, fine_tune, path=["response"])
221
222@parametrize
223async def test_raw_response_cancel(self, client: AsyncOpenAI) -> None:
224response = await client.fine_tunes.with_raw_response.cancel(
225"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
226)
227assert response.http_request.headers.get("X-Stainless-Lang") == "python"
228fine_tune = response.parse()
229assert_matches_type(FineTune, fine_tune, path=["response"])
230
231@pytest.mark.skip(reason="Prism chokes on this")
232@parametrize
233async def test_method_list_events_overload_1(self, client: AsyncOpenAI) -> None:
234fine_tune = await client.fine_tunes.list_events(
235"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
236)
237assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
238
239@pytest.mark.skip(reason="Prism chokes on this")
240@parametrize
241async def test_method_list_events_with_all_params_overload_1(self, client: AsyncOpenAI) -> None:
242fine_tune = await client.fine_tunes.list_events(
243"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
244stream=False,
245)
246assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
247
248@pytest.mark.skip(reason="Prism chokes on this")
249@parametrize
250async def test_raw_response_list_events_overload_1(self, client: AsyncOpenAI) -> None:
251response = await client.fine_tunes.with_raw_response.list_events(
252"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
253)
254assert response.http_request.headers.get("X-Stainless-Lang") == "python"
255fine_tune = response.parse()
256assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
257
258@pytest.mark.skip(reason="Prism chokes on this")
259@parametrize
260async def test_method_list_events_overload_2(self, client: AsyncOpenAI) -> None:
261await client.fine_tunes.list_events(
262"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
263stream=True,
264)
265
266@pytest.mark.skip(reason="Prism chokes on this")
267@parametrize
268async def test_raw_response_list_events_overload_2(self, client: AsyncOpenAI) -> None:
269response = await client.fine_tunes.with_raw_response.list_events(
270"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
271stream=True,
272)
273assert response.http_request.headers.get("X-Stainless-Lang") == "python"
274response.parse()