Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Realtime API support #1958

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 69
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-779ea2754025daf5e18eb8ceb203ec321692636bc3a999338556a479178efa6c.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-0d64ca9e45f51b4279f87b205eeb3a3576df98407698ce053f2e2302c1c08df1.yml
51 changes: 51 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,57 @@ Methods:

## Realtime

Types:

```python
from openai.types.beta.realtime import (
ConversationCreatedEvent,
ConversationItem,
ConversationItemContent,
ConversationItemCreateEvent,
ConversationItemCreatedEvent,
ConversationItemDeleteEvent,
ConversationItemDeletedEvent,
ConversationItemInputAudioTranscriptionCompletedEvent,
ConversationItemInputAudioTranscriptionFailedEvent,
ConversationItemTruncateEvent,
ConversationItemTruncatedEvent,
ErrorEvent,
InputAudioBufferAppendEvent,
InputAudioBufferClearEvent,
InputAudioBufferClearedEvent,
InputAudioBufferCommitEvent,
InputAudioBufferCommittedEvent,
InputAudioBufferSpeechStartedEvent,
InputAudioBufferSpeechStoppedEvent,
RateLimitsUpdatedEvent,
RealtimeClientEvent,
RealtimeResponse,
RealtimeResponseStatus,
RealtimeResponseUsage,
RealtimeServerEvent,
ResponseAudioDeltaEvent,
ResponseAudioDoneEvent,
ResponseAudioTranscriptDeltaEvent,
ResponseAudioTranscriptDoneEvent,
ResponseCancelEvent,
ResponseContentPartAddedEvent,
ResponseContentPartDoneEvent,
ResponseCreateEvent,
ResponseCreatedEvent,
ResponseDoneEvent,
ResponseFunctionCallArgumentsDeltaEvent,
ResponseFunctionCallArgumentsDoneEvent,
ResponseOutputItemAddedEvent,
ResponseOutputItemDoneEvent,
ResponseTextDeltaEvent,
ResponseTextDoneEvent,
SessionCreatedEvent,
SessionUpdateEvent,
SessionUpdatedEvent,
)
```

### Sessions

Types:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ classifiers = [
Homepage = "https://github.com/openai/openai-python"
Repository = "https://github.com/openai/openai-python"


[project.optional-dependencies]
realtime = ["websockets >= 13, < 15"]

[tool.rye]
managed = true
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,7 @@ typing-extensions==4.12.2
# via pyright
virtualenv==20.24.5
# via nox
websockets==14.1
# via openai
zipp==3.17.0
# via importlib-metadata
2 changes: 2 additions & 0 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ typing-extensions==4.12.2
# via openai
# via pydantic
# via pydantic-core
websockets==14.1
# via openai
26 changes: 26 additions & 0 deletions src/openai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,22 @@ class OpenAI(SyncAPIClient):
organization: str | None
project: str | None

websocket_base_url: str | httpx.URL | None
"""Base URL for WebSocket connections.

If not specified, the default base URL will be used, with 'wss://' replacing the
'http://' or 'https://' scheme. For example: 'http://example.com' becomes
'wss://example.com'
"""

def __init__(
self,
*,
api_key: str | None = None,
organization: str | None = None,
project: str | None = None,
base_url: str | httpx.URL | None = None,
websocket_base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
Expand Down Expand Up @@ -111,6 +120,8 @@ def __init__(
project = os.environ.get("OPENAI_PROJECT_ID")
self.project = project

self.websocket_base_url = websocket_base_url

if base_url is None:
base_url = os.environ.get("OPENAI_BASE_URL")
if base_url is None:
Expand Down Expand Up @@ -172,6 +183,7 @@ def copy(
api_key: str | None = None,
organization: str | None = None,
project: str | None = None,
websocket_base_url: str | httpx.URL | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
http_client: httpx.Client | None = None,
Expand Down Expand Up @@ -208,6 +220,7 @@ def copy(
api_key=api_key or self.api_key,
organization=organization or self.organization,
project=project or self.project,
websocket_base_url=websocket_base_url or self.websocket_base_url,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
Expand Down Expand Up @@ -277,13 +290,22 @@ class AsyncOpenAI(AsyncAPIClient):
organization: str | None
project: str | None

websocket_base_url: str | httpx.URL | None
"""Base URL for WebSocket connections.

If not specified, the default base URL will be used, with 'wss://' replacing the
'http://' or 'https://' scheme. For example: 'http://example.com' becomes
'wss://example.com'
"""

def __init__(
self,
*,
api_key: str | None = None,
organization: str | None = None,
project: str | None = None,
base_url: str | httpx.URL | None = None,
websocket_base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
Expand Down Expand Up @@ -325,6 +347,8 @@ def __init__(
project = os.environ.get("OPENAI_PROJECT_ID")
self.project = project

self.websocket_base_url = websocket_base_url

if base_url is None:
base_url = os.environ.get("OPENAI_BASE_URL")
if base_url is None:
Expand Down Expand Up @@ -386,6 +410,7 @@ def copy(
api_key: str | None = None,
organization: str | None = None,
project: str | None = None,
websocket_base_url: str | httpx.URL | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
http_client: httpx.AsyncClient | None = None,
Expand Down Expand Up @@ -422,6 +447,7 @@ def copy(
api_key=api_key or self.api_key,
organization=organization or self.organization,
project=project or self.project,
websocket_base_url=websocket_base_url or self.websocket_base_url,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
Expand Down
Loading