Skip to content

Commit

Permalink
feat(api): releases from DevDay; assistants, multimodality, tools, da…
Browse files Browse the repository at this point in the history
…ll-e-3, tts, and more (#682)

* feat(api): releases from DevDay; assistants, multimodality, tools, dall-e-3, tts, and more

* docs(api): improve docstrings

* v1.1.0
  • Loading branch information
RobertCraigie authored Nov 6, 2023
1 parent 26d1a93 commit baa9f07
Show file tree
Hide file tree
Showing 144 changed files with 8,618 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 28
configured_endpoints: 57
140 changes: 139 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,23 @@ Types:
```python
from openai.types.chat import (
ChatCompletion,
ChatCompletionAssistantMessageParam,
ChatCompletionChunk,
ChatCompletionContentPart,
ChatCompletionContentPartImage,
ChatCompletionContentPartText,
ChatCompletionFunctionCallOption,
ChatCompletionFunctionMessageParam,
ChatCompletionMessage,
ChatCompletionMessageParam,
ChatCompletionMessageToolCall,
ChatCompletionNamedToolChoice,
ChatCompletionRole,
ChatCompletionSystemMessageParam,
ChatCompletionTool,
ChatCompletionToolChoiceOption,
ChatCompletionToolMessageParam,
ChatCompletionUserMessageParam,
)
```

Expand Down Expand Up @@ -66,7 +79,7 @@ Methods:

- <code title="post /files">client.files.<a href="./src/openai/resources/files.py">create</a>(\*\*<a href="src/openai/types/file_create_params.py">params</a>) -> <a href="./src/openai/types/file_object.py">FileObject</a></code>
- <code title="get /files/{file_id}">client.files.<a href="./src/openai/resources/files.py">retrieve</a>(file_id) -> <a href="./src/openai/types/file_object.py">FileObject</a></code>
- <code title="get /files">client.files.<a href="./src/openai/resources/files.py">list</a>() -> <a href="./src/openai/types/file_object.py">SyncPage[FileObject]</a></code>
- <code title="get /files">client.files.<a href="./src/openai/resources/files.py">list</a>(\*\*<a href="src/openai/types/file_list_params.py">params</a>) -> <a href="./src/openai/types/file_object.py">SyncPage[FileObject]</a></code>
- <code title="delete /files/{file_id}">client.files.<a href="./src/openai/resources/files.py">delete</a>(file_id) -> <a href="./src/openai/types/file_deleted.py">FileDeleted</a></code>
- <code title="get /files/{file_id}/content">client.files.<a href="./src/openai/resources/files.py">retrieve_content</a>(file_id) -> str</code>
- <code>client.files.<a href="./src/openai/resources/files.py">wait_for_processing</a>(\*args) -> FileObject</code>
Expand Down Expand Up @@ -111,6 +124,12 @@ Methods:

- <code title="post /audio/translations">client.audio.translations.<a href="./src/openai/resources/audio/translations.py">create</a>(\*\*<a href="src/openai/types/audio/translation_create_params.py">params</a>) -> <a href="./src/openai/types/audio/translation.py">Translation</a></code>

## Speech

Methods:

- <code title="post /audio/speech">client.audio.speech.<a href="./src/openai/resources/audio/speech.py">create</a>(\*\*<a href="src/openai/types/audio/speech_create_params.py">params</a>) -> HttpxBinaryResponseContent</code>

# Moderations

Types:
Expand Down Expand Up @@ -170,3 +189,122 @@ Methods:
- <code title="get /fine-tunes">client.fine_tunes.<a href="./src/openai/resources/fine_tunes.py">list</a>() -> <a href="./src/openai/types/fine_tune.py">SyncPage[FineTune]</a></code>
- <code title="post /fine-tunes/{fine_tune_id}/cancel">client.fine_tunes.<a href="./src/openai/resources/fine_tunes.py">cancel</a>(fine_tune_id) -> <a href="./src/openai/types/fine_tune.py">FineTune</a></code>
- <code title="get /fine-tunes/{fine_tune_id}/events">client.fine_tunes.<a href="./src/openai/resources/fine_tunes.py">list_events</a>(fine_tune_id, \*\*<a href="src/openai/types/fine_tune_list_events_params.py">params</a>) -> <a href="./src/openai/types/fine_tune_events_list_response.py">FineTuneEventsListResponse</a></code>

# Beta

## Assistants

Types:

```python
from openai.types.beta import Assistant, AsssitantDeleted
```

Methods:

- <code title="post /assistants">client.beta.assistants.<a href="./src/openai/resources/beta/assistants/assistants.py">create</a>(\*\*<a href="src/openai/types/beta/assistant_create_params.py">params</a>) -> <a href="./src/openai/types/beta/assistant.py">Assistant</a></code>
- <code title="get /assistants/{assistant_id}">client.beta.assistants.<a href="./src/openai/resources/beta/assistants/assistants.py">retrieve</a>(assistant_id) -> <a href="./src/openai/types/beta/assistant.py">Assistant</a></code>
- <code title="post /assistants/{assistant_id}">client.beta.assistants.<a href="./src/openai/resources/beta/assistants/assistants.py">update</a>(assistant_id, \*\*<a href="src/openai/types/beta/assistant_update_params.py">params</a>) -> <a href="./src/openai/types/beta/assistant.py">Assistant</a></code>
- <code title="get /assistants">client.beta.assistants.<a href="./src/openai/resources/beta/assistants/assistants.py">list</a>(\*\*<a href="src/openai/types/beta/assistant_list_params.py">params</a>) -> <a href="./src/openai/types/beta/assistant.py">SyncCursorPage[Assistant]</a></code>
- <code title="delete /assistants/{assistant_id}">client.beta.assistants.<a href="./src/openai/resources/beta/assistants/assistants.py">delete</a>(assistant_id) -> <a href="./src/openai/types/beta/asssitant_deleted.py">AsssitantDeleted</a></code>

### Files

Types:

```python
from openai.types.beta.assistants import AssistantFile, FileDeleteResponse
```

Methods:

- <code title="post /assistants/{assistant_id}/files">client.beta.assistants.files.<a href="./src/openai/resources/beta/assistants/files.py">create</a>(assistant_id, \*\*<a href="src/openai/types/beta/assistants/file_create_params.py">params</a>) -> <a href="./src/openai/types/beta/assistants/assistant_file.py">AssistantFile</a></code>
- <code title="get /assistants/{assistant_id}/files/{file_id}">client.beta.assistants.files.<a href="./src/openai/resources/beta/assistants/files.py">retrieve</a>(file_id, \*, assistant_id) -> <a href="./src/openai/types/beta/assistants/assistant_file.py">AssistantFile</a></code>
- <code title="get /assistants/{assistant_id}/files">client.beta.assistants.files.<a href="./src/openai/resources/beta/assistants/files.py">list</a>(assistant_id, \*\*<a href="src/openai/types/beta/assistants/file_list_params.py">params</a>) -> <a href="./src/openai/types/beta/assistants/assistant_file.py">SyncCursorPage[AssistantFile]</a></code>
- <code title="delete /assistants/{assistant_id}/files/{file_id}">client.beta.assistants.files.<a href="./src/openai/resources/beta/assistants/files.py">delete</a>(file_id, \*, assistant_id) -> <a href="./src/openai/types/beta/assistants/file_delete_response.py">FileDeleteResponse</a></code>

## Threads

Types:

```python
from openai.types.beta import Thread, ThreadDeleted
```

Methods:

- <code title="post /threads">client.beta.threads.<a href="./src/openai/resources/beta/threads/threads.py">create</a>(\*\*<a href="src/openai/types/beta/thread_create_params.py">params</a>) -> <a href="./src/openai/types/beta/thread.py">Thread</a></code>
- <code title="get /threads/{thread_id}">client.beta.threads.<a href="./src/openai/resources/beta/threads/threads.py">retrieve</a>(thread_id) -> <a href="./src/openai/types/beta/thread.py">Thread</a></code>
- <code title="post /threads/{thread_id}">client.beta.threads.<a href="./src/openai/resources/beta/threads/threads.py">update</a>(thread_id, \*\*<a href="src/openai/types/beta/thread_update_params.py">params</a>) -> <a href="./src/openai/types/beta/thread.py">Thread</a></code>
- <code title="delete /threads/{thread_id}">client.beta.threads.<a href="./src/openai/resources/beta/threads/threads.py">delete</a>(thread_id) -> <a href="./src/openai/types/beta/thread_deleted.py">ThreadDeleted</a></code>
- <code title="post /threads/runs">client.beta.threads.<a href="./src/openai/resources/beta/threads/threads.py">create_and_run</a>(\*\*<a href="src/openai/types/beta/thread_create_and_run_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/run.py">Run</a></code>

### Runs

Types:

```python
from openai.types.beta.threads import RequiredActionFunctionToolCall, Run
```

Methods:

- <code title="post /threads/{thread_id}/runs">client.beta.threads.runs.<a href="./src/openai/resources/beta/threads/runs/runs.py">create</a>(thread_id, \*\*<a href="src/openai/types/beta/threads/run_create_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/run.py">Run</a></code>
- <code title="get /threads/{thread_id}/runs/{run_id}">client.beta.threads.runs.<a href="./src/openai/resources/beta/threads/runs/runs.py">retrieve</a>(run_id, \*, thread_id) -> <a href="./src/openai/types/beta/threads/run.py">Run</a></code>
- <code title="post /threads/{thread_id}/runs/{run_id}">client.beta.threads.runs.<a href="./src/openai/resources/beta/threads/runs/runs.py">update</a>(run_id, \*, thread_id, \*\*<a href="src/openai/types/beta/threads/run_update_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/run.py">Run</a></code>
- <code title="get /threads/{thread_id}/runs">client.beta.threads.runs.<a href="./src/openai/resources/beta/threads/runs/runs.py">list</a>(thread_id, \*\*<a href="src/openai/types/beta/threads/run_list_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/run.py">SyncCursorPage[Run]</a></code>
- <code title="post /threads/{thread_id}/runs/{run_id}/cancel">client.beta.threads.runs.<a href="./src/openai/resources/beta/threads/runs/runs.py">cancel</a>(run_id, \*, thread_id) -> <a href="./src/openai/types/beta/threads/run.py">Run</a></code>
- <code title="post /threads/{thread_id}/runs/{run_id}/submit_tool_outputs">client.beta.threads.runs.<a href="./src/openai/resources/beta/threads/runs/runs.py">submit_tool_outputs</a>(run_id, \*, thread_id, \*\*<a href="src/openai/types/beta/threads/run_submit_tool_outputs_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/run.py">Run</a></code>

#### Steps

Types:

```python
from openai.types.beta.threads.runs import (
CodeToolCall,
FunctionToolCall,
MessageCreationStepDetails,
RetrievalToolCall,
RunStep,
ToolCallsStepDetails,
)
```

Methods:

- <code title="get /threads/{thread_id}/runs/{run_id}/steps/{step_id}">client.beta.threads.runs.steps.<a href="./src/openai/resources/beta/threads/runs/steps.py">retrieve</a>(step_id, \*, thread_id, run_id) -> <a href="./src/openai/types/beta/threads/runs/run_step.py">RunStep</a></code>
- <code title="get /threads/{thread_id}/runs/{run_id}/steps">client.beta.threads.runs.steps.<a href="./src/openai/resources/beta/threads/runs/steps.py">list</a>(run_id, \*, thread_id, \*\*<a href="src/openai/types/beta/threads/runs/step_list_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/runs/run_step.py">SyncCursorPage[RunStep]</a></code>

### Messages

Types:

```python
from openai.types.beta.threads import (
MessageContentImageFile,
MessageContentText,
ThreadMessage,
ThreadMessageDeleted,
)
```

Methods:

- <code title="post /threads/{thread_id}/messages">client.beta.threads.messages.<a href="./src/openai/resources/beta/threads/messages/messages.py">create</a>(thread_id, \*\*<a href="src/openai/types/beta/threads/message_create_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/thread_message.py">ThreadMessage</a></code>
- <code title="get /threads/{thread_id}/messages/{message_id}">client.beta.threads.messages.<a href="./src/openai/resources/beta/threads/messages/messages.py">retrieve</a>(message_id, \*, thread_id) -> <a href="./src/openai/types/beta/threads/thread_message.py">ThreadMessage</a></code>
- <code title="post /threads/{thread_id}/messages/{message_id}">client.beta.threads.messages.<a href="./src/openai/resources/beta/threads/messages/messages.py">update</a>(message_id, \*, thread_id, \*\*<a href="src/openai/types/beta/threads/message_update_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/thread_message.py">ThreadMessage</a></code>
- <code title="get /threads/{thread_id}/messages">client.beta.threads.messages.<a href="./src/openai/resources/beta/threads/messages/messages.py">list</a>(thread_id, \*\*<a href="src/openai/types/beta/threads/message_list_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/thread_message.py">SyncCursorPage[ThreadMessage]</a></code>

#### Files

Types:

```python
from openai.types.beta.threads.messages import MessageFile
```

Methods:

- <code title="get /threads/{thread_id}/messages/{message_id}/files/{file_id}">client.beta.threads.messages.files.<a href="./src/openai/resources/beta/threads/messages/files.py">retrieve</a>(file_id, \*, thread_id, message_id) -> <a href="./src/openai/types/beta/threads/messages/message_file.py">MessageFile</a></code>
- <code title="get /threads/{thread_id}/messages/{message_id}/files">client.beta.threads.messages.files.<a href="./src/openai/resources/beta/threads/messages/files.py">list</a>(message_id, \*, thread_id, \*\*<a href="src/openai/types/beta/threads/messages/file_list_params.py">params</a>) -> <a href="./src/openai/types/beta/threads/messages/message_file.py">SyncCursorPage[MessageFile]</a></code>
Empty file modified examples/async_demo.py
100644 → 100755
Empty file.
Empty file modified examples/azure.py
100644 → 100755
Empty file.
Empty file modified examples/azure_ad.py
100644 → 100755
Empty file.
Empty file modified examples/demo.py
100644 → 100755
Empty file.
Empty file modified examples/module_client.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "openai"
version = "1.0.1"
version = "1.1.0"
description = "Client library for the openai API"
readme = "README.md"
license = "Apache-2.0"
Expand Down
1 change: 1 addition & 0 deletions src/openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def _reset_client() -> None: # type: ignore[reportUnusedFunction]
_client = None


from ._module_client import beta as beta
from ._module_client import chat as chat
from ._module_client import audio as audio
from ._module_client import edits as edits
Expand Down
6 changes: 6 additions & 0 deletions src/openai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class OpenAI(SyncAPIClient):
models: resources.Models
fine_tuning: resources.FineTuning
fine_tunes: resources.FineTunes
beta: resources.Beta
with_raw_response: OpenAIWithRawResponse

# client options
Expand Down Expand Up @@ -125,6 +126,7 @@ def __init__(
self.models = resources.Models(self)
self.fine_tuning = resources.FineTuning(self)
self.fine_tunes = resources.FineTunes(self)
self.beta = resources.Beta(self)
self.with_raw_response = OpenAIWithRawResponse(self)

@property
Expand Down Expand Up @@ -257,6 +259,7 @@ class AsyncOpenAI(AsyncAPIClient):
models: resources.AsyncModels
fine_tuning: resources.AsyncFineTuning
fine_tunes: resources.AsyncFineTunes
beta: resources.AsyncBeta
with_raw_response: AsyncOpenAIWithRawResponse

# client options
Expand Down Expand Up @@ -330,6 +333,7 @@ def __init__(
self.models = resources.AsyncModels(self)
self.fine_tuning = resources.AsyncFineTuning(self)
self.fine_tunes = resources.AsyncFineTunes(self)
self.beta = resources.AsyncBeta(self)
self.with_raw_response = AsyncOpenAIWithRawResponse(self)

@property
Expand Down Expand Up @@ -466,6 +470,7 @@ def __init__(self, client: OpenAI) -> None:
self.models = resources.ModelsWithRawResponse(client.models)
self.fine_tuning = resources.FineTuningWithRawResponse(client.fine_tuning)
self.fine_tunes = resources.FineTunesWithRawResponse(client.fine_tunes)
self.beta = resources.BetaWithRawResponse(client.beta)


class AsyncOpenAIWithRawResponse:
Expand All @@ -481,6 +486,7 @@ def __init__(self, client: AsyncOpenAI) -> None:
self.models = resources.AsyncModelsWithRawResponse(client.models)
self.fine_tuning = resources.AsyncFineTuningWithRawResponse(client.fine_tuning)
self.fine_tunes = resources.AsyncFineTunesWithRawResponse(client.fine_tunes)
self.beta = resources.AsyncBetaWithRawResponse(client.beta)


Client = OpenAI
Expand Down
7 changes: 7 additions & 0 deletions src/openai/_module_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def __load__(self) -> resources.Chat:
return _load_client().chat


class BetaProxy(LazyProxy[resources.Beta]):
@override
def __load__(self) -> resources.Beta:
return _load_client().beta


class EditsProxy(LazyProxy[resources.Edits]):
@override
def __load__(self) -> resources.Edits:
Expand Down Expand Up @@ -73,6 +79,7 @@ def __load__(self) -> resources.FineTuning:


chat: resources.Chat = ChatProxy().__as_proxied__()
beta: resources.Beta = BetaProxy().__as_proxied__()
edits: resources.Edits = EditsProxy().__as_proxied__()
files: resources.Files = FilesProxy().__as_proxied__()
audio: resources.Audio = AudioProxy().__as_proxied__()
Expand Down
2 changes: 1 addition & 1 deletion src/openai/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless.

__title__ = "openai"
__version__ = "1.0.1"
__version__ = "1.1.0"
6 changes: 4 additions & 2 deletions src/openai/cli/_api/chat/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from typing import TYPE_CHECKING, List, Optional, cast
from argparse import ArgumentParser
from typing_extensions import NamedTuple
from typing_extensions import Literal, NamedTuple

from ..._utils import get_client
from ..._models import BaseModel
Expand Down Expand Up @@ -97,7 +97,9 @@ class CLIChatCompletion:
def create(args: CLIChatCompletionCreateArgs) -> None:
params: CompletionCreateParams = {
"model": args.model,
"messages": [{"role": message.role, "content": message.content} for message in args.message],
"messages": [
{"role": cast(Literal["user"], message.role), "content": message.content} for message in args.message
],
"n": args.n,
"temperature": args.temperature,
"top_p": args.top_p,
Expand Down
9 changes: 7 additions & 2 deletions src/openai/cli/_api/files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any, cast
from argparse import ArgumentParser

from .._utils import get_client, print_model
Expand Down Expand Up @@ -55,7 +55,12 @@ def create(args: CLIFileCreateArgs) -> None:
with open(args.file, "rb") as file_reader:
buffer_reader = BufferReader(file_reader.read(), desc="Upload progress")

file = get_client().files.create(file=(args.file, buffer_reader), purpose=args.purpose)
file = get_client().files.create(
file=(args.file, buffer_reader),
# casts required because the API is typed for enums
# but we don't want to validate that here for forwards-compat
purpose=cast(Any, args.purpose),
)
print_model(file)

@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions src/openai/pagination.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# File generated from our OpenAPI spec by Stainless.

from typing import Any, List, Generic, TypeVar, Optional, cast
from typing_extensions import Protocol, override, runtime_checkable
from typing_extensions import Literal, Protocol, override, runtime_checkable

from ._types import ModelT
from ._models import BaseModel
Expand All @@ -21,7 +21,7 @@ class SyncPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
"""Note: no pagination actually occurs yet, this is for forwards-compatibility."""

data: List[ModelT]
object: str
object: Literal["list"]

@override
def _get_page_items(self) -> List[ModelT]:
Expand All @@ -40,7 +40,7 @@ class AsyncPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]):
"""Note: no pagination actually occurs yet, this is for forwards-compatibility."""

data: List[ModelT]
object: str
object: Literal["list"]

@override
def _get_page_items(self) -> List[ModelT]:
Expand Down
5 changes: 5 additions & 0 deletions src/openai/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# File generated from our OpenAPI spec by Stainless.

from .beta import Beta, AsyncBeta, BetaWithRawResponse, AsyncBetaWithRawResponse
from .chat import Chat, AsyncChat, ChatWithRawResponse, AsyncChatWithRawResponse
from .audio import Audio, AsyncAudio, AudioWithRawResponse, AsyncAudioWithRawResponse
from .edits import Edits, AsyncEdits, EditsWithRawResponse, AsyncEditsWithRawResponse
Expand Down Expand Up @@ -92,4 +93,8 @@
"AsyncFineTunes",
"FineTunesWithRawResponse",
"AsyncFineTunesWithRawResponse",
"Beta",
"AsyncBeta",
"BetaWithRawResponse",
"AsyncBetaWithRawResponse",
]
10 changes: 10 additions & 0 deletions src/openai/resources/audio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# File generated from our OpenAPI spec by Stainless.

from .audio import Audio, AsyncAudio, AudioWithRawResponse, AsyncAudioWithRawResponse
from .speech import (
Speech,
AsyncSpeech,
SpeechWithRawResponse,
AsyncSpeechWithRawResponse,
)
from .translations import (
Translations,
AsyncTranslations,
Expand All @@ -23,6 +29,10 @@
"AsyncTranslations",
"TranslationsWithRawResponse",
"AsyncTranslationsWithRawResponse",
"Speech",
"AsyncSpeech",
"SpeechWithRawResponse",
"AsyncSpeechWithRawResponse",
"Audio",
"AsyncAudio",
"AudioWithRawResponse",
Expand Down
Loading

0 comments on commit baa9f07

Please sign in to comment.