main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import typing_extensions
6from typing import List
7from typing_extensions import Literal
8
9import httpx
10
11from ..... import _legacy_response
12from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
13from ....._utils import maybe_transform, async_maybe_transform
14from ....._compat import cached_property
15from ....._resource import SyncAPIResource, AsyncAPIResource
16from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
17from .....pagination import SyncCursorPage, AsyncCursorPage
18from ....._base_client import AsyncPaginator, make_request_options
19from .....types.beta.threads.runs import step_list_params, step_retrieve_params
20from .....types.beta.threads.runs.run_step import RunStep
21from .....types.beta.threads.runs.run_step_include import RunStepInclude
22
23__all__ = ["Steps", "AsyncSteps"]
24
25
26class Steps(SyncAPIResource):
27 @cached_property
28 def with_raw_response(self) -> StepsWithRawResponse:
29 """
30 This property can be used as a prefix for any HTTP method call to return
31 the raw response object instead of the parsed content.
32
33 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
34 """
35 return StepsWithRawResponse(self)
36
37 @cached_property
38 def with_streaming_response(self) -> StepsWithStreamingResponse:
39 """
40 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
41
42 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
43 """
44 return StepsWithStreamingResponse(self)
45
46 @typing_extensions.deprecated("The Assistants API is deprecated in favor of the Responses API")
47 def retrieve(
48 self,
49 step_id: str,
50 *,
51 thread_id: str,
52 run_id: str,
53 include: List[RunStepInclude] | Omit = omit,
54 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
55 # The extra values given here take precedence over values defined on the client or passed to this method.
56 extra_headers: Headers | None = None,
57 extra_query: Query | None = None,
58 extra_body: Body | None = None,
59 timeout: float | httpx.Timeout | None | NotGiven = not_given,
60 ) -> RunStep:
61 """
62 Retrieves a run step.
63
64 Args:
65 include: A list of additional fields to include in the response. Currently the only
66 supported value is `step_details.tool_calls[*].file_search.results[*].content`
67 to fetch the file search result content.
68
69 See the
70 [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
71 for more information.
72
73 extra_headers: Send extra headers
74
75 extra_query: Add additional query parameters to the request
76
77 extra_body: Add additional JSON properties to the request
78
79 timeout: Override the client-level default timeout for this request, in seconds
80 """
81 if not thread_id:
82 raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
83 if not run_id:
84 raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
85 if not step_id:
86 raise ValueError(f"Expected a non-empty value for `step_id` but received {step_id!r}")
87 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
88 return self._get(
89 f"/threads/{thread_id}/runs/{run_id}/steps/{step_id}",
90 options=make_request_options(
91 extra_headers=extra_headers,
92 extra_query=extra_query,
93 extra_body=extra_body,
94 timeout=timeout,
95 query=maybe_transform({"include": include}, step_retrieve_params.StepRetrieveParams),
96 ),
97 cast_to=RunStep,
98 )
99
100 @typing_extensions.deprecated("The Assistants API is deprecated in favor of the Responses API")
101 def list(
102 self,
103 run_id: str,
104 *,
105 thread_id: str,
106 after: str | Omit = omit,
107 before: str | Omit = omit,
108 include: List[RunStepInclude] | Omit = omit,
109 limit: int | Omit = omit,
110 order: Literal["asc", "desc"] | Omit = omit,
111 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
112 # The extra values given here take precedence over values defined on the client or passed to this method.
113 extra_headers: Headers | None = None,
114 extra_query: Query | None = None,
115 extra_body: Body | None = None,
116 timeout: float | httpx.Timeout | None | NotGiven = not_given,
117 ) -> SyncCursorPage[RunStep]:
118 """
119 Returns a list of run steps belonging to a run.
120
121 Args:
122 after: A cursor for use in pagination. `after` is an object ID that defines your place
123 in the list. For instance, if you make a list request and receive 100 objects,
124 ending with obj_foo, your subsequent call can include after=obj_foo in order to
125 fetch the next page of the list.
126
127 before: A cursor for use in pagination. `before` is an object ID that defines your place
128 in the list. For instance, if you make a list request and receive 100 objects,
129 starting with obj_foo, your subsequent call can include before=obj_foo in order
130 to fetch the previous page of the list.
131
132 include: A list of additional fields to include in the response. Currently the only
133 supported value is `step_details.tool_calls[*].file_search.results[*].content`
134 to fetch the file search result content.
135
136 See the
137 [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
138 for more information.
139
140 limit: A limit on the number of objects to be returned. Limit can range between 1 and
141 100, and the default is 20.
142
143 order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
144 order and `desc` for descending order.
145
146 extra_headers: Send extra headers
147
148 extra_query: Add additional query parameters to the request
149
150 extra_body: Add additional JSON properties to the request
151
152 timeout: Override the client-level default timeout for this request, in seconds
153 """
154 if not thread_id:
155 raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
156 if not run_id:
157 raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
158 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
159 return self._get_api_list(
160 f"/threads/{thread_id}/runs/{run_id}/steps",
161 page=SyncCursorPage[RunStep],
162 options=make_request_options(
163 extra_headers=extra_headers,
164 extra_query=extra_query,
165 extra_body=extra_body,
166 timeout=timeout,
167 query=maybe_transform(
168 {
169 "after": after,
170 "before": before,
171 "include": include,
172 "limit": limit,
173 "order": order,
174 },
175 step_list_params.StepListParams,
176 ),
177 ),
178 model=RunStep,
179 )
180
181
182class AsyncSteps(AsyncAPIResource):
183 @cached_property
184 def with_raw_response(self) -> AsyncStepsWithRawResponse:
185 """
186 This property can be used as a prefix for any HTTP method call to return
187 the raw response object instead of the parsed content.
188
189 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
190 """
191 return AsyncStepsWithRawResponse(self)
192
193 @cached_property
194 def with_streaming_response(self) -> AsyncStepsWithStreamingResponse:
195 """
196 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
197
198 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
199 """
200 return AsyncStepsWithStreamingResponse(self)
201
202 @typing_extensions.deprecated("The Assistants API is deprecated in favor of the Responses API")
203 async def retrieve(
204 self,
205 step_id: str,
206 *,
207 thread_id: str,
208 run_id: str,
209 include: List[RunStepInclude] | Omit = omit,
210 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
211 # The extra values given here take precedence over values defined on the client or passed to this method.
212 extra_headers: Headers | None = None,
213 extra_query: Query | None = None,
214 extra_body: Body | None = None,
215 timeout: float | httpx.Timeout | None | NotGiven = not_given,
216 ) -> RunStep:
217 """
218 Retrieves a run step.
219
220 Args:
221 include: A list of additional fields to include in the response. Currently the only
222 supported value is `step_details.tool_calls[*].file_search.results[*].content`
223 to fetch the file search result content.
224
225 See the
226 [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
227 for more information.
228
229 extra_headers: Send extra headers
230
231 extra_query: Add additional query parameters to the request
232
233 extra_body: Add additional JSON properties to the request
234
235 timeout: Override the client-level default timeout for this request, in seconds
236 """
237 if not thread_id:
238 raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
239 if not run_id:
240 raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
241 if not step_id:
242 raise ValueError(f"Expected a non-empty value for `step_id` but received {step_id!r}")
243 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
244 return await self._get(
245 f"/threads/{thread_id}/runs/{run_id}/steps/{step_id}",
246 options=make_request_options(
247 extra_headers=extra_headers,
248 extra_query=extra_query,
249 extra_body=extra_body,
250 timeout=timeout,
251 query=await async_maybe_transform({"include": include}, step_retrieve_params.StepRetrieveParams),
252 ),
253 cast_to=RunStep,
254 )
255
256 @typing_extensions.deprecated("The Assistants API is deprecated in favor of the Responses API")
257 def list(
258 self,
259 run_id: str,
260 *,
261 thread_id: str,
262 after: str | Omit = omit,
263 before: str | Omit = omit,
264 include: List[RunStepInclude] | Omit = omit,
265 limit: int | Omit = omit,
266 order: Literal["asc", "desc"] | Omit = omit,
267 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
268 # The extra values given here take precedence over values defined on the client or passed to this method.
269 extra_headers: Headers | None = None,
270 extra_query: Query | None = None,
271 extra_body: Body | None = None,
272 timeout: float | httpx.Timeout | None | NotGiven = not_given,
273 ) -> AsyncPaginator[RunStep, AsyncCursorPage[RunStep]]:
274 """
275 Returns a list of run steps belonging to a run.
276
277 Args:
278 after: A cursor for use in pagination. `after` is an object ID that defines your place
279 in the list. For instance, if you make a list request and receive 100 objects,
280 ending with obj_foo, your subsequent call can include after=obj_foo in order to
281 fetch the next page of the list.
282
283 before: A cursor for use in pagination. `before` is an object ID that defines your place
284 in the list. For instance, if you make a list request and receive 100 objects,
285 starting with obj_foo, your subsequent call can include before=obj_foo in order
286 to fetch the previous page of the list.
287
288 include: A list of additional fields to include in the response. Currently the only
289 supported value is `step_details.tool_calls[*].file_search.results[*].content`
290 to fetch the file search result content.
291
292 See the
293 [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
294 for more information.
295
296 limit: A limit on the number of objects to be returned. Limit can range between 1 and
297 100, and the default is 20.
298
299 order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
300 order and `desc` for descending order.
301
302 extra_headers: Send extra headers
303
304 extra_query: Add additional query parameters to the request
305
306 extra_body: Add additional JSON properties to the request
307
308 timeout: Override the client-level default timeout for this request, in seconds
309 """
310 if not thread_id:
311 raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
312 if not run_id:
313 raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
314 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
315 return self._get_api_list(
316 f"/threads/{thread_id}/runs/{run_id}/steps",
317 page=AsyncCursorPage[RunStep],
318 options=make_request_options(
319 extra_headers=extra_headers,
320 extra_query=extra_query,
321 extra_body=extra_body,
322 timeout=timeout,
323 query=maybe_transform(
324 {
325 "after": after,
326 "before": before,
327 "include": include,
328 "limit": limit,
329 "order": order,
330 },
331 step_list_params.StepListParams,
332 ),
333 ),
334 model=RunStep,
335 )
336
337
338class StepsWithRawResponse:
339 def __init__(self, steps: Steps) -> None:
340 self._steps = steps
341
342 self.retrieve = ( # pyright: ignore[reportDeprecated]
343 _legacy_response.to_raw_response_wrapper(
344 steps.retrieve, # pyright: ignore[reportDeprecated],
345 )
346 )
347 self.list = ( # pyright: ignore[reportDeprecated]
348 _legacy_response.to_raw_response_wrapper(
349 steps.list, # pyright: ignore[reportDeprecated],
350 )
351 )
352
353
354class AsyncStepsWithRawResponse:
355 def __init__(self, steps: AsyncSteps) -> None:
356 self._steps = steps
357
358 self.retrieve = ( # pyright: ignore[reportDeprecated]
359 _legacy_response.async_to_raw_response_wrapper(
360 steps.retrieve, # pyright: ignore[reportDeprecated],
361 )
362 )
363 self.list = ( # pyright: ignore[reportDeprecated]
364 _legacy_response.async_to_raw_response_wrapper(
365 steps.list, # pyright: ignore[reportDeprecated],
366 )
367 )
368
369
370class StepsWithStreamingResponse:
371 def __init__(self, steps: Steps) -> None:
372 self._steps = steps
373
374 self.retrieve = ( # pyright: ignore[reportDeprecated]
375 to_streamed_response_wrapper(
376 steps.retrieve, # pyright: ignore[reportDeprecated],
377 )
378 )
379 self.list = ( # pyright: ignore[reportDeprecated]
380 to_streamed_response_wrapper(
381 steps.list, # pyright: ignore[reportDeprecated],
382 )
383 )
384
385
386class AsyncStepsWithStreamingResponse:
387 def __init__(self, steps: AsyncSteps) -> None:
388 self._steps = steps
389
390 self.retrieve = ( # pyright: ignore[reportDeprecated]
391 async_to_streamed_response_wrapper(
392 steps.retrieve, # pyright: ignore[reportDeprecated],
393 )
394 )
395 self.list = ( # pyright: ignore[reportDeprecated]
396 async_to_streamed_response_wrapper(
397 steps.list, # pyright: ignore[reportDeprecated],
398 )
399 )