feat: initial project setup with psagentia agent implementation
Add core Python agent with configuration management, environment setup, and deployment documentation. Includes user/agent profiles, startup scripts, and dependency management for the psagentia system.
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
# File generated from our OpenAPI spec by Stainless.
|
||||
|
||||
from .runs import (
|
||||
Runs,
|
||||
AsyncRuns,
|
||||
RunsWithRawResponse,
|
||||
AsyncRunsWithRawResponse,
|
||||
RunsWithStreamingResponse,
|
||||
AsyncRunsWithStreamingResponse,
|
||||
)
|
||||
from .threads import (
|
||||
Threads,
|
||||
AsyncThreads,
|
||||
ThreadsWithRawResponse,
|
||||
AsyncThreadsWithRawResponse,
|
||||
ThreadsWithStreamingResponse,
|
||||
AsyncThreadsWithStreamingResponse,
|
||||
)
|
||||
from .messages import (
|
||||
Messages,
|
||||
AsyncMessages,
|
||||
MessagesWithRawResponse,
|
||||
AsyncMessagesWithRawResponse,
|
||||
MessagesWithStreamingResponse,
|
||||
AsyncMessagesWithStreamingResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Runs",
|
||||
"AsyncRuns",
|
||||
"RunsWithRawResponse",
|
||||
"AsyncRunsWithRawResponse",
|
||||
"RunsWithStreamingResponse",
|
||||
"AsyncRunsWithStreamingResponse",
|
||||
"Messages",
|
||||
"AsyncMessages",
|
||||
"MessagesWithRawResponse",
|
||||
"AsyncMessagesWithRawResponse",
|
||||
"MessagesWithStreamingResponse",
|
||||
"AsyncMessagesWithStreamingResponse",
|
||||
"Threads",
|
||||
"AsyncThreads",
|
||||
"ThreadsWithRawResponse",
|
||||
"AsyncThreadsWithRawResponse",
|
||||
"ThreadsWithStreamingResponse",
|
||||
"AsyncThreadsWithStreamingResponse",
|
||||
]
|
||||
venv/lib/python3.11/site-packages/openai/resources/beta/threads/__pycache__/__init__.cpython-311.pyc
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
+33
@@ -0,0 +1,33 @@
|
||||
# File generated from our OpenAPI spec by Stainless.
|
||||
|
||||
from .files import (
|
||||
Files,
|
||||
AsyncFiles,
|
||||
FilesWithRawResponse,
|
||||
AsyncFilesWithRawResponse,
|
||||
FilesWithStreamingResponse,
|
||||
AsyncFilesWithStreamingResponse,
|
||||
)
|
||||
from .messages import (
|
||||
Messages,
|
||||
AsyncMessages,
|
||||
MessagesWithRawResponse,
|
||||
AsyncMessagesWithRawResponse,
|
||||
MessagesWithStreamingResponse,
|
||||
AsyncMessagesWithStreamingResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Files",
|
||||
"AsyncFiles",
|
||||
"FilesWithRawResponse",
|
||||
"AsyncFilesWithRawResponse",
|
||||
"FilesWithStreamingResponse",
|
||||
"AsyncFilesWithStreamingResponse",
|
||||
"Messages",
|
||||
"AsyncMessages",
|
||||
"MessagesWithRawResponse",
|
||||
"AsyncMessagesWithRawResponse",
|
||||
"MessagesWithStreamingResponse",
|
||||
"AsyncMessagesWithStreamingResponse",
|
||||
]
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+312
@@ -0,0 +1,312 @@
|
||||
# File generated from our OpenAPI spec by Stainless.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing_extensions import Literal
|
||||
|
||||
import httpx
|
||||
|
||||
from ..... import _legacy_response
|
||||
from ....._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
||||
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.beta.threads.messages import MessageFile, file_list_params
|
||||
|
||||
__all__ = ["Files", "AsyncFiles"]
|
||||
|
||||
|
||||
class Files(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> FilesWithRawResponse:
|
||||
return FilesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> FilesWithStreamingResponse:
|
||||
return FilesWithStreamingResponse(self)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
message_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,
|
||||
) -> MessageFile:
|
||||
"""
|
||||
Retrieves a message file.
|
||||
|
||||
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}")
|
||||
if not message_id:
|
||||
raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}")
|
||||
if not file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/threads/{thread_id}/messages/{message_id}/files/{file_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=MessageFile,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
message_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
before: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
|
||||
# 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[MessageFile]:
|
||||
"""Returns a list of message files.
|
||||
|
||||
Args:
|
||||
after: A cursor for use in pagination.
|
||||
|
||||
`after` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
||||
fetch the next page of the list.
|
||||
|
||||
before: A cursor for use in pagination. `before` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include before=obj_foo in order to
|
||||
fetch the previous page of the list.
|
||||
|
||||
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
||||
100, and the default is 20.
|
||||
|
||||
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
||||
order and `desc` for 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 thread_id:
|
||||
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
|
||||
if not message_id:
|
||||
raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/threads/{thread_id}/messages/{message_id}/files",
|
||||
page=SyncCursorPage[MessageFile],
|
||||
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,
|
||||
},
|
||||
file_list_params.FileListParams,
|
||||
),
|
||||
),
|
||||
model=MessageFile,
|
||||
)
|
||||
|
||||
|
||||
class AsyncFiles(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncFilesWithRawResponse:
|
||||
return AsyncFilesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncFilesWithStreamingResponse:
|
||||
return AsyncFilesWithStreamingResponse(self)
|
||||
|
||||
async def retrieve(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
message_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,
|
||||
) -> MessageFile:
|
||||
"""
|
||||
Retrieves a message file.
|
||||
|
||||
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}")
|
||||
if not message_id:
|
||||
raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}")
|
||||
if not file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
f"/threads/{thread_id}/messages/{message_id}/files/{file_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=MessageFile,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
message_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
before: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
|
||||
# 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[MessageFile, AsyncCursorPage[MessageFile]]:
|
||||
"""Returns a list of message files.
|
||||
|
||||
Args:
|
||||
after: A cursor for use in pagination.
|
||||
|
||||
`after` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
||||
fetch the next page of the list.
|
||||
|
||||
before: A cursor for use in pagination. `before` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include before=obj_foo in order to
|
||||
fetch the previous page of the list.
|
||||
|
||||
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
||||
100, and the default is 20.
|
||||
|
||||
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
||||
order and `desc` for 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 thread_id:
|
||||
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
|
||||
if not message_id:
|
||||
raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/threads/{thread_id}/messages/{message_id}/files",
|
||||
page=AsyncCursorPage[MessageFile],
|
||||
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,
|
||||
},
|
||||
file_list_params.FileListParams,
|
||||
),
|
||||
),
|
||||
model=MessageFile,
|
||||
)
|
||||
|
||||
|
||||
class FilesWithRawResponse:
|
||||
def __init__(self, files: Files) -> None:
|
||||
self._files = files
|
||||
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
files.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
files.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncFilesWithRawResponse:
|
||||
def __init__(self, files: AsyncFiles) -> None:
|
||||
self._files = files
|
||||
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
files.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.async_to_raw_response_wrapper(
|
||||
files.list,
|
||||
)
|
||||
|
||||
|
||||
class FilesWithStreamingResponse:
|
||||
def __init__(self, files: Files) -> None:
|
||||
self._files = files
|
||||
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
files.retrieve,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
files.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncFilesWithStreamingResponse:
|
||||
def __init__(self, files: AsyncFiles) -> None:
|
||||
self._files = files
|
||||
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
files.retrieve,
|
||||
)
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
files.list,
|
||||
)
|
||||
+567
@@ -0,0 +1,567 @@
|
||||
# File generated from our OpenAPI spec by Stainless.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List, Optional
|
||||
from typing_extensions import Literal
|
||||
|
||||
import httpx
|
||||
|
||||
from ..... import _legacy_response
|
||||
from .files import (
|
||||
Files,
|
||||
AsyncFiles,
|
||||
FilesWithRawResponse,
|
||||
AsyncFilesWithRawResponse,
|
||||
FilesWithStreamingResponse,
|
||||
AsyncFilesWithStreamingResponse,
|
||||
)
|
||||
from ....._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
||||
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.beta.threads import ThreadMessage, message_list_params, message_create_params, message_update_params
|
||||
|
||||
__all__ = ["Messages", "AsyncMessages"]
|
||||
|
||||
|
||||
class Messages(SyncAPIResource):
|
||||
@cached_property
|
||||
def files(self) -> Files:
|
||||
return Files(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> MessagesWithRawResponse:
|
||||
return MessagesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> MessagesWithStreamingResponse:
|
||||
return MessagesWithStreamingResponse(self)
|
||||
|
||||
def create(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
content: str,
|
||||
role: Literal["user"],
|
||||
file_ids: List[str] | NotGiven = NOT_GIVEN,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> ThreadMessage:
|
||||
"""
|
||||
Create a message.
|
||||
|
||||
Args:
|
||||
content: The content of the message.
|
||||
|
||||
role: The role of the entity that is creating the message. Currently only `user` is
|
||||
supported.
|
||||
|
||||
file_ids: A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
|
||||
the message should use. There can be a maximum of 10 files attached to a
|
||||
message. Useful for tools like `retrieval` and `code_interpreter` that can
|
||||
access and use files.
|
||||
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return self._post(
|
||||
f"/threads/{thread_id}/messages",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"content": content,
|
||||
"role": role,
|
||||
"file_ids": file_ids,
|
||||
"metadata": metadata,
|
||||
},
|
||||
message_create_params.MessageCreateParams,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ThreadMessage,
|
||||
)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
message_id: str,
|
||||
*,
|
||||
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,
|
||||
) -> ThreadMessage:
|
||||
"""
|
||||
Retrieve a message.
|
||||
|
||||
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}")
|
||||
if not message_id:
|
||||
raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/threads/{thread_id}/messages/{message_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ThreadMessage,
|
||||
)
|
||||
|
||||
def update(
|
||||
self,
|
||||
message_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> ThreadMessage:
|
||||
"""
|
||||
Modifies a message.
|
||||
|
||||
Args:
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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}")
|
||||
if not message_id:
|
||||
raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._post(
|
||||
f"/threads/{thread_id}/messages/{message_id}",
|
||||
body=maybe_transform({"metadata": metadata}, message_update_params.MessageUpdateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ThreadMessage,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
before: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
|
||||
# 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[ThreadMessage]:
|
||||
"""
|
||||
Returns a list of messages for a given thread.
|
||||
|
||||
Args:
|
||||
after: A cursor for use in pagination. `after` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
||||
fetch the next page of the list.
|
||||
|
||||
before: A cursor for use in pagination. `before` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include before=obj_foo in order to
|
||||
fetch the previous page of the list.
|
||||
|
||||
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
||||
100, and the default is 20.
|
||||
|
||||
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
||||
order and `desc` for 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 thread_id:
|
||||
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/threads/{thread_id}/messages",
|
||||
page=SyncCursorPage[ThreadMessage],
|
||||
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,
|
||||
},
|
||||
message_list_params.MessageListParams,
|
||||
),
|
||||
),
|
||||
model=ThreadMessage,
|
||||
)
|
||||
|
||||
|
||||
class AsyncMessages(AsyncAPIResource):
|
||||
@cached_property
|
||||
def files(self) -> AsyncFiles:
|
||||
return AsyncFiles(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncMessagesWithRawResponse:
|
||||
return AsyncMessagesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncMessagesWithStreamingResponse:
|
||||
return AsyncMessagesWithStreamingResponse(self)
|
||||
|
||||
async def create(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
content: str,
|
||||
role: Literal["user"],
|
||||
file_ids: List[str] | NotGiven = NOT_GIVEN,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> ThreadMessage:
|
||||
"""
|
||||
Create a message.
|
||||
|
||||
Args:
|
||||
content: The content of the message.
|
||||
|
||||
role: The role of the entity that is creating the message. Currently only `user` is
|
||||
supported.
|
||||
|
||||
file_ids: A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
|
||||
the message should use. There can be a maximum of 10 files attached to a
|
||||
message. Useful for tools like `retrieval` and `code_interpreter` that can
|
||||
access and use files.
|
||||
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._post(
|
||||
f"/threads/{thread_id}/messages",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"content": content,
|
||||
"role": role,
|
||||
"file_ids": file_ids,
|
||||
"metadata": metadata,
|
||||
},
|
||||
message_create_params.MessageCreateParams,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ThreadMessage,
|
||||
)
|
||||
|
||||
async def retrieve(
|
||||
self,
|
||||
message_id: str,
|
||||
*,
|
||||
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,
|
||||
) -> ThreadMessage:
|
||||
"""
|
||||
Retrieve a message.
|
||||
|
||||
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}")
|
||||
if not message_id:
|
||||
raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
f"/threads/{thread_id}/messages/{message_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ThreadMessage,
|
||||
)
|
||||
|
||||
async def update(
|
||||
self,
|
||||
message_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> ThreadMessage:
|
||||
"""
|
||||
Modifies a message.
|
||||
|
||||
Args:
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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}")
|
||||
if not message_id:
|
||||
raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._post(
|
||||
f"/threads/{thread_id}/messages/{message_id}",
|
||||
body=maybe_transform({"metadata": metadata}, message_update_params.MessageUpdateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ThreadMessage,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
before: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
|
||||
# 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[ThreadMessage, AsyncCursorPage[ThreadMessage]]:
|
||||
"""
|
||||
Returns a list of messages for a given thread.
|
||||
|
||||
Args:
|
||||
after: A cursor for use in pagination. `after` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
||||
fetch the next page of the list.
|
||||
|
||||
before: A cursor for use in pagination. `before` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include before=obj_foo in order to
|
||||
fetch the previous page of the list.
|
||||
|
||||
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
||||
100, and the default is 20.
|
||||
|
||||
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
||||
order and `desc` for 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 thread_id:
|
||||
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/threads/{thread_id}/messages",
|
||||
page=AsyncCursorPage[ThreadMessage],
|
||||
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,
|
||||
},
|
||||
message_list_params.MessageListParams,
|
||||
),
|
||||
),
|
||||
model=ThreadMessage,
|
||||
)
|
||||
|
||||
|
||||
class MessagesWithRawResponse:
|
||||
def __init__(self, messages: Messages) -> None:
|
||||
self._messages = messages
|
||||
|
||||
self.create = _legacy_response.to_raw_response_wrapper(
|
||||
messages.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
messages.retrieve,
|
||||
)
|
||||
self.update = _legacy_response.to_raw_response_wrapper(
|
||||
messages.update,
|
||||
)
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
messages.list,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> FilesWithRawResponse:
|
||||
return FilesWithRawResponse(self._messages.files)
|
||||
|
||||
|
||||
class AsyncMessagesWithRawResponse:
|
||||
def __init__(self, messages: AsyncMessages) -> None:
|
||||
self._messages = messages
|
||||
|
||||
self.create = _legacy_response.async_to_raw_response_wrapper(
|
||||
messages.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
messages.retrieve,
|
||||
)
|
||||
self.update = _legacy_response.async_to_raw_response_wrapper(
|
||||
messages.update,
|
||||
)
|
||||
self.list = _legacy_response.async_to_raw_response_wrapper(
|
||||
messages.list,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> AsyncFilesWithRawResponse:
|
||||
return AsyncFilesWithRawResponse(self._messages.files)
|
||||
|
||||
|
||||
class MessagesWithStreamingResponse:
|
||||
def __init__(self, messages: Messages) -> None:
|
||||
self._messages = messages
|
||||
|
||||
self.create = to_streamed_response_wrapper(
|
||||
messages.create,
|
||||
)
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
messages.retrieve,
|
||||
)
|
||||
self.update = to_streamed_response_wrapper(
|
||||
messages.update,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
messages.list,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> FilesWithStreamingResponse:
|
||||
return FilesWithStreamingResponse(self._messages.files)
|
||||
|
||||
|
||||
class AsyncMessagesWithStreamingResponse:
|
||||
def __init__(self, messages: AsyncMessages) -> None:
|
||||
self._messages = messages
|
||||
|
||||
self.create = async_to_streamed_response_wrapper(
|
||||
messages.create,
|
||||
)
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
messages.retrieve,
|
||||
)
|
||||
self.update = async_to_streamed_response_wrapper(
|
||||
messages.update,
|
||||
)
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
messages.list,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> AsyncFilesWithStreamingResponse:
|
||||
return AsyncFilesWithStreamingResponse(self._messages.files)
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
# File generated from our OpenAPI spec by Stainless.
|
||||
|
||||
from .runs import (
|
||||
Runs,
|
||||
AsyncRuns,
|
||||
RunsWithRawResponse,
|
||||
AsyncRunsWithRawResponse,
|
||||
RunsWithStreamingResponse,
|
||||
AsyncRunsWithStreamingResponse,
|
||||
)
|
||||
from .steps import (
|
||||
Steps,
|
||||
AsyncSteps,
|
||||
StepsWithRawResponse,
|
||||
AsyncStepsWithRawResponse,
|
||||
StepsWithStreamingResponse,
|
||||
AsyncStepsWithStreamingResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Steps",
|
||||
"AsyncSteps",
|
||||
"StepsWithRawResponse",
|
||||
"AsyncStepsWithRawResponse",
|
||||
"StepsWithStreamingResponse",
|
||||
"AsyncStepsWithStreamingResponse",
|
||||
"Runs",
|
||||
"AsyncRuns",
|
||||
"RunsWithRawResponse",
|
||||
"AsyncRunsWithRawResponse",
|
||||
"RunsWithStreamingResponse",
|
||||
"AsyncRunsWithStreamingResponse",
|
||||
]
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+791
@@ -0,0 +1,791 @@
|
||||
# File generated from our OpenAPI spec by Stainless.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable, Optional
|
||||
from typing_extensions import Literal
|
||||
|
||||
import httpx
|
||||
|
||||
from ..... import _legacy_response
|
||||
from .steps import (
|
||||
Steps,
|
||||
AsyncSteps,
|
||||
StepsWithRawResponse,
|
||||
AsyncStepsWithRawResponse,
|
||||
StepsWithStreamingResponse,
|
||||
AsyncStepsWithStreamingResponse,
|
||||
)
|
||||
from ....._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
||||
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.beta.threads import (
|
||||
Run,
|
||||
run_list_params,
|
||||
run_create_params,
|
||||
run_update_params,
|
||||
run_submit_tool_outputs_params,
|
||||
)
|
||||
|
||||
__all__ = ["Runs", "AsyncRuns"]
|
||||
|
||||
|
||||
class Runs(SyncAPIResource):
|
||||
@cached_property
|
||||
def steps(self) -> Steps:
|
||||
return Steps(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> RunsWithRawResponse:
|
||||
return RunsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> RunsWithStreamingResponse:
|
||||
return RunsWithStreamingResponse(self)
|
||||
|
||||
def create(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
assistant_id: str,
|
||||
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
instructions: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
model: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
tools: Optional[Iterable[run_create_params.Tool]] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Run:
|
||||
"""
|
||||
Create a run.
|
||||
|
||||
Args:
|
||||
assistant_id: The ID of the
|
||||
[assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
|
||||
execute this run.
|
||||
|
||||
additional_instructions: Appends additional instructions at the end of the instructions for the run. This
|
||||
is useful for modifying the behavior on a per-run basis without overriding other
|
||||
instructions.
|
||||
|
||||
instructions: Overrides the
|
||||
[instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
|
||||
of the assistant. This is useful for modifying the behavior on a per-run basis.
|
||||
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
model: The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
|
||||
be used to execute this run. If a value is provided here, it will override the
|
||||
model associated with the assistant. If not, the model associated with the
|
||||
assistant will be used.
|
||||
|
||||
tools: Override the tools the assistant can use for this run. This is useful for
|
||||
modifying the behavior on a per-run basis.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return self._post(
|
||||
f"/threads/{thread_id}/runs",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"assistant_id": assistant_id,
|
||||
"additional_instructions": additional_instructions,
|
||||
"instructions": instructions,
|
||||
"metadata": metadata,
|
||||
"model": model,
|
||||
"tools": tools,
|
||||
},
|
||||
run_create_params.RunCreateParams,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
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,
|
||||
) -> Run:
|
||||
"""
|
||||
Retrieves a run.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/threads/{thread_id}/runs/{run_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
def update(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Run:
|
||||
"""
|
||||
Modifies a run.
|
||||
|
||||
Args:
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._post(
|
||||
f"/threads/{thread_id}/runs/{run_id}",
|
||||
body=maybe_transform({"metadata": metadata}, run_update_params.RunUpdateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
before: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
|
||||
# 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[Run]:
|
||||
"""
|
||||
Returns a list of runs belonging to a thread.
|
||||
|
||||
Args:
|
||||
after: A cursor for use in pagination. `after` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
||||
fetch the next page of the list.
|
||||
|
||||
before: A cursor for use in pagination. `before` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include before=obj_foo in order to
|
||||
fetch the previous page of the list.
|
||||
|
||||
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
||||
100, and the default is 20.
|
||||
|
||||
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
||||
order and `desc` for 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 thread_id:
|
||||
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/threads/{thread_id}/runs",
|
||||
page=SyncCursorPage[Run],
|
||||
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,
|
||||
},
|
||||
run_list_params.RunListParams,
|
||||
),
|
||||
),
|
||||
model=Run,
|
||||
)
|
||||
|
||||
def cancel(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
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,
|
||||
) -> Run:
|
||||
"""
|
||||
Cancels a run that is `in_progress`.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._post(
|
||||
f"/threads/{thread_id}/runs/{run_id}/cancel",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
def submit_tool_outputs(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
tool_outputs: Iterable[run_submit_tool_outputs_params.ToolOutput],
|
||||
# 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,
|
||||
) -> Run:
|
||||
"""
|
||||
When a run has the `status: "requires_action"` and `required_action.type` is
|
||||
`submit_tool_outputs`, this endpoint can be used to submit the outputs from the
|
||||
tool calls once they're all completed. All outputs must be submitted in a single
|
||||
request.
|
||||
|
||||
Args:
|
||||
tool_outputs: A list of tools for which the outputs are being submitted.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._post(
|
||||
f"/threads/{thread_id}/runs/{run_id}/submit_tool_outputs",
|
||||
body=maybe_transform(
|
||||
{"tool_outputs": tool_outputs}, run_submit_tool_outputs_params.RunSubmitToolOutputsParams
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
|
||||
class AsyncRuns(AsyncAPIResource):
|
||||
@cached_property
|
||||
def steps(self) -> AsyncSteps:
|
||||
return AsyncSteps(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncRunsWithRawResponse:
|
||||
return AsyncRunsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncRunsWithStreamingResponse:
|
||||
return AsyncRunsWithStreamingResponse(self)
|
||||
|
||||
async def create(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
assistant_id: str,
|
||||
additional_instructions: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
instructions: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
model: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
tools: Optional[Iterable[run_create_params.Tool]] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Run:
|
||||
"""
|
||||
Create a run.
|
||||
|
||||
Args:
|
||||
assistant_id: The ID of the
|
||||
[assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
|
||||
execute this run.
|
||||
|
||||
additional_instructions: Appends additional instructions at the end of the instructions for the run. This
|
||||
is useful for modifying the behavior on a per-run basis without overriding other
|
||||
instructions.
|
||||
|
||||
instructions: Overrides the
|
||||
[instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
|
||||
of the assistant. This is useful for modifying the behavior on a per-run basis.
|
||||
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
model: The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
|
||||
be used to execute this run. If a value is provided here, it will override the
|
||||
model associated with the assistant. If not, the model associated with the
|
||||
assistant will be used.
|
||||
|
||||
tools: Override the tools the assistant can use for this run. This is useful for
|
||||
modifying the behavior on a per-run basis.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._post(
|
||||
f"/threads/{thread_id}/runs",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"assistant_id": assistant_id,
|
||||
"additional_instructions": additional_instructions,
|
||||
"instructions": instructions,
|
||||
"metadata": metadata,
|
||||
"model": model,
|
||||
"tools": tools,
|
||||
},
|
||||
run_create_params.RunCreateParams,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
async def retrieve(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
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,
|
||||
) -> Run:
|
||||
"""
|
||||
Retrieves a run.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
f"/threads/{thread_id}/runs/{run_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
async def update(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Run:
|
||||
"""
|
||||
Modifies a run.
|
||||
|
||||
Args:
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._post(
|
||||
f"/threads/{thread_id}/runs/{run_id}",
|
||||
body=maybe_transform({"metadata": metadata}, run_update_params.RunUpdateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
before: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
|
||||
# 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[Run, AsyncCursorPage[Run]]:
|
||||
"""
|
||||
Returns a list of runs belonging to a thread.
|
||||
|
||||
Args:
|
||||
after: A cursor for use in pagination. `after` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
||||
fetch the next page of the list.
|
||||
|
||||
before: A cursor for use in pagination. `before` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include before=obj_foo in order to
|
||||
fetch the previous page of the list.
|
||||
|
||||
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
||||
100, and the default is 20.
|
||||
|
||||
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
||||
order and `desc` for 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 thread_id:
|
||||
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/threads/{thread_id}/runs",
|
||||
page=AsyncCursorPage[Run],
|
||||
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,
|
||||
},
|
||||
run_list_params.RunListParams,
|
||||
),
|
||||
),
|
||||
model=Run,
|
||||
)
|
||||
|
||||
async def cancel(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
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,
|
||||
) -> Run:
|
||||
"""
|
||||
Cancels a run that is `in_progress`.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._post(
|
||||
f"/threads/{thread_id}/runs/{run_id}/cancel",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
async def submit_tool_outputs(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
tool_outputs: Iterable[run_submit_tool_outputs_params.ToolOutput],
|
||||
# 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,
|
||||
) -> Run:
|
||||
"""
|
||||
When a run has the `status: "requires_action"` and `required_action.type` is
|
||||
`submit_tool_outputs`, this endpoint can be used to submit the outputs from the
|
||||
tool calls once they're all completed. All outputs must be submitted in a single
|
||||
request.
|
||||
|
||||
Args:
|
||||
tool_outputs: A list of tools for which the outputs are being submitted.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._post(
|
||||
f"/threads/{thread_id}/runs/{run_id}/submit_tool_outputs",
|
||||
body=maybe_transform(
|
||||
{"tool_outputs": tool_outputs}, run_submit_tool_outputs_params.RunSubmitToolOutputsParams
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
|
||||
class RunsWithRawResponse:
|
||||
def __init__(self, runs: Runs) -> None:
|
||||
self._runs = runs
|
||||
|
||||
self.create = _legacy_response.to_raw_response_wrapper(
|
||||
runs.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
runs.retrieve,
|
||||
)
|
||||
self.update = _legacy_response.to_raw_response_wrapper(
|
||||
runs.update,
|
||||
)
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
runs.list,
|
||||
)
|
||||
self.cancel = _legacy_response.to_raw_response_wrapper(
|
||||
runs.cancel,
|
||||
)
|
||||
self.submit_tool_outputs = _legacy_response.to_raw_response_wrapper(
|
||||
runs.submit_tool_outputs,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def steps(self) -> StepsWithRawResponse:
|
||||
return StepsWithRawResponse(self._runs.steps)
|
||||
|
||||
|
||||
class AsyncRunsWithRawResponse:
|
||||
def __init__(self, runs: AsyncRuns) -> None:
|
||||
self._runs = runs
|
||||
|
||||
self.create = _legacy_response.async_to_raw_response_wrapper(
|
||||
runs.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
runs.retrieve,
|
||||
)
|
||||
self.update = _legacy_response.async_to_raw_response_wrapper(
|
||||
runs.update,
|
||||
)
|
||||
self.list = _legacy_response.async_to_raw_response_wrapper(
|
||||
runs.list,
|
||||
)
|
||||
self.cancel = _legacy_response.async_to_raw_response_wrapper(
|
||||
runs.cancel,
|
||||
)
|
||||
self.submit_tool_outputs = _legacy_response.async_to_raw_response_wrapper(
|
||||
runs.submit_tool_outputs,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def steps(self) -> AsyncStepsWithRawResponse:
|
||||
return AsyncStepsWithRawResponse(self._runs.steps)
|
||||
|
||||
|
||||
class RunsWithStreamingResponse:
|
||||
def __init__(self, runs: Runs) -> None:
|
||||
self._runs = runs
|
||||
|
||||
self.create = to_streamed_response_wrapper(
|
||||
runs.create,
|
||||
)
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
runs.retrieve,
|
||||
)
|
||||
self.update = to_streamed_response_wrapper(
|
||||
runs.update,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
runs.list,
|
||||
)
|
||||
self.cancel = to_streamed_response_wrapper(
|
||||
runs.cancel,
|
||||
)
|
||||
self.submit_tool_outputs = to_streamed_response_wrapper(
|
||||
runs.submit_tool_outputs,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def steps(self) -> StepsWithStreamingResponse:
|
||||
return StepsWithStreamingResponse(self._runs.steps)
|
||||
|
||||
|
||||
class AsyncRunsWithStreamingResponse:
|
||||
def __init__(self, runs: AsyncRuns) -> None:
|
||||
self._runs = runs
|
||||
|
||||
self.create = async_to_streamed_response_wrapper(
|
||||
runs.create,
|
||||
)
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
runs.retrieve,
|
||||
)
|
||||
self.update = async_to_streamed_response_wrapper(
|
||||
runs.update,
|
||||
)
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
runs.list,
|
||||
)
|
||||
self.cancel = async_to_streamed_response_wrapper(
|
||||
runs.cancel,
|
||||
)
|
||||
self.submit_tool_outputs = async_to_streamed_response_wrapper(
|
||||
runs.submit_tool_outputs,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def steps(self) -> AsyncStepsWithStreamingResponse:
|
||||
return AsyncStepsWithStreamingResponse(self._runs.steps)
|
||||
+310
@@ -0,0 +1,310 @@
|
||||
# File generated from our OpenAPI spec by Stainless.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing_extensions import Literal
|
||||
|
||||
import httpx
|
||||
|
||||
from ..... import _legacy_response
|
||||
from ....._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
||||
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.beta.threads.runs import RunStep, step_list_params
|
||||
|
||||
__all__ = ["Steps", "AsyncSteps"]
|
||||
|
||||
|
||||
class Steps(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> StepsWithRawResponse:
|
||||
return StepsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> StepsWithStreamingResponse:
|
||||
return StepsWithStreamingResponse(self)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
step_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
run_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,
|
||||
) -> RunStep:
|
||||
"""
|
||||
Retrieves a run step.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
if not step_id:
|
||||
raise ValueError(f"Expected a non-empty value for `step_id` but received {step_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/threads/{thread_id}/runs/{run_id}/steps/{step_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=RunStep,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
before: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
|
||||
# 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[RunStep]:
|
||||
"""
|
||||
Returns a list of run steps belonging to a run.
|
||||
|
||||
Args:
|
||||
after: A cursor for use in pagination. `after` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
||||
fetch the next page of the list.
|
||||
|
||||
before: A cursor for use in pagination. `before` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include before=obj_foo in order to
|
||||
fetch the previous page of the list.
|
||||
|
||||
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
||||
100, and the default is 20.
|
||||
|
||||
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
||||
order and `desc` for 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 thread_id:
|
||||
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/threads/{thread_id}/runs/{run_id}/steps",
|
||||
page=SyncCursorPage[RunStep],
|
||||
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,
|
||||
},
|
||||
step_list_params.StepListParams,
|
||||
),
|
||||
),
|
||||
model=RunStep,
|
||||
)
|
||||
|
||||
|
||||
class AsyncSteps(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncStepsWithRawResponse:
|
||||
return AsyncStepsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncStepsWithStreamingResponse:
|
||||
return AsyncStepsWithStreamingResponse(self)
|
||||
|
||||
async def retrieve(
|
||||
self,
|
||||
step_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
run_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,
|
||||
) -> RunStep:
|
||||
"""
|
||||
Retrieves a run step.
|
||||
|
||||
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}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
if not step_id:
|
||||
raise ValueError(f"Expected a non-empty value for `step_id` but received {step_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
f"/threads/{thread_id}/runs/{run_id}/steps/{step_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=RunStep,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
run_id: str,
|
||||
*,
|
||||
thread_id: str,
|
||||
after: str | NotGiven = NOT_GIVEN,
|
||||
before: str | NotGiven = NOT_GIVEN,
|
||||
limit: int | NotGiven = NOT_GIVEN,
|
||||
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
|
||||
# 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[RunStep, AsyncCursorPage[RunStep]]:
|
||||
"""
|
||||
Returns a list of run steps belonging to a run.
|
||||
|
||||
Args:
|
||||
after: A cursor for use in pagination. `after` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
||||
fetch the next page of the list.
|
||||
|
||||
before: A cursor for use in pagination. `before` is an object ID that defines your place
|
||||
in the list. For instance, if you make a list request and receive 100 objects,
|
||||
ending with obj_foo, your subsequent call can include before=obj_foo in order to
|
||||
fetch the previous page of the list.
|
||||
|
||||
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
||||
100, and the default is 20.
|
||||
|
||||
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
||||
order and `desc` for 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 thread_id:
|
||||
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
|
||||
if not run_id:
|
||||
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
|
||||
extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/threads/{thread_id}/runs/{run_id}/steps",
|
||||
page=AsyncCursorPage[RunStep],
|
||||
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,
|
||||
},
|
||||
step_list_params.StepListParams,
|
||||
),
|
||||
),
|
||||
model=RunStep,
|
||||
)
|
||||
|
||||
|
||||
class StepsWithRawResponse:
|
||||
def __init__(self, steps: Steps) -> None:
|
||||
self._steps = steps
|
||||
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
steps.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
steps.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncStepsWithRawResponse:
|
||||
def __init__(self, steps: AsyncSteps) -> None:
|
||||
self._steps = steps
|
||||
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
steps.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.async_to_raw_response_wrapper(
|
||||
steps.list,
|
||||
)
|
||||
|
||||
|
||||
class StepsWithStreamingResponse:
|
||||
def __init__(self, steps: Steps) -> None:
|
||||
self._steps = steps
|
||||
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
steps.retrieve,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
steps.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncStepsWithStreamingResponse:
|
||||
def __init__(self, steps: AsyncSteps) -> None:
|
||||
self._steps = steps
|
||||
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
steps.retrieve,
|
||||
)
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
steps.list,
|
||||
)
|
||||
+651
@@ -0,0 +1,651 @@
|
||||
# File generated from our OpenAPI spec by Stainless.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable, Optional
|
||||
|
||||
import httpx
|
||||
|
||||
from .... import _legacy_response
|
||||
from .runs import (
|
||||
Runs,
|
||||
AsyncRuns,
|
||||
RunsWithRawResponse,
|
||||
AsyncRunsWithRawResponse,
|
||||
RunsWithStreamingResponse,
|
||||
AsyncRunsWithStreamingResponse,
|
||||
)
|
||||
from .messages import (
|
||||
Messages,
|
||||
AsyncMessages,
|
||||
MessagesWithRawResponse,
|
||||
AsyncMessagesWithRawResponse,
|
||||
MessagesWithStreamingResponse,
|
||||
AsyncMessagesWithStreamingResponse,
|
||||
)
|
||||
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
||||
from ...._utils import maybe_transform
|
||||
from .runs.runs import Runs, AsyncRuns
|
||||
from ...._compat import cached_property
|
||||
from ...._resource import SyncAPIResource, AsyncAPIResource
|
||||
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
||||
from ....types.beta import (
|
||||
Thread,
|
||||
ThreadDeleted,
|
||||
thread_create_params,
|
||||
thread_update_params,
|
||||
thread_create_and_run_params,
|
||||
)
|
||||
from ...._base_client import (
|
||||
make_request_options,
|
||||
)
|
||||
from .messages.messages import Messages, AsyncMessages
|
||||
from ....types.beta.threads import Run
|
||||
|
||||
__all__ = ["Threads", "AsyncThreads"]
|
||||
|
||||
|
||||
class Threads(SyncAPIResource):
|
||||
@cached_property
|
||||
def runs(self) -> Runs:
|
||||
return Runs(self._client)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> Messages:
|
||||
return Messages(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> ThreadsWithRawResponse:
|
||||
return ThreadsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> ThreadsWithStreamingResponse:
|
||||
return ThreadsWithStreamingResponse(self)
|
||||
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
messages: Iterable[thread_create_params.Message] | NotGiven = NOT_GIVEN,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Thread:
|
||||
"""
|
||||
Create a thread.
|
||||
|
||||
Args:
|
||||
messages: A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
|
||||
start the thread with.
|
||||
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return self._post(
|
||||
"/threads",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"messages": messages,
|
||||
"metadata": metadata,
|
||||
},
|
||||
thread_create_params.ThreadCreateParams,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Thread,
|
||||
)
|
||||
|
||||
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,
|
||||
) -> Thread:
|
||||
"""
|
||||
Retrieves a 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": "assistants=v1", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/threads/{thread_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Thread,
|
||||
)
|
||||
|
||||
def update(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Thread:
|
||||
"""
|
||||
Modifies a thread.
|
||||
|
||||
Args:
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return self._post(
|
||||
f"/threads/{thread_id}",
|
||||
body=maybe_transform({"metadata": metadata}, thread_update_params.ThreadUpdateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Thread,
|
||||
)
|
||||
|
||||
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,
|
||||
) -> ThreadDeleted:
|
||||
"""
|
||||
Delete a 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": "assistants=v1", **(extra_headers or {})}
|
||||
return self._delete(
|
||||
f"/threads/{thread_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ThreadDeleted,
|
||||
)
|
||||
|
||||
def create_and_run(
|
||||
self,
|
||||
*,
|
||||
assistant_id: str,
|
||||
instructions: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
model: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
thread: thread_create_and_run_params.Thread | NotGiven = NOT_GIVEN,
|
||||
tools: Optional[Iterable[thread_create_and_run_params.Tool]] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Run:
|
||||
"""
|
||||
Create a thread and run it in one request.
|
||||
|
||||
Args:
|
||||
assistant_id: The ID of the
|
||||
[assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
|
||||
execute this run.
|
||||
|
||||
instructions: Override the default system message of the assistant. This is useful for
|
||||
modifying the behavior on a per-run basis.
|
||||
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
model: The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
|
||||
be used to execute this run. If a value is provided here, it will override the
|
||||
model associated with the assistant. If not, the model associated with the
|
||||
assistant will be used.
|
||||
|
||||
thread: If no thread is provided, an empty thread will be created.
|
||||
|
||||
tools: Override the tools the assistant can use for this run. This is useful for
|
||||
modifying the behavior on a per-run basis.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return self._post(
|
||||
"/threads/runs",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"assistant_id": assistant_id,
|
||||
"instructions": instructions,
|
||||
"metadata": metadata,
|
||||
"model": model,
|
||||
"thread": thread,
|
||||
"tools": tools,
|
||||
},
|
||||
thread_create_and_run_params.ThreadCreateAndRunParams,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
|
||||
class AsyncThreads(AsyncAPIResource):
|
||||
@cached_property
|
||||
def runs(self) -> AsyncRuns:
|
||||
return AsyncRuns(self._client)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> AsyncMessages:
|
||||
return AsyncMessages(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncThreadsWithRawResponse:
|
||||
return AsyncThreadsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncThreadsWithStreamingResponse:
|
||||
return AsyncThreadsWithStreamingResponse(self)
|
||||
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
messages: Iterable[thread_create_params.Message] | NotGiven = NOT_GIVEN,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Thread:
|
||||
"""
|
||||
Create a thread.
|
||||
|
||||
Args:
|
||||
messages: A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
|
||||
start the thread with.
|
||||
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._post(
|
||||
"/threads",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"messages": messages,
|
||||
"metadata": metadata,
|
||||
},
|
||||
thread_create_params.ThreadCreateParams,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Thread,
|
||||
)
|
||||
|
||||
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,
|
||||
) -> Thread:
|
||||
"""
|
||||
Retrieves a 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": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
f"/threads/{thread_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Thread,
|
||||
)
|
||||
|
||||
async def update(
|
||||
self,
|
||||
thread_id: str,
|
||||
*,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Thread:
|
||||
"""
|
||||
Modifies a thread.
|
||||
|
||||
Args:
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._post(
|
||||
f"/threads/{thread_id}",
|
||||
body=maybe_transform({"metadata": metadata}, thread_update_params.ThreadUpdateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Thread,
|
||||
)
|
||||
|
||||
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,
|
||||
) -> ThreadDeleted:
|
||||
"""
|
||||
Delete a 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": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._delete(
|
||||
f"/threads/{thread_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ThreadDeleted,
|
||||
)
|
||||
|
||||
async def create_and_run(
|
||||
self,
|
||||
*,
|
||||
assistant_id: str,
|
||||
instructions: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
metadata: Optional[object] | NotGiven = NOT_GIVEN,
|
||||
model: Optional[str] | NotGiven = NOT_GIVEN,
|
||||
thread: thread_create_and_run_params.Thread | NotGiven = NOT_GIVEN,
|
||||
tools: Optional[Iterable[thread_create_and_run_params.Tool]] | NotGiven = NOT_GIVEN,
|
||||
# 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,
|
||||
) -> Run:
|
||||
"""
|
||||
Create a thread and run it in one request.
|
||||
|
||||
Args:
|
||||
assistant_id: The ID of the
|
||||
[assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
|
||||
execute this run.
|
||||
|
||||
instructions: Override the default system message of the assistant. This is useful for
|
||||
modifying the behavior on a per-run basis.
|
||||
|
||||
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
|
||||
for storing additional information about the object in a structured format. Keys
|
||||
can be a maximum of 64 characters long and values can be a maxium of 512
|
||||
characters long.
|
||||
|
||||
model: The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
|
||||
be used to execute this run. If a value is provided here, it will override the
|
||||
model associated with the assistant. If not, the model associated with the
|
||||
assistant will be used.
|
||||
|
||||
thread: If no thread is provided, an empty thread will be created.
|
||||
|
||||
tools: Override the tools the assistant can use for this run. This is useful for
|
||||
modifying the behavior on a per-run basis.
|
||||
|
||||
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": "assistants=v1", **(extra_headers or {})}
|
||||
return await self._post(
|
||||
"/threads/runs",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"assistant_id": assistant_id,
|
||||
"instructions": instructions,
|
||||
"metadata": metadata,
|
||||
"model": model,
|
||||
"thread": thread,
|
||||
"tools": tools,
|
||||
},
|
||||
thread_create_and_run_params.ThreadCreateAndRunParams,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Run,
|
||||
)
|
||||
|
||||
|
||||
class ThreadsWithRawResponse:
|
||||
def __init__(self, threads: Threads) -> None:
|
||||
self._threads = threads
|
||||
|
||||
self.create = _legacy_response.to_raw_response_wrapper(
|
||||
threads.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
threads.retrieve,
|
||||
)
|
||||
self.update = _legacy_response.to_raw_response_wrapper(
|
||||
threads.update,
|
||||
)
|
||||
self.delete = _legacy_response.to_raw_response_wrapper(
|
||||
threads.delete,
|
||||
)
|
||||
self.create_and_run = _legacy_response.to_raw_response_wrapper(
|
||||
threads.create_and_run,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def runs(self) -> RunsWithRawResponse:
|
||||
return RunsWithRawResponse(self._threads.runs)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> MessagesWithRawResponse:
|
||||
return MessagesWithRawResponse(self._threads.messages)
|
||||
|
||||
|
||||
class AsyncThreadsWithRawResponse:
|
||||
def __init__(self, threads: AsyncThreads) -> None:
|
||||
self._threads = threads
|
||||
|
||||
self.create = _legacy_response.async_to_raw_response_wrapper(
|
||||
threads.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
threads.retrieve,
|
||||
)
|
||||
self.update = _legacy_response.async_to_raw_response_wrapper(
|
||||
threads.update,
|
||||
)
|
||||
self.delete = _legacy_response.async_to_raw_response_wrapper(
|
||||
threads.delete,
|
||||
)
|
||||
self.create_and_run = _legacy_response.async_to_raw_response_wrapper(
|
||||
threads.create_and_run,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def runs(self) -> AsyncRunsWithRawResponse:
|
||||
return AsyncRunsWithRawResponse(self._threads.runs)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> AsyncMessagesWithRawResponse:
|
||||
return AsyncMessagesWithRawResponse(self._threads.messages)
|
||||
|
||||
|
||||
class ThreadsWithStreamingResponse:
|
||||
def __init__(self, threads: Threads) -> None:
|
||||
self._threads = threads
|
||||
|
||||
self.create = to_streamed_response_wrapper(
|
||||
threads.create,
|
||||
)
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
threads.retrieve,
|
||||
)
|
||||
self.update = to_streamed_response_wrapper(
|
||||
threads.update,
|
||||
)
|
||||
self.delete = to_streamed_response_wrapper(
|
||||
threads.delete,
|
||||
)
|
||||
self.create_and_run = to_streamed_response_wrapper(
|
||||
threads.create_and_run,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def runs(self) -> RunsWithStreamingResponse:
|
||||
return RunsWithStreamingResponse(self._threads.runs)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> MessagesWithStreamingResponse:
|
||||
return MessagesWithStreamingResponse(self._threads.messages)
|
||||
|
||||
|
||||
class AsyncThreadsWithStreamingResponse:
|
||||
def __init__(self, threads: AsyncThreads) -> None:
|
||||
self._threads = threads
|
||||
|
||||
self.create = async_to_streamed_response_wrapper(
|
||||
threads.create,
|
||||
)
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
threads.retrieve,
|
||||
)
|
||||
self.update = async_to_streamed_response_wrapper(
|
||||
threads.update,
|
||||
)
|
||||
self.delete = async_to_streamed_response_wrapper(
|
||||
threads.delete,
|
||||
)
|
||||
self.create_and_run = async_to_streamed_response_wrapper(
|
||||
threads.create_and_run,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def runs(self) -> AsyncRunsWithStreamingResponse:
|
||||
return AsyncRunsWithStreamingResponse(self._threads.runs)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> AsyncMessagesWithStreamingResponse:
|
||||
return AsyncMessagesWithStreamingResponse(self._threads.messages)
|
||||
Reference in New Issue
Block a user