input_items.py 8.6 KB

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