1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2
  3from __future__ import annotations
  4
  5from typing import Dict, Union, Iterable, Optional
  6from typing_extensions import Literal
  7
  8import httpx
  9
 10from .... import _legacy_response
 11from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
 12from ...._utils import maybe_transform, async_maybe_transform
 13from ...._compat import cached_property
 14from .checkpoints import (
 15    Checkpoints,
 16    AsyncCheckpoints,
 17    CheckpointsWithRawResponse,
 18    AsyncCheckpointsWithRawResponse,
 19    CheckpointsWithStreamingResponse,
 20    AsyncCheckpointsWithStreamingResponse,
 21)
 22from ...._resource import SyncAPIResource, AsyncAPIResource
 23from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
 24from ....pagination import SyncCursorPage, AsyncCursorPage
 25from ...._base_client import (
 26    AsyncPaginator,
 27    make_request_options,
 28)
 29from ....types.fine_tuning import job_list_params, job_create_params, job_list_events_params
 30from ....types.shared_params.metadata import Metadata
 31from ....types.fine_tuning.fine_tuning_job import FineTuningJob
 32from ....types.fine_tuning.fine_tuning_job_event import FineTuningJobEvent
 33
 34__all__ = ["Jobs", "AsyncJobs"]
 35
 36
 37class Jobs(SyncAPIResource):
 38    @cached_property
 39    def checkpoints(self) -> Checkpoints:
 40        return Checkpoints(self._client)
 41
 42    @cached_property
 43    def with_raw_response(self) -> JobsWithRawResponse:
 44        """
 45        This property can be used as a prefix for any HTTP method call to return
 46        the raw response object instead of the parsed content.
 47
 48        For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
 49        """
 50        return JobsWithRawResponse(self)
 51
 52    @cached_property
 53    def with_streaming_response(self) -> JobsWithStreamingResponse:
 54        """
 55        An alternative to `.with_raw_response` that doesn't eagerly read the response body.
 56
 57        For more information, see https://www.github.com/openai/openai-python#with_streaming_response
 58        """
 59        return JobsWithStreamingResponse(self)
 60
 61    def create(
 62        self,
 63        *,
 64        model: Union[str, Literal["babbage-002", "davinci-002", "gpt-3.5-turbo", "gpt-4o-mini"]],
 65        training_file: str,
 66        hyperparameters: job_create_params.Hyperparameters | Omit = omit,
 67        integrations: Optional[Iterable[job_create_params.Integration]] | Omit = omit,
 68        metadata: Optional[Metadata] | Omit = omit,
 69        method: job_create_params.Method | Omit = omit,
 70        seed: Optional[int] | Omit = omit,
 71        suffix: Optional[str] | Omit = omit,
 72        validation_file: Optional[str] | Omit = omit,
 73        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
 74        # The extra values given here take precedence over values defined on the client or passed to this method.
 75        extra_headers: Headers | None = None,
 76        extra_query: Query | None = None,
 77        extra_body: Body | None = None,
 78        timeout: float | httpx.Timeout | None | NotGiven = not_given,
 79    ) -> FineTuningJob:
 80        """
 81        Creates a fine-tuning job which begins the process of creating a new model from
 82        a given dataset.
 83
 84        Response includes details of the enqueued job including job status and the name
 85        of the fine-tuned models once complete.
 86
 87        [Learn more about fine-tuning](https://platform.openai.com/docs/guides/model-optimization)
 88
 89        Args:
 90          model: The name of the model to fine-tune. You can select one of the
 91              [supported models](https://platform.openai.com/docs/guides/fine-tuning#which-models-can-be-fine-tuned).
 92
 93          training_file: The ID of an uploaded file that contains training data.
 94
 95              See [upload file](https://platform.openai.com/docs/api-reference/files/create)
 96              for how to upload a file.
 97
 98              Your dataset must be formatted as a JSONL file. Additionally, you must upload
 99              your file with the purpose `fine-tune`.
100
101              The contents of the file should differ depending on if the model uses the
102              [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input),
103              [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)
104              format, or if the fine-tuning method uses the
105              [preference](https://platform.openai.com/docs/api-reference/fine-tuning/preference-input)
106              format.
107
108              See the
109              [fine-tuning guide](https://platform.openai.com/docs/guides/model-optimization)
110              for more details.
111
112          hyperparameters: The hyperparameters used for the fine-tuning job. This value is now deprecated
113              in favor of `method`, and should be passed in under the `method` parameter.
114
115          integrations: A list of integrations to enable for your fine-tuning job.
116
117          metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
118              for storing additional information about the object in a structured format, and
119              querying for objects via API or the dashboard.
120
121              Keys are strings with a maximum length of 64 characters. Values are strings with
122              a maximum length of 512 characters.
123
124          method: The method used for fine-tuning.
125
126          seed: The seed controls the reproducibility of the job. Passing in the same seed and
127              job parameters should produce the same results, but may differ in rare cases. If
128              a seed is not specified, one will be generated for you.
129
130          suffix: A string of up to 64 characters that will be added to your fine-tuned model
131              name.
132
133              For example, a `suffix` of "custom-model-name" would produce a model name like
134              `ft:gpt-4o-mini:openai:custom-model-name:7p4lURel`.
135
136          validation_file: The ID of an uploaded file that contains validation data.
137
138              If you provide this file, the data is used to generate validation metrics
139              periodically during fine-tuning. These metrics can be viewed in the fine-tuning
140              results file. The same data should not be present in both train and validation
141              files.
142
143              Your dataset must be formatted as a JSONL file. You must upload your file with
144              the purpose `fine-tune`.
145
146              See the
147              [fine-tuning guide](https://platform.openai.com/docs/guides/model-optimization)
148              for more details.
149
150          extra_headers: Send extra headers
151
152          extra_query: Add additional query parameters to the request
153
154          extra_body: Add additional JSON properties to the request
155
156          timeout: Override the client-level default timeout for this request, in seconds
157        """
158        return self._post(
159            "/fine_tuning/jobs",
160            body=maybe_transform(
161                {
162                    "model": model,
163                    "training_file": training_file,
164                    "hyperparameters": hyperparameters,
165                    "integrations": integrations,
166                    "metadata": metadata,
167                    "method": method,
168                    "seed": seed,
169                    "suffix": suffix,
170                    "validation_file": validation_file,
171                },
172                job_create_params.JobCreateParams,
173            ),
174            options=make_request_options(
175                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
176            ),
177            cast_to=FineTuningJob,
178        )
179
180    def retrieve(
181        self,
182        fine_tuning_job_id: str,
183        *,
184        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
185        # The extra values given here take precedence over values defined on the client or passed to this method.
186        extra_headers: Headers | None = None,
187        extra_query: Query | None = None,
188        extra_body: Body | None = None,
189        timeout: float | httpx.Timeout | None | NotGiven = not_given,
190    ) -> FineTuningJob:
191        """
192        Get info about a fine-tuning job.
193
194        [Learn more about fine-tuning](https://platform.openai.com/docs/guides/model-optimization)
195
196        Args:
197          extra_headers: Send extra headers
198
199          extra_query: Add additional query parameters to the request
200
201          extra_body: Add additional JSON properties to the request
202
203          timeout: Override the client-level default timeout for this request, in seconds
204        """
205        if not fine_tuning_job_id:
206            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
207        return self._get(
208            f"/fine_tuning/jobs/{fine_tuning_job_id}",
209            options=make_request_options(
210                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
211            ),
212            cast_to=FineTuningJob,
213        )
214
215    def list(
216        self,
217        *,
218        after: str | Omit = omit,
219        limit: int | Omit = omit,
220        metadata: Optional[Dict[str, str]] | Omit = omit,
221        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
222        # The extra values given here take precedence over values defined on the client or passed to this method.
223        extra_headers: Headers | None = None,
224        extra_query: Query | None = None,
225        extra_body: Body | None = None,
226        timeout: float | httpx.Timeout | None | NotGiven = not_given,
227    ) -> SyncCursorPage[FineTuningJob]:
228        """
229        List your organization's fine-tuning jobs
230
231        Args:
232          after: Identifier for the last job from the previous pagination request.
233
234          limit: Number of fine-tuning jobs to retrieve.
235
236          metadata: Optional metadata filter. To filter, use the syntax `metadata[k]=v`.
237              Alternatively, set `metadata=null` to indicate no metadata.
238
239          extra_headers: Send extra headers
240
241          extra_query: Add additional query parameters to the request
242
243          extra_body: Add additional JSON properties to the request
244
245          timeout: Override the client-level default timeout for this request, in seconds
246        """
247        return self._get_api_list(
248            "/fine_tuning/jobs",
249            page=SyncCursorPage[FineTuningJob],
250            options=make_request_options(
251                extra_headers=extra_headers,
252                extra_query=extra_query,
253                extra_body=extra_body,
254                timeout=timeout,
255                query=maybe_transform(
256                    {
257                        "after": after,
258                        "limit": limit,
259                        "metadata": metadata,
260                    },
261                    job_list_params.JobListParams,
262                ),
263            ),
264            model=FineTuningJob,
265        )
266
267    def cancel(
268        self,
269        fine_tuning_job_id: str,
270        *,
271        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
272        # The extra values given here take precedence over values defined on the client or passed to this method.
273        extra_headers: Headers | None = None,
274        extra_query: Query | None = None,
275        extra_body: Body | None = None,
276        timeout: float | httpx.Timeout | None | NotGiven = not_given,
277    ) -> FineTuningJob:
278        """
279        Immediately cancel a fine-tune job.
280
281        Args:
282          extra_headers: Send extra headers
283
284          extra_query: Add additional query parameters to the request
285
286          extra_body: Add additional JSON properties to the request
287
288          timeout: Override the client-level default timeout for this request, in seconds
289        """
290        if not fine_tuning_job_id:
291            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
292        return self._post(
293            f"/fine_tuning/jobs/{fine_tuning_job_id}/cancel",
294            options=make_request_options(
295                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
296            ),
297            cast_to=FineTuningJob,
298        )
299
300    def list_events(
301        self,
302        fine_tuning_job_id: str,
303        *,
304        after: str | Omit = omit,
305        limit: int | Omit = omit,
306        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
307        # The extra values given here take precedence over values defined on the client or passed to this method.
308        extra_headers: Headers | None = None,
309        extra_query: Query | None = None,
310        extra_body: Body | None = None,
311        timeout: float | httpx.Timeout | None | NotGiven = not_given,
312    ) -> SyncCursorPage[FineTuningJobEvent]:
313        """
314        Get status updates for a fine-tuning job.
315
316        Args:
317          after: Identifier for the last event from the previous pagination request.
318
319          limit: Number of events to retrieve.
320
321          extra_headers: Send extra headers
322
323          extra_query: Add additional query parameters to the request
324
325          extra_body: Add additional JSON properties to the request
326
327          timeout: Override the client-level default timeout for this request, in seconds
328        """
329        if not fine_tuning_job_id:
330            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
331        return self._get_api_list(
332            f"/fine_tuning/jobs/{fine_tuning_job_id}/events",
333            page=SyncCursorPage[FineTuningJobEvent],
334            options=make_request_options(
335                extra_headers=extra_headers,
336                extra_query=extra_query,
337                extra_body=extra_body,
338                timeout=timeout,
339                query=maybe_transform(
340                    {
341                        "after": after,
342                        "limit": limit,
343                    },
344                    job_list_events_params.JobListEventsParams,
345                ),
346            ),
347            model=FineTuningJobEvent,
348        )
349
350    def pause(
351        self,
352        fine_tuning_job_id: str,
353        *,
354        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
355        # The extra values given here take precedence over values defined on the client or passed to this method.
356        extra_headers: Headers | None = None,
357        extra_query: Query | None = None,
358        extra_body: Body | None = None,
359        timeout: float | httpx.Timeout | None | NotGiven = not_given,
360    ) -> FineTuningJob:
361        """
362        Pause a fine-tune job.
363
364        Args:
365          extra_headers: Send extra headers
366
367          extra_query: Add additional query parameters to the request
368
369          extra_body: Add additional JSON properties to the request
370
371          timeout: Override the client-level default timeout for this request, in seconds
372        """
373        if not fine_tuning_job_id:
374            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
375        return self._post(
376            f"/fine_tuning/jobs/{fine_tuning_job_id}/pause",
377            options=make_request_options(
378                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
379            ),
380            cast_to=FineTuningJob,
381        )
382
383    def resume(
384        self,
385        fine_tuning_job_id: str,
386        *,
387        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
388        # The extra values given here take precedence over values defined on the client or passed to this method.
389        extra_headers: Headers | None = None,
390        extra_query: Query | None = None,
391        extra_body: Body | None = None,
392        timeout: float | httpx.Timeout | None | NotGiven = not_given,
393    ) -> FineTuningJob:
394        """
395        Resume a fine-tune job.
396
397        Args:
398          extra_headers: Send extra headers
399
400          extra_query: Add additional query parameters to the request
401
402          extra_body: Add additional JSON properties to the request
403
404          timeout: Override the client-level default timeout for this request, in seconds
405        """
406        if not fine_tuning_job_id:
407            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
408        return self._post(
409            f"/fine_tuning/jobs/{fine_tuning_job_id}/resume",
410            options=make_request_options(
411                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
412            ),
413            cast_to=FineTuningJob,
414        )
415
416
417class AsyncJobs(AsyncAPIResource):
418    @cached_property
419    def checkpoints(self) -> AsyncCheckpoints:
420        return AsyncCheckpoints(self._client)
421
422    @cached_property
423    def with_raw_response(self) -> AsyncJobsWithRawResponse:
424        """
425        This property can be used as a prefix for any HTTP method call to return
426        the raw response object instead of the parsed content.
427
428        For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
429        """
430        return AsyncJobsWithRawResponse(self)
431
432    @cached_property
433    def with_streaming_response(self) -> AsyncJobsWithStreamingResponse:
434        """
435        An alternative to `.with_raw_response` that doesn't eagerly read the response body.
436
437        For more information, see https://www.github.com/openai/openai-python#with_streaming_response
438        """
439        return AsyncJobsWithStreamingResponse(self)
440
441    async def create(
442        self,
443        *,
444        model: Union[str, Literal["babbage-002", "davinci-002", "gpt-3.5-turbo", "gpt-4o-mini"]],
445        training_file: str,
446        hyperparameters: job_create_params.Hyperparameters | Omit = omit,
447        integrations: Optional[Iterable[job_create_params.Integration]] | Omit = omit,
448        metadata: Optional[Metadata] | Omit = omit,
449        method: job_create_params.Method | Omit = omit,
450        seed: Optional[int] | Omit = omit,
451        suffix: Optional[str] | Omit = omit,
452        validation_file: Optional[str] | Omit = omit,
453        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
454        # The extra values given here take precedence over values defined on the client or passed to this method.
455        extra_headers: Headers | None = None,
456        extra_query: Query | None = None,
457        extra_body: Body | None = None,
458        timeout: float | httpx.Timeout | None | NotGiven = not_given,
459    ) -> FineTuningJob:
460        """
461        Creates a fine-tuning job which begins the process of creating a new model from
462        a given dataset.
463
464        Response includes details of the enqueued job including job status and the name
465        of the fine-tuned models once complete.
466
467        [Learn more about fine-tuning](https://platform.openai.com/docs/guides/model-optimization)
468
469        Args:
470          model: The name of the model to fine-tune. You can select one of the
471              [supported models](https://platform.openai.com/docs/guides/fine-tuning#which-models-can-be-fine-tuned).
472
473          training_file: The ID of an uploaded file that contains training data.
474
475              See [upload file](https://platform.openai.com/docs/api-reference/files/create)
476              for how to upload a file.
477
478              Your dataset must be formatted as a JSONL file. Additionally, you must upload
479              your file with the purpose `fine-tune`.
480
481              The contents of the file should differ depending on if the model uses the
482              [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input),
483              [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)
484              format, or if the fine-tuning method uses the
485              [preference](https://platform.openai.com/docs/api-reference/fine-tuning/preference-input)
486              format.
487
488              See the
489              [fine-tuning guide](https://platform.openai.com/docs/guides/model-optimization)
490              for more details.
491
492          hyperparameters: The hyperparameters used for the fine-tuning job. This value is now deprecated
493              in favor of `method`, and should be passed in under the `method` parameter.
494
495          integrations: A list of integrations to enable for your fine-tuning job.
496
497          metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
498              for storing additional information about the object in a structured format, and
499              querying for objects via API or the dashboard.
500
501              Keys are strings with a maximum length of 64 characters. Values are strings with
502              a maximum length of 512 characters.
503
504          method: The method used for fine-tuning.
505
506          seed: The seed controls the reproducibility of the job. Passing in the same seed and
507              job parameters should produce the same results, but may differ in rare cases. If
508              a seed is not specified, one will be generated for you.
509
510          suffix: A string of up to 64 characters that will be added to your fine-tuned model
511              name.
512
513              For example, a `suffix` of "custom-model-name" would produce a model name like
514              `ft:gpt-4o-mini:openai:custom-model-name:7p4lURel`.
515
516          validation_file: The ID of an uploaded file that contains validation data.
517
518              If you provide this file, the data is used to generate validation metrics
519              periodically during fine-tuning. These metrics can be viewed in the fine-tuning
520              results file. The same data should not be present in both train and validation
521              files.
522
523              Your dataset must be formatted as a JSONL file. You must upload your file with
524              the purpose `fine-tune`.
525
526              See the
527              [fine-tuning guide](https://platform.openai.com/docs/guides/model-optimization)
528              for more details.
529
530          extra_headers: Send extra headers
531
532          extra_query: Add additional query parameters to the request
533
534          extra_body: Add additional JSON properties to the request
535
536          timeout: Override the client-level default timeout for this request, in seconds
537        """
538        return await self._post(
539            "/fine_tuning/jobs",
540            body=await async_maybe_transform(
541                {
542                    "model": model,
543                    "training_file": training_file,
544                    "hyperparameters": hyperparameters,
545                    "integrations": integrations,
546                    "metadata": metadata,
547                    "method": method,
548                    "seed": seed,
549                    "suffix": suffix,
550                    "validation_file": validation_file,
551                },
552                job_create_params.JobCreateParams,
553            ),
554            options=make_request_options(
555                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
556            ),
557            cast_to=FineTuningJob,
558        )
559
560    async def retrieve(
561        self,
562        fine_tuning_job_id: str,
563        *,
564        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
565        # The extra values given here take precedence over values defined on the client or passed to this method.
566        extra_headers: Headers | None = None,
567        extra_query: Query | None = None,
568        extra_body: Body | None = None,
569        timeout: float | httpx.Timeout | None | NotGiven = not_given,
570    ) -> FineTuningJob:
571        """
572        Get info about a fine-tuning job.
573
574        [Learn more about fine-tuning](https://platform.openai.com/docs/guides/model-optimization)
575
576        Args:
577          extra_headers: Send extra headers
578
579          extra_query: Add additional query parameters to the request
580
581          extra_body: Add additional JSON properties to the request
582
583          timeout: Override the client-level default timeout for this request, in seconds
584        """
585        if not fine_tuning_job_id:
586            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
587        return await self._get(
588            f"/fine_tuning/jobs/{fine_tuning_job_id}",
589            options=make_request_options(
590                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
591            ),
592            cast_to=FineTuningJob,
593        )
594
595    def list(
596        self,
597        *,
598        after: str | Omit = omit,
599        limit: int | Omit = omit,
600        metadata: Optional[Dict[str, str]] | Omit = omit,
601        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
602        # The extra values given here take precedence over values defined on the client or passed to this method.
603        extra_headers: Headers | None = None,
604        extra_query: Query | None = None,
605        extra_body: Body | None = None,
606        timeout: float | httpx.Timeout | None | NotGiven = not_given,
607    ) -> AsyncPaginator[FineTuningJob, AsyncCursorPage[FineTuningJob]]:
608        """
609        List your organization's fine-tuning jobs
610
611        Args:
612          after: Identifier for the last job from the previous pagination request.
613
614          limit: Number of fine-tuning jobs to retrieve.
615
616          metadata: Optional metadata filter. To filter, use the syntax `metadata[k]=v`.
617              Alternatively, set `metadata=null` to indicate no metadata.
618
619          extra_headers: Send extra headers
620
621          extra_query: Add additional query parameters to the request
622
623          extra_body: Add additional JSON properties to the request
624
625          timeout: Override the client-level default timeout for this request, in seconds
626        """
627        return self._get_api_list(
628            "/fine_tuning/jobs",
629            page=AsyncCursorPage[FineTuningJob],
630            options=make_request_options(
631                extra_headers=extra_headers,
632                extra_query=extra_query,
633                extra_body=extra_body,
634                timeout=timeout,
635                query=maybe_transform(
636                    {
637                        "after": after,
638                        "limit": limit,
639                        "metadata": metadata,
640                    },
641                    job_list_params.JobListParams,
642                ),
643            ),
644            model=FineTuningJob,
645        )
646
647    async def cancel(
648        self,
649        fine_tuning_job_id: str,
650        *,
651        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
652        # The extra values given here take precedence over values defined on the client or passed to this method.
653        extra_headers: Headers | None = None,
654        extra_query: Query | None = None,
655        extra_body: Body | None = None,
656        timeout: float | httpx.Timeout | None | NotGiven = not_given,
657    ) -> FineTuningJob:
658        """
659        Immediately cancel a fine-tune job.
660
661        Args:
662          extra_headers: Send extra headers
663
664          extra_query: Add additional query parameters to the request
665
666          extra_body: Add additional JSON properties to the request
667
668          timeout: Override the client-level default timeout for this request, in seconds
669        """
670        if not fine_tuning_job_id:
671            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
672        return await self._post(
673            f"/fine_tuning/jobs/{fine_tuning_job_id}/cancel",
674            options=make_request_options(
675                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
676            ),
677            cast_to=FineTuningJob,
678        )
679
680    def list_events(
681        self,
682        fine_tuning_job_id: str,
683        *,
684        after: str | Omit = omit,
685        limit: int | Omit = omit,
686        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
687        # The extra values given here take precedence over values defined on the client or passed to this method.
688        extra_headers: Headers | None = None,
689        extra_query: Query | None = None,
690        extra_body: Body | None = None,
691        timeout: float | httpx.Timeout | None | NotGiven = not_given,
692    ) -> AsyncPaginator[FineTuningJobEvent, AsyncCursorPage[FineTuningJobEvent]]:
693        """
694        Get status updates for a fine-tuning job.
695
696        Args:
697          after: Identifier for the last event from the previous pagination request.
698
699          limit: Number of events to retrieve.
700
701          extra_headers: Send extra headers
702
703          extra_query: Add additional query parameters to the request
704
705          extra_body: Add additional JSON properties to the request
706
707          timeout: Override the client-level default timeout for this request, in seconds
708        """
709        if not fine_tuning_job_id:
710            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
711        return self._get_api_list(
712            f"/fine_tuning/jobs/{fine_tuning_job_id}/events",
713            page=AsyncCursorPage[FineTuningJobEvent],
714            options=make_request_options(
715                extra_headers=extra_headers,
716                extra_query=extra_query,
717                extra_body=extra_body,
718                timeout=timeout,
719                query=maybe_transform(
720                    {
721                        "after": after,
722                        "limit": limit,
723                    },
724                    job_list_events_params.JobListEventsParams,
725                ),
726            ),
727            model=FineTuningJobEvent,
728        )
729
730    async def pause(
731        self,
732        fine_tuning_job_id: str,
733        *,
734        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
735        # The extra values given here take precedence over values defined on the client or passed to this method.
736        extra_headers: Headers | None = None,
737        extra_query: Query | None = None,
738        extra_body: Body | None = None,
739        timeout: float | httpx.Timeout | None | NotGiven = not_given,
740    ) -> FineTuningJob:
741        """
742        Pause a fine-tune job.
743
744        Args:
745          extra_headers: Send extra headers
746
747          extra_query: Add additional query parameters to the request
748
749          extra_body: Add additional JSON properties to the request
750
751          timeout: Override the client-level default timeout for this request, in seconds
752        """
753        if not fine_tuning_job_id:
754            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
755        return await self._post(
756            f"/fine_tuning/jobs/{fine_tuning_job_id}/pause",
757            options=make_request_options(
758                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
759            ),
760            cast_to=FineTuningJob,
761        )
762
763    async def resume(
764        self,
765        fine_tuning_job_id: str,
766        *,
767        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
768        # The extra values given here take precedence over values defined on the client or passed to this method.
769        extra_headers: Headers | None = None,
770        extra_query: Query | None = None,
771        extra_body: Body | None = None,
772        timeout: float | httpx.Timeout | None | NotGiven = not_given,
773    ) -> FineTuningJob:
774        """
775        Resume a fine-tune job.
776
777        Args:
778          extra_headers: Send extra headers
779
780          extra_query: Add additional query parameters to the request
781
782          extra_body: Add additional JSON properties to the request
783
784          timeout: Override the client-level default timeout for this request, in seconds
785        """
786        if not fine_tuning_job_id:
787            raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
788        return await self._post(
789            f"/fine_tuning/jobs/{fine_tuning_job_id}/resume",
790            options=make_request_options(
791                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
792            ),
793            cast_to=FineTuningJob,
794        )
795
796
797class JobsWithRawResponse:
798    def __init__(self, jobs: Jobs) -> None:
799        self._jobs = jobs
800
801        self.create = _legacy_response.to_raw_response_wrapper(
802            jobs.create,
803        )
804        self.retrieve = _legacy_response.to_raw_response_wrapper(
805            jobs.retrieve,
806        )
807        self.list = _legacy_response.to_raw_response_wrapper(
808            jobs.list,
809        )
810        self.cancel = _legacy_response.to_raw_response_wrapper(
811            jobs.cancel,
812        )
813        self.list_events = _legacy_response.to_raw_response_wrapper(
814            jobs.list_events,
815        )
816        self.pause = _legacy_response.to_raw_response_wrapper(
817            jobs.pause,
818        )
819        self.resume = _legacy_response.to_raw_response_wrapper(
820            jobs.resume,
821        )
822
823    @cached_property
824    def checkpoints(self) -> CheckpointsWithRawResponse:
825        return CheckpointsWithRawResponse(self._jobs.checkpoints)
826
827
828class AsyncJobsWithRawResponse:
829    def __init__(self, jobs: AsyncJobs) -> None:
830        self._jobs = jobs
831
832        self.create = _legacy_response.async_to_raw_response_wrapper(
833            jobs.create,
834        )
835        self.retrieve = _legacy_response.async_to_raw_response_wrapper(
836            jobs.retrieve,
837        )
838        self.list = _legacy_response.async_to_raw_response_wrapper(
839            jobs.list,
840        )
841        self.cancel = _legacy_response.async_to_raw_response_wrapper(
842            jobs.cancel,
843        )
844        self.list_events = _legacy_response.async_to_raw_response_wrapper(
845            jobs.list_events,
846        )
847        self.pause = _legacy_response.async_to_raw_response_wrapper(
848            jobs.pause,
849        )
850        self.resume = _legacy_response.async_to_raw_response_wrapper(
851            jobs.resume,
852        )
853
854    @cached_property
855    def checkpoints(self) -> AsyncCheckpointsWithRawResponse:
856        return AsyncCheckpointsWithRawResponse(self._jobs.checkpoints)
857
858
859class JobsWithStreamingResponse:
860    def __init__(self, jobs: Jobs) -> None:
861        self._jobs = jobs
862
863        self.create = to_streamed_response_wrapper(
864            jobs.create,
865        )
866        self.retrieve = to_streamed_response_wrapper(
867            jobs.retrieve,
868        )
869        self.list = to_streamed_response_wrapper(
870            jobs.list,
871        )
872        self.cancel = to_streamed_response_wrapper(
873            jobs.cancel,
874        )
875        self.list_events = to_streamed_response_wrapper(
876            jobs.list_events,
877        )
878        self.pause = to_streamed_response_wrapper(
879            jobs.pause,
880        )
881        self.resume = to_streamed_response_wrapper(
882            jobs.resume,
883        )
884
885    @cached_property
886    def checkpoints(self) -> CheckpointsWithStreamingResponse:
887        return CheckpointsWithStreamingResponse(self._jobs.checkpoints)
888
889
890class AsyncJobsWithStreamingResponse:
891    def __init__(self, jobs: AsyncJobs) -> None:
892        self._jobs = jobs
893
894        self.create = async_to_streamed_response_wrapper(
895            jobs.create,
896        )
897        self.retrieve = async_to_streamed_response_wrapper(
898            jobs.retrieve,
899        )
900        self.list = async_to_streamed_response_wrapper(
901            jobs.list,
902        )
903        self.cancel = async_to_streamed_response_wrapper(
904            jobs.cancel,
905        )
906        self.list_events = async_to_streamed_response_wrapper(
907            jobs.list_events,
908        )
909        self.pause = async_to_streamed_response_wrapper(
910            jobs.pause,
911        )
912        self.resume = async_to_streamed_response_wrapper(
913            jobs.resume,
914        )
915
916    @cached_property
917    def checkpoints(self) -> AsyncCheckpointsWithStreamingResponse:
918        return AsyncCheckpointsWithStreamingResponse(self._jobs.checkpoints)