| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
- from __future__ import annotations
- from typing import Any, 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 SyncConversationCursorPage, AsyncConversationCursorPage
- from ...._base_client import AsyncPaginator, make_request_options
- from ....types.beta.chatkit import thread_list_params, thread_list_items_params
- from ....types.beta.chatkit.chatkit_thread import ChatKitThread
- from ....types.beta.chatkit.thread_delete_response import ThreadDeleteResponse
- from ....types.beta.chatkit.chatkit_thread_item_list import Data
- __all__ = ["Threads", "AsyncThreads"]
- class Threads(SyncAPIResource):
- @cached_property
- def with_raw_response(self) -> ThreadsWithRawResponse:
- """
- 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 ThreadsWithRawResponse(self)
- @cached_property
- def with_streaming_response(self) -> ThreadsWithStreamingResponse:
- """
- 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 ThreadsWithStreamingResponse(self)
- def retrieve(
- self,
- thread_id: str,
- *,
- # 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,
- ) -> ChatKitThread:
- """
- Retrieve a ChatKit thread
- Args:
- 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 thread_id:
- raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
- extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
- return self._get(
- f"/chatkit/threads/{thread_id}",
- options=make_request_options(
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
- ),
- cast_to=ChatKitThread,
- )
- def list(
- self,
- *,
- after: str | Omit = omit,
- before: str | Omit = omit,
- limit: int | Omit = omit,
- order: Literal["asc", "desc"] | Omit = omit,
- user: str | 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,
- ) -> SyncConversationCursorPage[ChatKitThread]:
- """
- List ChatKit threads
- Args:
- after: List items created after this thread item ID. Defaults to null for the first
- page.
- before: List items created before this thread item ID. Defaults to null for the newest
- results.
- limit: Maximum number of thread items to return. Defaults to 20.
- order: Sort order for results by creation time. Defaults to `desc`.
- user: Filter threads that belong to this user identifier. Defaults to null to return
- all users.
- 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
- """
- extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
- return self._get_api_list(
- "/chatkit/threads",
- page=SyncConversationCursorPage[ChatKitThread],
- options=make_request_options(
- extra_headers=extra_headers,
- extra_query=extra_query,
- extra_body=extra_body,
- timeout=timeout,
- query=maybe_transform(
- {
- "after": after,
- "before": before,
- "limit": limit,
- "order": order,
- "user": user,
- },
- thread_list_params.ThreadListParams,
- ),
- ),
- model=ChatKitThread,
- )
- def delete(
- self,
- thread_id: str,
- *,
- # 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,
- ) -> ThreadDeleteResponse:
- """
- Delete a ChatKit thread
- Args:
- 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 thread_id:
- raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
- extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
- return self._delete(
- f"/chatkit/threads/{thread_id}",
- options=make_request_options(
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
- ),
- cast_to=ThreadDeleteResponse,
- )
- def list_items(
- self,
- thread_id: str,
- *,
- after: str | Omit = omit,
- before: str | 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,
- ) -> SyncConversationCursorPage[Data]:
- """
- List ChatKit thread items
- Args:
- after: List items created after this thread item ID. Defaults to null for the first
- page.
- before: List items created before this thread item ID. Defaults to null for the newest
- results.
- limit: Maximum number of thread items to return. Defaults to 20.
- order: Sort order for results by creation time. Defaults to `desc`.
- 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 thread_id:
- raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
- extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
- return self._get_api_list(
- f"/chatkit/threads/{thread_id}/items",
- page=SyncConversationCursorPage[Data],
- options=make_request_options(
- extra_headers=extra_headers,
- extra_query=extra_query,
- extra_body=extra_body,
- timeout=timeout,
- query=maybe_transform(
- {
- "after": after,
- "before": before,
- "limit": limit,
- "order": order,
- },
- thread_list_items_params.ThreadListItemsParams,
- ),
- ),
- model=cast(Any, Data), # Union types cannot be passed in as arguments in the type system
- )
- class AsyncThreads(AsyncAPIResource):
- @cached_property
- def with_raw_response(self) -> AsyncThreadsWithRawResponse:
- """
- 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 AsyncThreadsWithRawResponse(self)
- @cached_property
- def with_streaming_response(self) -> AsyncThreadsWithStreamingResponse:
- """
- 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 AsyncThreadsWithStreamingResponse(self)
- async def retrieve(
- self,
- thread_id: str,
- *,
- # 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,
- ) -> ChatKitThread:
- """
- Retrieve a ChatKit thread
- Args:
- 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 thread_id:
- raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
- extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
- return await self._get(
- f"/chatkit/threads/{thread_id}",
- options=make_request_options(
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
- ),
- cast_to=ChatKitThread,
- )
- def list(
- self,
- *,
- after: str | Omit = omit,
- before: str | Omit = omit,
- limit: int | Omit = omit,
- order: Literal["asc", "desc"] | Omit = omit,
- user: str | 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[ChatKitThread, AsyncConversationCursorPage[ChatKitThread]]:
- """
- List ChatKit threads
- Args:
- after: List items created after this thread item ID. Defaults to null for the first
- page.
- before: List items created before this thread item ID. Defaults to null for the newest
- results.
- limit: Maximum number of thread items to return. Defaults to 20.
- order: Sort order for results by creation time. Defaults to `desc`.
- user: Filter threads that belong to this user identifier. Defaults to null to return
- all users.
- 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
- """
- extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
- return self._get_api_list(
- "/chatkit/threads",
- page=AsyncConversationCursorPage[ChatKitThread],
- options=make_request_options(
- extra_headers=extra_headers,
- extra_query=extra_query,
- extra_body=extra_body,
- timeout=timeout,
- query=maybe_transform(
- {
- "after": after,
- "before": before,
- "limit": limit,
- "order": order,
- "user": user,
- },
- thread_list_params.ThreadListParams,
- ),
- ),
- model=ChatKitThread,
- )
- async def delete(
- self,
- thread_id: str,
- *,
- # 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,
- ) -> ThreadDeleteResponse:
- """
- Delete a ChatKit thread
- Args:
- 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 thread_id:
- raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
- extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
- return await self._delete(
- f"/chatkit/threads/{thread_id}",
- options=make_request_options(
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
- ),
- cast_to=ThreadDeleteResponse,
- )
- def list_items(
- self,
- thread_id: str,
- *,
- after: str | Omit = omit,
- before: str | 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[Data, AsyncConversationCursorPage[Data]]:
- """
- List ChatKit thread items
- Args:
- after: List items created after this thread item ID. Defaults to null for the first
- page.
- before: List items created before this thread item ID. Defaults to null for the newest
- results.
- limit: Maximum number of thread items to return. Defaults to 20.
- order: Sort order for results by creation time. Defaults to `desc`.
- 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 thread_id:
- raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
- extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
- return self._get_api_list(
- f"/chatkit/threads/{thread_id}/items",
- page=AsyncConversationCursorPage[Data],
- options=make_request_options(
- extra_headers=extra_headers,
- extra_query=extra_query,
- extra_body=extra_body,
- timeout=timeout,
- query=maybe_transform(
- {
- "after": after,
- "before": before,
- "limit": limit,
- "order": order,
- },
- thread_list_items_params.ThreadListItemsParams,
- ),
- ),
- model=cast(Any, Data), # Union types cannot be passed in as arguments in the type system
- )
- class ThreadsWithRawResponse:
- def __init__(self, threads: Threads) -> None:
- self._threads = threads
- self.retrieve = _legacy_response.to_raw_response_wrapper(
- threads.retrieve,
- )
- self.list = _legacy_response.to_raw_response_wrapper(
- threads.list,
- )
- self.delete = _legacy_response.to_raw_response_wrapper(
- threads.delete,
- )
- self.list_items = _legacy_response.to_raw_response_wrapper(
- threads.list_items,
- )
- class AsyncThreadsWithRawResponse:
- def __init__(self, threads: AsyncThreads) -> None:
- self._threads = threads
- self.retrieve = _legacy_response.async_to_raw_response_wrapper(
- threads.retrieve,
- )
- self.list = _legacy_response.async_to_raw_response_wrapper(
- threads.list,
- )
- self.delete = _legacy_response.async_to_raw_response_wrapper(
- threads.delete,
- )
- self.list_items = _legacy_response.async_to_raw_response_wrapper(
- threads.list_items,
- )
- class ThreadsWithStreamingResponse:
- def __init__(self, threads: Threads) -> None:
- self._threads = threads
- self.retrieve = to_streamed_response_wrapper(
- threads.retrieve,
- )
- self.list = to_streamed_response_wrapper(
- threads.list,
- )
- self.delete = to_streamed_response_wrapper(
- threads.delete,
- )
- self.list_items = to_streamed_response_wrapper(
- threads.list_items,
- )
- class AsyncThreadsWithStreamingResponse:
- def __init__(self, threads: AsyncThreads) -> None:
- self._threads = threads
- self.retrieve = async_to_streamed_response_wrapper(
- threads.retrieve,
- )
- self.list = async_to_streamed_response_wrapper(
- threads.list,
- )
- self.delete = async_to_streamed_response_wrapper(
- threads.delete,
- )
- self.list_items = async_to_streamed_response_wrapper(
- threads.list_items,
- )
|