openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
tests/api_resources/fine_tuning/test_jobs.py
690lines · modecode
| 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | from typing import Any, cast |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from openai import OpenAI, AsyncOpenAI |
| 11 | from tests.utils import assert_matches_type |
| 12 | from openai.pagination import SyncCursorPage, AsyncCursorPage |
| 13 | from openai.types.fine_tuning import ( |
| 14 | FineTuningJob, |
| 15 | FineTuningJobEvent, |
| 16 | ) |
| 17 | |
| 18 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 19 | |
| 20 | |
| 21 | class 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-4o-mini", |
| 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-4o-mini", |
| 36 | training_file="file-abc123", |
| 37 | hyperparameters={ |
| 38 | "batch_size": "auto", |
| 39 | "learning_rate_multiplier": "auto", |
| 40 | "n_epochs": "auto", |
| 41 | }, |
| 42 | integrations=[ |
| 43 | { |
| 44 | "type": "wandb", |
| 45 | "wandb": { |
| 46 | "project": "my-wandb-project", |
| 47 | "entity": "entity", |
| 48 | "name": "name", |
| 49 | "tags": ["custom-tag"], |
| 50 | }, |
| 51 | } |
| 52 | ], |
| 53 | metadata={"foo": "string"}, |
| 54 | method={ |
| 55 | "type": "supervised", |
| 56 | "dpo": { |
| 57 | "hyperparameters": { |
| 58 | "batch_size": "auto", |
| 59 | "beta": "auto", |
| 60 | "learning_rate_multiplier": "auto", |
| 61 | "n_epochs": "auto", |
| 62 | } |
| 63 | }, |
| 64 | "reinforcement": { |
| 65 | "grader": { |
| 66 | "input": "input", |
| 67 | "name": "name", |
| 68 | "operation": "eq", |
| 69 | "reference": "reference", |
| 70 | "type": "string_check", |
| 71 | }, |
| 72 | "hyperparameters": { |
| 73 | "batch_size": "auto", |
| 74 | "compute_multiplier": "auto", |
| 75 | "eval_interval": "auto", |
| 76 | "eval_samples": "auto", |
| 77 | "learning_rate_multiplier": "auto", |
| 78 | "n_epochs": "auto", |
| 79 | "reasoning_effort": "default", |
| 80 | }, |
| 81 | }, |
| 82 | "supervised": { |
| 83 | "hyperparameters": { |
| 84 | "batch_size": "auto", |
| 85 | "learning_rate_multiplier": "auto", |
| 86 | "n_epochs": "auto", |
| 87 | } |
| 88 | }, |
| 89 | }, |
| 90 | seed=42, |
| 91 | suffix="x", |
| 92 | validation_file="file-abc123", |
| 93 | ) |
| 94 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 95 | |
| 96 | @parametrize |
| 97 | def test_raw_response_create(self, client: OpenAI) -> None: |
| 98 | response = client.fine_tuning.jobs.with_raw_response.create( |
| 99 | model="gpt-4o-mini", |
| 100 | training_file="file-abc123", |
| 101 | ) |
| 102 | |
| 103 | assert response.is_closed is True |
| 104 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 105 | job = response.parse() |
| 106 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 107 | |
| 108 | @parametrize |
| 109 | def test_streaming_response_create(self, client: OpenAI) -> None: |
| 110 | with client.fine_tuning.jobs.with_streaming_response.create( |
| 111 | model="gpt-4o-mini", |
| 112 | training_file="file-abc123", |
| 113 | ) as response: |
| 114 | assert not response.is_closed |
| 115 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 116 | |
| 117 | job = response.parse() |
| 118 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 119 | |
| 120 | assert cast(Any, response.is_closed) is True |
| 121 | |
| 122 | @parametrize |
| 123 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 124 | job = client.fine_tuning.jobs.retrieve( |
| 125 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 126 | ) |
| 127 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 128 | |
| 129 | @parametrize |
| 130 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 131 | response = client.fine_tuning.jobs.with_raw_response.retrieve( |
| 132 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 133 | ) |
| 134 | |
| 135 | assert response.is_closed is True |
| 136 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 137 | job = response.parse() |
| 138 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 139 | |
| 140 | @parametrize |
| 141 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 142 | with client.fine_tuning.jobs.with_streaming_response.retrieve( |
| 143 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 144 | ) as response: |
| 145 | assert not response.is_closed |
| 146 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 147 | |
| 148 | job = response.parse() |
| 149 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 150 | |
| 151 | assert cast(Any, response.is_closed) is True |
| 152 | |
| 153 | @parametrize |
| 154 | def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 155 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 156 | client.fine_tuning.jobs.with_raw_response.retrieve( |
| 157 | "", |
| 158 | ) |
| 159 | |
| 160 | @parametrize |
| 161 | def test_method_list(self, client: OpenAI) -> None: |
| 162 | job = client.fine_tuning.jobs.list() |
| 163 | assert_matches_type(SyncCursorPage[FineTuningJob], job, path=["response"]) |
| 164 | |
| 165 | @parametrize |
| 166 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 167 | job = client.fine_tuning.jobs.list( |
| 168 | after="string", |
| 169 | limit=0, |
| 170 | metadata={"foo": "string"}, |
| 171 | ) |
| 172 | assert_matches_type(SyncCursorPage[FineTuningJob], job, path=["response"]) |
| 173 | |
| 174 | @parametrize |
| 175 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 176 | response = client.fine_tuning.jobs.with_raw_response.list() |
| 177 | |
| 178 | assert response.is_closed is True |
| 179 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 180 | job = response.parse() |
| 181 | assert_matches_type(SyncCursorPage[FineTuningJob], job, path=["response"]) |
| 182 | |
| 183 | @parametrize |
| 184 | def test_streaming_response_list(self, client: OpenAI) -> None: |
| 185 | with client.fine_tuning.jobs.with_streaming_response.list() as response: |
| 186 | assert not response.is_closed |
| 187 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 188 | |
| 189 | job = response.parse() |
| 190 | assert_matches_type(SyncCursorPage[FineTuningJob], job, path=["response"]) |
| 191 | |
| 192 | assert cast(Any, response.is_closed) is True |
| 193 | |
| 194 | @parametrize |
| 195 | def test_method_cancel(self, client: OpenAI) -> None: |
| 196 | job = client.fine_tuning.jobs.cancel( |
| 197 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 198 | ) |
| 199 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 200 | |
| 201 | @parametrize |
| 202 | def test_raw_response_cancel(self, client: OpenAI) -> None: |
| 203 | response = client.fine_tuning.jobs.with_raw_response.cancel( |
| 204 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 205 | ) |
| 206 | |
| 207 | assert response.is_closed is True |
| 208 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 209 | job = response.parse() |
| 210 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 211 | |
| 212 | @parametrize |
| 213 | def test_streaming_response_cancel(self, client: OpenAI) -> None: |
| 214 | with client.fine_tuning.jobs.with_streaming_response.cancel( |
| 215 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 216 | ) as response: |
| 217 | assert not response.is_closed |
| 218 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 219 | |
| 220 | job = response.parse() |
| 221 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 222 | |
| 223 | assert cast(Any, response.is_closed) is True |
| 224 | |
| 225 | @parametrize |
| 226 | def test_path_params_cancel(self, client: OpenAI) -> None: |
| 227 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 228 | client.fine_tuning.jobs.with_raw_response.cancel( |
| 229 | "", |
| 230 | ) |
| 231 | |
| 232 | @parametrize |
| 233 | def test_method_list_events(self, client: OpenAI) -> None: |
| 234 | job = client.fine_tuning.jobs.list_events( |
| 235 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 236 | ) |
| 237 | assert_matches_type(SyncCursorPage[FineTuningJobEvent], job, path=["response"]) |
| 238 | |
| 239 | @parametrize |
| 240 | def test_method_list_events_with_all_params(self, client: OpenAI) -> None: |
| 241 | job = client.fine_tuning.jobs.list_events( |
| 242 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 243 | after="string", |
| 244 | limit=0, |
| 245 | ) |
| 246 | assert_matches_type(SyncCursorPage[FineTuningJobEvent], job, path=["response"]) |
| 247 | |
| 248 | @parametrize |
| 249 | def test_raw_response_list_events(self, client: OpenAI) -> None: |
| 250 | response = client.fine_tuning.jobs.with_raw_response.list_events( |
| 251 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 252 | ) |
| 253 | |
| 254 | assert response.is_closed is True |
| 255 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 256 | job = response.parse() |
| 257 | assert_matches_type(SyncCursorPage[FineTuningJobEvent], job, path=["response"]) |
| 258 | |
| 259 | @parametrize |
| 260 | def test_streaming_response_list_events(self, client: OpenAI) -> None: |
| 261 | with client.fine_tuning.jobs.with_streaming_response.list_events( |
| 262 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 263 | ) as response: |
| 264 | assert not response.is_closed |
| 265 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 266 | |
| 267 | job = response.parse() |
| 268 | assert_matches_type(SyncCursorPage[FineTuningJobEvent], job, path=["response"]) |
| 269 | |
| 270 | assert cast(Any, response.is_closed) is True |
| 271 | |
| 272 | @parametrize |
| 273 | def test_path_params_list_events(self, client: OpenAI) -> None: |
| 274 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 275 | client.fine_tuning.jobs.with_raw_response.list_events( |
| 276 | "", |
| 277 | ) |
| 278 | |
| 279 | @parametrize |
| 280 | def test_method_pause(self, client: OpenAI) -> None: |
| 281 | job = client.fine_tuning.jobs.pause( |
| 282 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 283 | ) |
| 284 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 285 | |
| 286 | @parametrize |
| 287 | def test_raw_response_pause(self, client: OpenAI) -> None: |
| 288 | response = client.fine_tuning.jobs.with_raw_response.pause( |
| 289 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 290 | ) |
| 291 | |
| 292 | assert response.is_closed is True |
| 293 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 294 | job = response.parse() |
| 295 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 296 | |
| 297 | @parametrize |
| 298 | def test_streaming_response_pause(self, client: OpenAI) -> None: |
| 299 | with client.fine_tuning.jobs.with_streaming_response.pause( |
| 300 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 301 | ) as response: |
| 302 | assert not response.is_closed |
| 303 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 304 | |
| 305 | job = response.parse() |
| 306 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 307 | |
| 308 | assert cast(Any, response.is_closed) is True |
| 309 | |
| 310 | @parametrize |
| 311 | def test_path_params_pause(self, client: OpenAI) -> None: |
| 312 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 313 | client.fine_tuning.jobs.with_raw_response.pause( |
| 314 | "", |
| 315 | ) |
| 316 | |
| 317 | @parametrize |
| 318 | def test_method_resume(self, client: OpenAI) -> None: |
| 319 | job = client.fine_tuning.jobs.resume( |
| 320 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 321 | ) |
| 322 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 323 | |
| 324 | @parametrize |
| 325 | def test_raw_response_resume(self, client: OpenAI) -> None: |
| 326 | response = client.fine_tuning.jobs.with_raw_response.resume( |
| 327 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 328 | ) |
| 329 | |
| 330 | assert response.is_closed is True |
| 331 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 332 | job = response.parse() |
| 333 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 334 | |
| 335 | @parametrize |
| 336 | def test_streaming_response_resume(self, client: OpenAI) -> None: |
| 337 | with client.fine_tuning.jobs.with_streaming_response.resume( |
| 338 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 339 | ) as response: |
| 340 | assert not response.is_closed |
| 341 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 342 | |
| 343 | job = response.parse() |
| 344 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 345 | |
| 346 | assert cast(Any, response.is_closed) is True |
| 347 | |
| 348 | @parametrize |
| 349 | def test_path_params_resume(self, client: OpenAI) -> None: |
| 350 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 351 | client.fine_tuning.jobs.with_raw_response.resume( |
| 352 | "", |
| 353 | ) |
| 354 | |
| 355 | |
| 356 | class TestAsyncJobs: |
| 357 | parametrize = pytest.mark.parametrize( |
| 358 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 359 | ) |
| 360 | |
| 361 | @parametrize |
| 362 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
| 363 | job = await async_client.fine_tuning.jobs.create( |
| 364 | model="gpt-4o-mini", |
| 365 | training_file="file-abc123", |
| 366 | ) |
| 367 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 368 | |
| 369 | @parametrize |
| 370 | async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 371 | job = await async_client.fine_tuning.jobs.create( |
| 372 | model="gpt-4o-mini", |
| 373 | training_file="file-abc123", |
| 374 | hyperparameters={ |
| 375 | "batch_size": "auto", |
| 376 | "learning_rate_multiplier": "auto", |
| 377 | "n_epochs": "auto", |
| 378 | }, |
| 379 | integrations=[ |
| 380 | { |
| 381 | "type": "wandb", |
| 382 | "wandb": { |
| 383 | "project": "my-wandb-project", |
| 384 | "entity": "entity", |
| 385 | "name": "name", |
| 386 | "tags": ["custom-tag"], |
| 387 | }, |
| 388 | } |
| 389 | ], |
| 390 | metadata={"foo": "string"}, |
| 391 | method={ |
| 392 | "type": "supervised", |
| 393 | "dpo": { |
| 394 | "hyperparameters": { |
| 395 | "batch_size": "auto", |
| 396 | "beta": "auto", |
| 397 | "learning_rate_multiplier": "auto", |
| 398 | "n_epochs": "auto", |
| 399 | } |
| 400 | }, |
| 401 | "reinforcement": { |
| 402 | "grader": { |
| 403 | "input": "input", |
| 404 | "name": "name", |
| 405 | "operation": "eq", |
| 406 | "reference": "reference", |
| 407 | "type": "string_check", |
| 408 | }, |
| 409 | "hyperparameters": { |
| 410 | "batch_size": "auto", |
| 411 | "compute_multiplier": "auto", |
| 412 | "eval_interval": "auto", |
| 413 | "eval_samples": "auto", |
| 414 | "learning_rate_multiplier": "auto", |
| 415 | "n_epochs": "auto", |
| 416 | "reasoning_effort": "default", |
| 417 | }, |
| 418 | }, |
| 419 | "supervised": { |
| 420 | "hyperparameters": { |
| 421 | "batch_size": "auto", |
| 422 | "learning_rate_multiplier": "auto", |
| 423 | "n_epochs": "auto", |
| 424 | } |
| 425 | }, |
| 426 | }, |
| 427 | seed=42, |
| 428 | suffix="x", |
| 429 | validation_file="file-abc123", |
| 430 | ) |
| 431 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 432 | |
| 433 | @parametrize |
| 434 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
| 435 | response = await async_client.fine_tuning.jobs.with_raw_response.create( |
| 436 | model="gpt-4o-mini", |
| 437 | training_file="file-abc123", |
| 438 | ) |
| 439 | |
| 440 | assert response.is_closed is True |
| 441 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 442 | job = response.parse() |
| 443 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 444 | |
| 445 | @parametrize |
| 446 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
| 447 | async with async_client.fine_tuning.jobs.with_streaming_response.create( |
| 448 | model="gpt-4o-mini", |
| 449 | training_file="file-abc123", |
| 450 | ) as response: |
| 451 | assert not response.is_closed |
| 452 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 453 | |
| 454 | job = await response.parse() |
| 455 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 456 | |
| 457 | assert cast(Any, response.is_closed) is True |
| 458 | |
| 459 | @parametrize |
| 460 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 461 | job = await async_client.fine_tuning.jobs.retrieve( |
| 462 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 463 | ) |
| 464 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 465 | |
| 466 | @parametrize |
| 467 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 468 | response = await async_client.fine_tuning.jobs.with_raw_response.retrieve( |
| 469 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 470 | ) |
| 471 | |
| 472 | assert response.is_closed is True |
| 473 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 474 | job = response.parse() |
| 475 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 476 | |
| 477 | @parametrize |
| 478 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 479 | async with async_client.fine_tuning.jobs.with_streaming_response.retrieve( |
| 480 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 481 | ) as response: |
| 482 | assert not response.is_closed |
| 483 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 484 | |
| 485 | job = await response.parse() |
| 486 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 487 | |
| 488 | assert cast(Any, response.is_closed) is True |
| 489 | |
| 490 | @parametrize |
| 491 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 492 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 493 | await async_client.fine_tuning.jobs.with_raw_response.retrieve( |
| 494 | "", |
| 495 | ) |
| 496 | |
| 497 | @parametrize |
| 498 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 499 | job = await async_client.fine_tuning.jobs.list() |
| 500 | assert_matches_type(AsyncCursorPage[FineTuningJob], job, path=["response"]) |
| 501 | |
| 502 | @parametrize |
| 503 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 504 | job = await async_client.fine_tuning.jobs.list( |
| 505 | after="string", |
| 506 | limit=0, |
| 507 | metadata={"foo": "string"}, |
| 508 | ) |
| 509 | assert_matches_type(AsyncCursorPage[FineTuningJob], job, path=["response"]) |
| 510 | |
| 511 | @parametrize |
| 512 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 513 | response = await async_client.fine_tuning.jobs.with_raw_response.list() |
| 514 | |
| 515 | assert response.is_closed is True |
| 516 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 517 | job = response.parse() |
| 518 | assert_matches_type(AsyncCursorPage[FineTuningJob], job, path=["response"]) |
| 519 | |
| 520 | @parametrize |
| 521 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 522 | async with async_client.fine_tuning.jobs.with_streaming_response.list() as response: |
| 523 | assert not response.is_closed |
| 524 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 525 | |
| 526 | job = await response.parse() |
| 527 | assert_matches_type(AsyncCursorPage[FineTuningJob], job, path=["response"]) |
| 528 | |
| 529 | assert cast(Any, response.is_closed) is True |
| 530 | |
| 531 | @parametrize |
| 532 | async def test_method_cancel(self, async_client: AsyncOpenAI) -> None: |
| 533 | job = await async_client.fine_tuning.jobs.cancel( |
| 534 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 535 | ) |
| 536 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 537 | |
| 538 | @parametrize |
| 539 | async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None: |
| 540 | response = await async_client.fine_tuning.jobs.with_raw_response.cancel( |
| 541 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 542 | ) |
| 543 | |
| 544 | assert response.is_closed is True |
| 545 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 546 | job = response.parse() |
| 547 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 548 | |
| 549 | @parametrize |
| 550 | async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None: |
| 551 | async with async_client.fine_tuning.jobs.with_streaming_response.cancel( |
| 552 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 553 | ) as response: |
| 554 | assert not response.is_closed |
| 555 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 556 | |
| 557 | job = await response.parse() |
| 558 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 559 | |
| 560 | assert cast(Any, response.is_closed) is True |
| 561 | |
| 562 | @parametrize |
| 563 | async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None: |
| 564 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 565 | await async_client.fine_tuning.jobs.with_raw_response.cancel( |
| 566 | "", |
| 567 | ) |
| 568 | |
| 569 | @parametrize |
| 570 | async def test_method_list_events(self, async_client: AsyncOpenAI) -> None: |
| 571 | job = await async_client.fine_tuning.jobs.list_events( |
| 572 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 573 | ) |
| 574 | assert_matches_type(AsyncCursorPage[FineTuningJobEvent], job, path=["response"]) |
| 575 | |
| 576 | @parametrize |
| 577 | async def test_method_list_events_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 578 | job = await async_client.fine_tuning.jobs.list_events( |
| 579 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 580 | after="string", |
| 581 | limit=0, |
| 582 | ) |
| 583 | assert_matches_type(AsyncCursorPage[FineTuningJobEvent], job, path=["response"]) |
| 584 | |
| 585 | @parametrize |
| 586 | async def test_raw_response_list_events(self, async_client: AsyncOpenAI) -> None: |
| 587 | response = await async_client.fine_tuning.jobs.with_raw_response.list_events( |
| 588 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 589 | ) |
| 590 | |
| 591 | assert response.is_closed is True |
| 592 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 593 | job = response.parse() |
| 594 | assert_matches_type(AsyncCursorPage[FineTuningJobEvent], job, path=["response"]) |
| 595 | |
| 596 | @parametrize |
| 597 | async def test_streaming_response_list_events(self, async_client: AsyncOpenAI) -> None: |
| 598 | async with async_client.fine_tuning.jobs.with_streaming_response.list_events( |
| 599 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 600 | ) as response: |
| 601 | assert not response.is_closed |
| 602 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 603 | |
| 604 | job = await response.parse() |
| 605 | assert_matches_type(AsyncCursorPage[FineTuningJobEvent], job, path=["response"]) |
| 606 | |
| 607 | assert cast(Any, response.is_closed) is True |
| 608 | |
| 609 | @parametrize |
| 610 | async def test_path_params_list_events(self, async_client: AsyncOpenAI) -> None: |
| 611 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 612 | await async_client.fine_tuning.jobs.with_raw_response.list_events( |
| 613 | "", |
| 614 | ) |
| 615 | |
| 616 | @parametrize |
| 617 | async def test_method_pause(self, async_client: AsyncOpenAI) -> None: |
| 618 | job = await async_client.fine_tuning.jobs.pause( |
| 619 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 620 | ) |
| 621 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 622 | |
| 623 | @parametrize |
| 624 | async def test_raw_response_pause(self, async_client: AsyncOpenAI) -> None: |
| 625 | response = await async_client.fine_tuning.jobs.with_raw_response.pause( |
| 626 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 627 | ) |
| 628 | |
| 629 | assert response.is_closed is True |
| 630 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 631 | job = response.parse() |
| 632 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 633 | |
| 634 | @parametrize |
| 635 | async def test_streaming_response_pause(self, async_client: AsyncOpenAI) -> None: |
| 636 | async with async_client.fine_tuning.jobs.with_streaming_response.pause( |
| 637 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 638 | ) as response: |
| 639 | assert not response.is_closed |
| 640 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 641 | |
| 642 | job = await response.parse() |
| 643 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 644 | |
| 645 | assert cast(Any, response.is_closed) is True |
| 646 | |
| 647 | @parametrize |
| 648 | async def test_path_params_pause(self, async_client: AsyncOpenAI) -> None: |
| 649 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 650 | await async_client.fine_tuning.jobs.with_raw_response.pause( |
| 651 | "", |
| 652 | ) |
| 653 | |
| 654 | @parametrize |
| 655 | async def test_method_resume(self, async_client: AsyncOpenAI) -> None: |
| 656 | job = await async_client.fine_tuning.jobs.resume( |
| 657 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 658 | ) |
| 659 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 660 | |
| 661 | @parametrize |
| 662 | async def test_raw_response_resume(self, async_client: AsyncOpenAI) -> None: |
| 663 | response = await async_client.fine_tuning.jobs.with_raw_response.resume( |
| 664 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 665 | ) |
| 666 | |
| 667 | assert response.is_closed is True |
| 668 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 669 | job = response.parse() |
| 670 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 671 | |
| 672 | @parametrize |
| 673 | async def test_streaming_response_resume(self, async_client: AsyncOpenAI) -> None: |
| 674 | async with async_client.fine_tuning.jobs.with_streaming_response.resume( |
| 675 | "ft-AF1WoRqd3aJAHsqc9NY7iL8F", |
| 676 | ) as response: |
| 677 | assert not response.is_closed |
| 678 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 679 | |
| 680 | job = await response.parse() |
| 681 | assert_matches_type(FineTuningJob, job, path=["response"]) |
| 682 | |
| 683 | assert cast(Any, response.is_closed) is True |
| 684 | |
| 685 | @parametrize |
| 686 | async def test_path_params_resume(self, async_client: AsyncOpenAI) -> None: |
| 687 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"): |
| 688 | await async_client.fine_tuning.jobs.with_raw_response.resume( |
| 689 | "", |
| 690 | ) |
| 691 | |