main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import httpx
6
7from .... import _legacy_response
8from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
9from ...._utils import maybe_transform
10from ...._compat import cached_property
11from ...._resource import SyncAPIResource, AsyncAPIResource
12from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
13from ....pagination import SyncCursorPage, AsyncCursorPage
14from ...._base_client import (
15 AsyncPaginator,
16 make_request_options,
17)
18from ....types.fine_tuning.jobs import checkpoint_list_params
19from ....types.fine_tuning.jobs.fine_tuning_job_checkpoint import FineTuningJobCheckpoint
20
21__all__ = ["Checkpoints", "AsyncCheckpoints"]
22
23
24class Checkpoints(SyncAPIResource):
25 @cached_property
26 def with_raw_response(self) -> CheckpointsWithRawResponse:
27 """
28 This property can be used as a prefix for any HTTP method call to return
29 the raw response object instead of the parsed content.
30
31 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
32 """
33 return CheckpointsWithRawResponse(self)
34
35 @cached_property
36 def with_streaming_response(self) -> CheckpointsWithStreamingResponse:
37 """
38 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
39
40 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
41 """
42 return CheckpointsWithStreamingResponse(self)
43
44 def list(
45 self,
46 fine_tuning_job_id: str,
47 *,
48 after: str | Omit = omit,
49 limit: int | Omit = omit,
50 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
51 # The extra values given here take precedence over values defined on the client or passed to this method.
52 extra_headers: Headers | None = None,
53 extra_query: Query | None = None,
54 extra_body: Body | None = None,
55 timeout: float | httpx.Timeout | None | NotGiven = not_given,
56 ) -> SyncCursorPage[FineTuningJobCheckpoint]:
57 """
58 List checkpoints for a fine-tuning job.
59
60 Args:
61 after: Identifier for the last checkpoint ID from the previous pagination request.
62
63 limit: Number of checkpoints to retrieve.
64
65 extra_headers: Send extra headers
66
67 extra_query: Add additional query parameters to the request
68
69 extra_body: Add additional JSON properties to the request
70
71 timeout: Override the client-level default timeout for this request, in seconds
72 """
73 if not fine_tuning_job_id:
74 raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
75 return self._get_api_list(
76 f"/fine_tuning/jobs/{fine_tuning_job_id}/checkpoints",
77 page=SyncCursorPage[FineTuningJobCheckpoint],
78 options=make_request_options(
79 extra_headers=extra_headers,
80 extra_query=extra_query,
81 extra_body=extra_body,
82 timeout=timeout,
83 query=maybe_transform(
84 {
85 "after": after,
86 "limit": limit,
87 },
88 checkpoint_list_params.CheckpointListParams,
89 ),
90 ),
91 model=FineTuningJobCheckpoint,
92 )
93
94
95class AsyncCheckpoints(AsyncAPIResource):
96 @cached_property
97 def with_raw_response(self) -> AsyncCheckpointsWithRawResponse:
98 """
99 This property can be used as a prefix for any HTTP method call to return
100 the raw response object instead of the parsed content.
101
102 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
103 """
104 return AsyncCheckpointsWithRawResponse(self)
105
106 @cached_property
107 def with_streaming_response(self) -> AsyncCheckpointsWithStreamingResponse:
108 """
109 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
110
111 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
112 """
113 return AsyncCheckpointsWithStreamingResponse(self)
114
115 def list(
116 self,
117 fine_tuning_job_id: str,
118 *,
119 after: str | Omit = omit,
120 limit: int | Omit = omit,
121 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
122 # The extra values given here take precedence over values defined on the client or passed to this method.
123 extra_headers: Headers | None = None,
124 extra_query: Query | None = None,
125 extra_body: Body | None = None,
126 timeout: float | httpx.Timeout | None | NotGiven = not_given,
127 ) -> AsyncPaginator[FineTuningJobCheckpoint, AsyncCursorPage[FineTuningJobCheckpoint]]:
128 """
129 List checkpoints for a fine-tuning job.
130
131 Args:
132 after: Identifier for the last checkpoint ID from the previous pagination request.
133
134 limit: Number of checkpoints to retrieve.
135
136 extra_headers: Send extra headers
137
138 extra_query: Add additional query parameters to the request
139
140 extra_body: Add additional JSON properties to the request
141
142 timeout: Override the client-level default timeout for this request, in seconds
143 """
144 if not fine_tuning_job_id:
145 raise ValueError(f"Expected a non-empty value for `fine_tuning_job_id` but received {fine_tuning_job_id!r}")
146 return self._get_api_list(
147 f"/fine_tuning/jobs/{fine_tuning_job_id}/checkpoints",
148 page=AsyncCursorPage[FineTuningJobCheckpoint],
149 options=make_request_options(
150 extra_headers=extra_headers,
151 extra_query=extra_query,
152 extra_body=extra_body,
153 timeout=timeout,
154 query=maybe_transform(
155 {
156 "after": after,
157 "limit": limit,
158 },
159 checkpoint_list_params.CheckpointListParams,
160 ),
161 ),
162 model=FineTuningJobCheckpoint,
163 )
164
165
166class CheckpointsWithRawResponse:
167 def __init__(self, checkpoints: Checkpoints) -> None:
168 self._checkpoints = checkpoints
169
170 self.list = _legacy_response.to_raw_response_wrapper(
171 checkpoints.list,
172 )
173
174
175class AsyncCheckpointsWithRawResponse:
176 def __init__(self, checkpoints: AsyncCheckpoints) -> None:
177 self._checkpoints = checkpoints
178
179 self.list = _legacy_response.async_to_raw_response_wrapper(
180 checkpoints.list,
181 )
182
183
184class CheckpointsWithStreamingResponse:
185 def __init__(self, checkpoints: Checkpoints) -> None:
186 self._checkpoints = checkpoints
187
188 self.list = to_streamed_response_wrapper(
189 checkpoints.list,
190 )
191
192
193class AsyncCheckpointsWithStreamingResponse:
194 def __init__(self, checkpoints: AsyncCheckpoints) -> None:
195 self._checkpoints = checkpoints
196
197 self.list = async_to_streamed_response_wrapper(
198 checkpoints.list,
199 )