openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.11.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/fine_tuning/test_jobs.py

436lines · modecode

1# File generated from our OpenAPI spec by Stainless.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.fine_tuning import (
14 FineTuningJob,
15 FineTuningJobEvent,
16)
17
18base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
19
20
21class TestJobs:
22 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
23
24 @parametrize
25 def test_method_create(self, client: OpenAI) -> None:
26 job = client.fine_tuning.jobs.create(
27 model="gpt-3.5-turbo",
28 training_file="file-abc123",
29 )
30 assert_matches_type(FineTuningJob, job, path=["response"])
31
32 @parametrize
33 def test_method_create_with_all_params(self, client: OpenAI) -> None:
34 job = client.fine_tuning.jobs.create(
35 model="gpt-3.5-turbo",
36 training_file="file-abc123",
37 hyperparameters={
38 "batch_size": "auto",
39 "learning_rate_multiplier": "auto",
40 "n_epochs": "auto",
41 },
42 suffix="x",
43 validation_file="file-abc123",
44 )
45 assert_matches_type(FineTuningJob, job, path=["response"])
46
47 @parametrize
48 def test_raw_response_create(self, client: OpenAI) -> None:
49 response = client.fine_tuning.jobs.with_raw_response.create(
50 model="gpt-3.5-turbo",
51 training_file="file-abc123",
52 )
53
54 assert response.is_closed is True
55 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
56 job = response.parse()
57 assert_matches_type(FineTuningJob, job, path=["response"])
58
59 @parametrize
60 def test_streaming_response_create(self, client: OpenAI) -> None:
61 with client.fine_tuning.jobs.with_streaming_response.create(
62 model="gpt-3.5-turbo",
63 training_file="file-abc123",
64 ) as response:
65 assert not response.is_closed
66 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
67
68 job = response.parse()
69 assert_matches_type(FineTuningJob, job, path=["response"])
70
71 assert cast(Any, response.is_closed) is True
72
73 @parametrize
74 def test_method_retrieve(self, client: OpenAI) -> None:
75 job = client.fine_tuning.jobs.retrieve(
76 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
77 )
78 assert_matches_type(FineTuningJob, job, path=["response"])
79
80 @parametrize
81 def test_raw_response_retrieve(self, client: OpenAI) -> None:
82 response = client.fine_tuning.jobs.with_raw_response.retrieve(
83 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
84 )
85
86 assert response.is_closed is True
87 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
88 job = response.parse()
89 assert_matches_type(FineTuningJob, job, path=["response"])
90
91 @parametrize
92 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
93 with client.fine_tuning.jobs.with_streaming_response.retrieve(
94 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
95 ) as response:
96 assert not response.is_closed
97 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
98
99 job = response.parse()
100 assert_matches_type(FineTuningJob, job, path=["response"])
101
102 assert cast(Any, response.is_closed) is True
103
104 @parametrize
105 def test_path_params_retrieve(self, client: OpenAI) -> None:
106 with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"):
107 client.fine_tuning.jobs.with_raw_response.retrieve(
108 "",
109 )
110
111 @parametrize
112 def test_method_list(self, client: OpenAI) -> None:
113 job = client.fine_tuning.jobs.list()
114 assert_matches_type(SyncCursorPage[FineTuningJob], job, path=["response"])
115
116 @parametrize
117 def test_method_list_with_all_params(self, client: OpenAI) -> None:
118 job = client.fine_tuning.jobs.list(
119 after="string",
120 limit=0,
121 )
122 assert_matches_type(SyncCursorPage[FineTuningJob], job, path=["response"])
123
124 @parametrize
125 def test_raw_response_list(self, client: OpenAI) -> None:
126 response = client.fine_tuning.jobs.with_raw_response.list()
127
128 assert response.is_closed is True
129 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
130 job = response.parse()
131 assert_matches_type(SyncCursorPage[FineTuningJob], job, path=["response"])
132
133 @parametrize
134 def test_streaming_response_list(self, client: OpenAI) -> None:
135 with client.fine_tuning.jobs.with_streaming_response.list() as response:
136 assert not response.is_closed
137 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
138
139 job = response.parse()
140 assert_matches_type(SyncCursorPage[FineTuningJob], job, path=["response"])
141
142 assert cast(Any, response.is_closed) is True
143
144 @parametrize
145 def test_method_cancel(self, client: OpenAI) -> None:
146 job = client.fine_tuning.jobs.cancel(
147 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
148 )
149 assert_matches_type(FineTuningJob, job, path=["response"])
150
151 @parametrize
152 def test_raw_response_cancel(self, client: OpenAI) -> None:
153 response = client.fine_tuning.jobs.with_raw_response.cancel(
154 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
155 )
156
157 assert response.is_closed is True
158 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
159 job = response.parse()
160 assert_matches_type(FineTuningJob, job, path=["response"])
161
162 @parametrize
163 def test_streaming_response_cancel(self, client: OpenAI) -> None:
164 with client.fine_tuning.jobs.with_streaming_response.cancel(
165 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
166 ) as response:
167 assert not response.is_closed
168 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
169
170 job = response.parse()
171 assert_matches_type(FineTuningJob, job, path=["response"])
172
173 assert cast(Any, response.is_closed) is True
174
175 @parametrize
176 def test_path_params_cancel(self, client: OpenAI) -> None:
177 with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"):
178 client.fine_tuning.jobs.with_raw_response.cancel(
179 "",
180 )
181
182 @parametrize
183 def test_method_list_events(self, client: OpenAI) -> None:
184 job = client.fine_tuning.jobs.list_events(
185 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
186 )
187 assert_matches_type(SyncCursorPage[FineTuningJobEvent], job, path=["response"])
188
189 @parametrize
190 def test_method_list_events_with_all_params(self, client: OpenAI) -> None:
191 job = client.fine_tuning.jobs.list_events(
192 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
193 after="string",
194 limit=0,
195 )
196 assert_matches_type(SyncCursorPage[FineTuningJobEvent], job, path=["response"])
197
198 @parametrize
199 def test_raw_response_list_events(self, client: OpenAI) -> None:
200 response = client.fine_tuning.jobs.with_raw_response.list_events(
201 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
202 )
203
204 assert response.is_closed is True
205 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
206 job = response.parse()
207 assert_matches_type(SyncCursorPage[FineTuningJobEvent], job, path=["response"])
208
209 @parametrize
210 def test_streaming_response_list_events(self, client: OpenAI) -> None:
211 with client.fine_tuning.jobs.with_streaming_response.list_events(
212 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
213 ) as response:
214 assert not response.is_closed
215 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
216
217 job = response.parse()
218 assert_matches_type(SyncCursorPage[FineTuningJobEvent], job, path=["response"])
219
220 assert cast(Any, response.is_closed) is True
221
222 @parametrize
223 def test_path_params_list_events(self, client: OpenAI) -> None:
224 with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"):
225 client.fine_tuning.jobs.with_raw_response.list_events(
226 "",
227 )
228
229
230class TestAsyncJobs:
231 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
232
233 @parametrize
234 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
235 job = await async_client.fine_tuning.jobs.create(
236 model="gpt-3.5-turbo",
237 training_file="file-abc123",
238 )
239 assert_matches_type(FineTuningJob, job, path=["response"])
240
241 @parametrize
242 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
243 job = await async_client.fine_tuning.jobs.create(
244 model="gpt-3.5-turbo",
245 training_file="file-abc123",
246 hyperparameters={
247 "batch_size": "auto",
248 "learning_rate_multiplier": "auto",
249 "n_epochs": "auto",
250 },
251 suffix="x",
252 validation_file="file-abc123",
253 )
254 assert_matches_type(FineTuningJob, job, path=["response"])
255
256 @parametrize
257 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
258 response = await async_client.fine_tuning.jobs.with_raw_response.create(
259 model="gpt-3.5-turbo",
260 training_file="file-abc123",
261 )
262
263 assert response.is_closed is True
264 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
265 job = response.parse()
266 assert_matches_type(FineTuningJob, job, path=["response"])
267
268 @parametrize
269 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
270 async with async_client.fine_tuning.jobs.with_streaming_response.create(
271 model="gpt-3.5-turbo",
272 training_file="file-abc123",
273 ) as response:
274 assert not response.is_closed
275 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
276
277 job = await response.parse()
278 assert_matches_type(FineTuningJob, job, path=["response"])
279
280 assert cast(Any, response.is_closed) is True
281
282 @parametrize
283 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
284 job = await async_client.fine_tuning.jobs.retrieve(
285 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
286 )
287 assert_matches_type(FineTuningJob, job, path=["response"])
288
289 @parametrize
290 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
291 response = await async_client.fine_tuning.jobs.with_raw_response.retrieve(
292 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
293 )
294
295 assert response.is_closed is True
296 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
297 job = response.parse()
298 assert_matches_type(FineTuningJob, job, path=["response"])
299
300 @parametrize
301 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
302 async with async_client.fine_tuning.jobs.with_streaming_response.retrieve(
303 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
304 ) as response:
305 assert not response.is_closed
306 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
307
308 job = await response.parse()
309 assert_matches_type(FineTuningJob, job, path=["response"])
310
311 assert cast(Any, response.is_closed) is True
312
313 @parametrize
314 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
315 with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"):
316 await async_client.fine_tuning.jobs.with_raw_response.retrieve(
317 "",
318 )
319
320 @parametrize
321 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
322 job = await async_client.fine_tuning.jobs.list()
323 assert_matches_type(AsyncCursorPage[FineTuningJob], job, path=["response"])
324
325 @parametrize
326 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
327 job = await async_client.fine_tuning.jobs.list(
328 after="string",
329 limit=0,
330 )
331 assert_matches_type(AsyncCursorPage[FineTuningJob], job, path=["response"])
332
333 @parametrize
334 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
335 response = await async_client.fine_tuning.jobs.with_raw_response.list()
336
337 assert response.is_closed is True
338 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
339 job = response.parse()
340 assert_matches_type(AsyncCursorPage[FineTuningJob], job, path=["response"])
341
342 @parametrize
343 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
344 async with async_client.fine_tuning.jobs.with_streaming_response.list() as response:
345 assert not response.is_closed
346 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
347
348 job = await response.parse()
349 assert_matches_type(AsyncCursorPage[FineTuningJob], job, path=["response"])
350
351 assert cast(Any, response.is_closed) is True
352
353 @parametrize
354 async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
355 job = await async_client.fine_tuning.jobs.cancel(
356 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
357 )
358 assert_matches_type(FineTuningJob, job, path=["response"])
359
360 @parametrize
361 async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
362 response = await async_client.fine_tuning.jobs.with_raw_response.cancel(
363 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
364 )
365
366 assert response.is_closed is True
367 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
368 job = response.parse()
369 assert_matches_type(FineTuningJob, job, path=["response"])
370
371 @parametrize
372 async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
373 async with async_client.fine_tuning.jobs.with_streaming_response.cancel(
374 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
375 ) as response:
376 assert not response.is_closed
377 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
378
379 job = await response.parse()
380 assert_matches_type(FineTuningJob, job, path=["response"])
381
382 assert cast(Any, response.is_closed) is True
383
384 @parametrize
385 async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
386 with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"):
387 await async_client.fine_tuning.jobs.with_raw_response.cancel(
388 "",
389 )
390
391 @parametrize
392 async def test_method_list_events(self, async_client: AsyncOpenAI) -> None:
393 job = await async_client.fine_tuning.jobs.list_events(
394 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
395 )
396 assert_matches_type(AsyncCursorPage[FineTuningJobEvent], job, path=["response"])
397
398 @parametrize
399 async def test_method_list_events_with_all_params(self, async_client: AsyncOpenAI) -> None:
400 job = await async_client.fine_tuning.jobs.list_events(
401 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
402 after="string",
403 limit=0,
404 )
405 assert_matches_type(AsyncCursorPage[FineTuningJobEvent], job, path=["response"])
406
407 @parametrize
408 async def test_raw_response_list_events(self, async_client: AsyncOpenAI) -> None:
409 response = await async_client.fine_tuning.jobs.with_raw_response.list_events(
410 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
411 )
412
413 assert response.is_closed is True
414 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
415 job = response.parse()
416 assert_matches_type(AsyncCursorPage[FineTuningJobEvent], job, path=["response"])
417
418 @parametrize
419 async def test_streaming_response_list_events(self, async_client: AsyncOpenAI) -> None:
420 async with async_client.fine_tuning.jobs.with_streaming_response.list_events(
421 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
422 ) as response:
423 assert not response.is_closed
424 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
425
426 job = await response.parse()
427 assert_matches_type(AsyncCursorPage[FineTuningJobEvent], job, path=["response"])
428
429 assert cast(Any, response.is_closed) is True
430
431 @parametrize
432 async def test_path_params_list_events(self, async_client: AsyncOpenAI) -> None:
433 with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"):
434 await async_client.fine_tuning.jobs.with_raw_response.list_events(
435 "",
436 )
437