main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5from typing import Any, List, cast
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
13from ..._compat import cached_property
14from ..._resource import SyncAPIResource, AsyncAPIResource
15from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
16from ...pagination import SyncCursorPage, AsyncCursorPage
17from ..._base_client import AsyncPaginator, make_request_options
18from ...types.responses import input_item_list_params
19from ...types.responses.response_item import ResponseItem
20from ...types.responses.response_includable import ResponseIncludable
21
22__all__ = ["InputItems", "AsyncInputItems"]
23
24
25class InputItems(SyncAPIResource):
26 @cached_property
27 def with_raw_response(self) -> InputItemsWithRawResponse:
28 """
29 This property can be used as a prefix for any HTTP method call to return
30 the raw response object instead of the parsed content.
31
32 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
33 """
34 return InputItemsWithRawResponse(self)
35
36 @cached_property
37 def with_streaming_response(self) -> InputItemsWithStreamingResponse:
38 """
39 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
40
41 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
42 """
43 return InputItemsWithStreamingResponse(self)
44
45 def list(
46 self,
47 response_id: str,
48 *,
49 after: str | Omit = omit,
50 include: List[ResponseIncludable] | Omit = omit,
51 limit: int | Omit = omit,
52 order: Literal["asc", "desc"] | Omit = omit,
53 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
54 # The extra values given here take precedence over values defined on the client or passed to this method.
55 extra_headers: Headers | None = None,
56 extra_query: Query | None = None,
57 extra_body: Body | None = None,
58 timeout: float | httpx.Timeout | None | NotGiven = not_given,
59 ) -> SyncCursorPage[ResponseItem]:
60 """
61 Returns a list of input items for a given response.
62
63 Args:
64 after: An item ID to list items after, used in pagination.
65
66 include: Additional fields to include in the response. See the `include` parameter for
67 Response creation above for more information.
68
69 limit: A limit on the number of objects to be returned. Limit can range between 1 and
70 100, and the default is 20.
71
72 order: The order to return the input items in. Default is `desc`.
73
74 - `asc`: Return the input items in ascending order.
75 - `desc`: Return the input items in descending order.
76
77 extra_headers: Send extra headers
78
79 extra_query: Add additional query parameters to the request
80
81 extra_body: Add additional JSON properties to the request
82
83 timeout: Override the client-level default timeout for this request, in seconds
84 """
85 if not response_id:
86 raise ValueError(f"Expected a non-empty value for `response_id` but received {response_id!r}")
87 return self._get_api_list(
88 f"/responses/{response_id}/input_items",
89 page=SyncCursorPage[ResponseItem],
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(
96 {
97 "after": after,
98 "include": include,
99 "limit": limit,
100 "order": order,
101 },
102 input_item_list_params.InputItemListParams,
103 ),
104 ),
105 model=cast(Any, ResponseItem), # Union types cannot be passed in as arguments in the type system
106 )
107
108
109class AsyncInputItems(AsyncAPIResource):
110 @cached_property
111 def with_raw_response(self) -> AsyncInputItemsWithRawResponse:
112 """
113 This property can be used as a prefix for any HTTP method call to return
114 the raw response object instead of the parsed content.
115
116 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
117 """
118 return AsyncInputItemsWithRawResponse(self)
119
120 @cached_property
121 def with_streaming_response(self) -> AsyncInputItemsWithStreamingResponse:
122 """
123 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
124
125 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
126 """
127 return AsyncInputItemsWithStreamingResponse(self)
128
129 def list(
130 self,
131 response_id: str,
132 *,
133 after: str | Omit = omit,
134 include: List[ResponseIncludable] | Omit = omit,
135 limit: int | Omit = omit,
136 order: Literal["asc", "desc"] | Omit = omit,
137 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
138 # The extra values given here take precedence over values defined on the client or passed to this method.
139 extra_headers: Headers | None = None,
140 extra_query: Query | None = None,
141 extra_body: Body | None = None,
142 timeout: float | httpx.Timeout | None | NotGiven = not_given,
143 ) -> AsyncPaginator[ResponseItem, AsyncCursorPage[ResponseItem]]:
144 """
145 Returns a list of input items for a given response.
146
147 Args:
148 after: An item ID to list items after, used in pagination.
149
150 include: Additional fields to include in the response. See the `include` parameter for
151 Response creation above for more information.
152
153 limit: A limit on the number of objects to be returned. Limit can range between 1 and
154 100, and the default is 20.
155
156 order: The order to return the input items in. Default is `desc`.
157
158 - `asc`: Return the input items in ascending order.
159 - `desc`: Return the input items in descending order.
160
161 extra_headers: Send extra headers
162
163 extra_query: Add additional query parameters to the request
164
165 extra_body: Add additional JSON properties to the request
166
167 timeout: Override the client-level default timeout for this request, in seconds
168 """
169 if not response_id:
170 raise ValueError(f"Expected a non-empty value for `response_id` but received {response_id!r}")
171 return self._get_api_list(
172 f"/responses/{response_id}/input_items",
173 page=AsyncCursorPage[ResponseItem],
174 options=make_request_options(
175 extra_headers=extra_headers,
176 extra_query=extra_query,
177 extra_body=extra_body,
178 timeout=timeout,
179 query=maybe_transform(
180 {
181 "after": after,
182 "include": include,
183 "limit": limit,
184 "order": order,
185 },
186 input_item_list_params.InputItemListParams,
187 ),
188 ),
189 model=cast(Any, ResponseItem), # Union types cannot be passed in as arguments in the type system
190 )
191
192
193class InputItemsWithRawResponse:
194 def __init__(self, input_items: InputItems) -> None:
195 self._input_items = input_items
196
197 self.list = _legacy_response.to_raw_response_wrapper(
198 input_items.list,
199 )
200
201
202class AsyncInputItemsWithRawResponse:
203 def __init__(self, input_items: AsyncInputItems) -> None:
204 self._input_items = input_items
205
206 self.list = _legacy_response.async_to_raw_response_wrapper(
207 input_items.list,
208 )
209
210
211class InputItemsWithStreamingResponse:
212 def __init__(self, input_items: InputItems) -> None:
213 self._input_items = input_items
214
215 self.list = to_streamed_response_wrapper(
216 input_items.list,
217 )
218
219
220class AsyncInputItemsWithStreamingResponse:
221 def __init__(self, input_items: AsyncInputItems) -> None:
222 self._input_items = input_items
223
224 self.list = async_to_streamed_response_wrapper(
225 input_items.list,
226 )