| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
- from __future__ import annotations
- from typing import Any, List, cast
- from typing_extensions import Literal
- import httpx
- from ... import _legacy_response
- from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
- from ..._utils import maybe_transform
- from ..._compat import cached_property
- from ..._resource import SyncAPIResource, AsyncAPIResource
- from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
- from ...pagination import SyncCursorPage, AsyncCursorPage
- from ..._base_client import AsyncPaginator, make_request_options
- from ...types.responses import input_item_list_params
- from ...types.responses.response_item import ResponseItem
- from ...types.responses.response_includable import ResponseIncludable
- __all__ = ["InputItems", "AsyncInputItems"]
- class InputItems(SyncAPIResource):
- @cached_property
- def with_raw_response(self) -> InputItemsWithRawResponse:
- """
- This property can be used as a prefix for any HTTP method call to return
- the raw response object instead of the parsed content.
- For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
- """
- return InputItemsWithRawResponse(self)
- @cached_property
- def with_streaming_response(self) -> InputItemsWithStreamingResponse:
- """
- An alternative to `.with_raw_response` that doesn't eagerly read the response body.
- For more information, see https://www.github.com/openai/openai-python#with_streaming_response
- """
- return InputItemsWithStreamingResponse(self)
- def list(
- self,
- response_id: str,
- *,
- after: str | Omit = omit,
- include: List[ResponseIncludable] | Omit = omit,
- limit: int | Omit = omit,
- order: Literal["asc", "desc"] | Omit = omit,
- # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
- # The extra values given here take precedence over values defined on the client or passed to this method.
- extra_headers: Headers | None = None,
- extra_query: Query | None = None,
- extra_body: Body | None = None,
- timeout: float | httpx.Timeout | None | NotGiven = not_given,
- ) -> SyncCursorPage[ResponseItem]:
- """
- Returns a list of input items for a given response.
- Args:
- after: An item ID to list items after, used in pagination.
- include: Additional fields to include in the response. See the `include` parameter for
- Response creation above for more information.
- limit: A limit on the number of objects to be returned. Limit can range between 1 and
- 100, and the default is 20.
- order: The order to return the input items in. Default is `desc`.
- - `asc`: Return the input items in ascending order.
- - `desc`: Return the input items in descending order.
- extra_headers: Send extra headers
- extra_query: Add additional query parameters to the request
- extra_body: Add additional JSON properties to the request
- timeout: Override the client-level default timeout for this request, in seconds
- """
- if not response_id:
- raise ValueError(f"Expected a non-empty value for `response_id` but received {response_id!r}")
- return self._get_api_list(
- f"/responses/{response_id}/input_items",
- page=SyncCursorPage[ResponseItem],
- options=make_request_options(
- extra_headers=extra_headers,
- extra_query=extra_query,
- extra_body=extra_body,
- timeout=timeout,
- query=maybe_transform(
- {
- "after": after,
- "include": include,
- "limit": limit,
- "order": order,
- },
- input_item_list_params.InputItemListParams,
- ),
- ),
- model=cast(Any, ResponseItem), # Union types cannot be passed in as arguments in the type system
- )
- class AsyncInputItems(AsyncAPIResource):
- @cached_property
- def with_raw_response(self) -> AsyncInputItemsWithRawResponse:
- """
- This property can be used as a prefix for any HTTP method call to return
- the raw response object instead of the parsed content.
- For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
- """
- return AsyncInputItemsWithRawResponse(self)
- @cached_property
- def with_streaming_response(self) -> AsyncInputItemsWithStreamingResponse:
- """
- An alternative to `.with_raw_response` that doesn't eagerly read the response body.
- For more information, see https://www.github.com/openai/openai-python#with_streaming_response
- """
- return AsyncInputItemsWithStreamingResponse(self)
- def list(
- self,
- response_id: str,
- *,
- after: str | Omit = omit,
- include: List[ResponseIncludable] | Omit = omit,
- limit: int | Omit = omit,
- order: Literal["asc", "desc"] | Omit = omit,
- # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
- # The extra values given here take precedence over values defined on the client or passed to this method.
- extra_headers: Headers | None = None,
- extra_query: Query | None = None,
- extra_body: Body | None = None,
- timeout: float | httpx.Timeout | None | NotGiven = not_given,
- ) -> AsyncPaginator[ResponseItem, AsyncCursorPage[ResponseItem]]:
- """
- Returns a list of input items for a given response.
- Args:
- after: An item ID to list items after, used in pagination.
- include: Additional fields to include in the response. See the `include` parameter for
- Response creation above for more information.
- limit: A limit on the number of objects to be returned. Limit can range between 1 and
- 100, and the default is 20.
- order: The order to return the input items in. Default is `desc`.
- - `asc`: Return the input items in ascending order.
- - `desc`: Return the input items in descending order.
- extra_headers: Send extra headers
- extra_query: Add additional query parameters to the request
- extra_body: Add additional JSON properties to the request
- timeout: Override the client-level default timeout for this request, in seconds
- """
- if not response_id:
- raise ValueError(f"Expected a non-empty value for `response_id` but received {response_id!r}")
- return self._get_api_list(
- f"/responses/{response_id}/input_items",
- page=AsyncCursorPage[ResponseItem],
- options=make_request_options(
- extra_headers=extra_headers,
- extra_query=extra_query,
- extra_body=extra_body,
- timeout=timeout,
- query=maybe_transform(
- {
- "after": after,
- "include": include,
- "limit": limit,
- "order": order,
- },
- input_item_list_params.InputItemListParams,
- ),
- ),
- model=cast(Any, ResponseItem), # Union types cannot be passed in as arguments in the type system
- )
- class InputItemsWithRawResponse:
- def __init__(self, input_items: InputItems) -> None:
- self._input_items = input_items
- self.list = _legacy_response.to_raw_response_wrapper(
- input_items.list,
- )
- class AsyncInputItemsWithRawResponse:
- def __init__(self, input_items: AsyncInputItems) -> None:
- self._input_items = input_items
- self.list = _legacy_response.async_to_raw_response_wrapper(
- input_items.list,
- )
- class InputItemsWithStreamingResponse:
- def __init__(self, input_items: InputItems) -> None:
- self._input_items = input_items
- self.list = to_streamed_response_wrapper(
- input_items.list,
- )
- class AsyncInputItemsWithStreamingResponse:
- def __init__(self, input_items: AsyncInputItems) -> None:
- self._input_items = input_items
- self.list = async_to_streamed_response_wrapper(
- input_items.list,
- )
|