Skip to content

Commit 7092be6

Browse files
committed
feat: main realtime added
1 parent 37acf8b commit 7092be6

5 files changed

Lines changed: 71 additions & 0 deletions

File tree

portkey_ai/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
AsyncProviders,
136136
Webhooks,
137137
AsyncWebhooks,
138+
MainRealtime,
139+
AsyncMainRealtime,
138140
)
139141

140142
from portkey_ai.version import VERSION
@@ -289,4 +291,6 @@
289291
"AsyncProviders",
290292
"Webhooks",
291293
"AsyncWebhooks",
294+
"MainRealtime",
295+
"AsyncMainRealtime",
292296
]

portkey_ai/api_resources/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
AsyncProviders,
124124
Webhooks,
125125
AsyncWebhooks,
126+
MainRealtime,
127+
AsyncMainRealtime,
126128
)
127129
from .utils import (
128130
Modes,
@@ -281,4 +283,6 @@
281283
"AsyncProviders",
282284
"Webhooks",
283285
"AsyncWebhooks",
286+
"MainRealtime",
287+
"AsyncMainRealtime",
284288
]

portkey_ai/api_resources/apis/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@
157157
AsyncProviders,
158158
)
159159

160+
from .main_realtime import (
161+
MainRealtime,
162+
AsyncMainRealtime,
163+
)
164+
160165
sys.modules["openai"] = vendored_openai # For pydantic v1 and v2 compatibility
161166

162167
__all__ = [
@@ -293,4 +298,6 @@
293298
"AsyncProviders",
294299
"Webhooks",
295300
"AsyncWebhooks",
301+
"MainRealtime",
302+
"AsyncMainRealtime",
296303
]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from portkey_ai._vendor.openai.resources.realtime.realtime import (
2+
AsyncRealtimeConnectionManager,
3+
RealtimeConnectionManager,
4+
)
5+
from portkey_ai._vendor.openai.types.websocket_connection_options import (
6+
WebsocketConnectionOptions,
7+
)
8+
from portkey_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource
9+
from portkey_ai.api_resources.client import AsyncPortkey, Portkey
10+
from portkey_ai.api_resources.types.shared_types import Headers, Query
11+
12+
13+
class MainRealtime(APIResource):
14+
def __init__(self, client: Portkey) -> None:
15+
super().__init__(client)
16+
self.openai_client = client.openai_client
17+
18+
def connect(
19+
self,
20+
*,
21+
model: str,
22+
extra_query: Query = {},
23+
extra_headers: Headers = {},
24+
websocket_connection_options: WebsocketConnectionOptions = {},
25+
) -> RealtimeConnectionManager:
26+
return self.openai_client.realtime.connect(
27+
model=model,
28+
extra_query=extra_query,
29+
extra_headers=extra_headers,
30+
websocket_connection_options=websocket_connection_options,
31+
)
32+
33+
34+
class AsyncMainRealtime(AsyncAPIResource):
35+
def __init__(self, client: AsyncPortkey) -> None:
36+
super().__init__(client)
37+
self.openai_client = client.openai_client
38+
39+
def connect(
40+
self,
41+
*,
42+
model: str,
43+
extra_query: Query = {},
44+
extra_headers: Headers = {},
45+
websocket_connection_options: WebsocketConnectionOptions = {},
46+
) -> AsyncRealtimeConnectionManager:
47+
return self.openai_client.realtime.connect(
48+
model=model,
49+
extra_query=extra_query,
50+
extra_headers=extra_headers,
51+
websocket_connection_options=websocket_connection_options,
52+
)

portkey_ai/api_resources/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Portkey(APIClient):
3838
collections: apis.Collections
3939
integrations: apis.Integrations
4040
providers: apis.Providers
41+
realtime: apis.MainRealtime
4142

4243
class beta:
4344
assistants: apis.Assistants
@@ -184,6 +185,7 @@ def __init__(
184185
self.collections = apis.Collections(self)
185186
self.integrations = apis.Integrations(self)
186187
self.providers = apis.Providers(self)
188+
self.realtime = apis.MainRealtime(self)
187189
self.beta = self.beta(self) # type: ignore
188190

189191
if self.instrumentation:
@@ -366,6 +368,7 @@ class AsyncPortkey(AsyncAPIClient):
366368
collections: apis.AsyncCollections
367369
integrations: apis.AsyncIntegrations
368370
providers: apis.AsyncProviders
371+
realtime: apis.AsyncMainRealtime
369372

370373
class beta:
371374
assistants: apis.AsyncAssistants
@@ -512,6 +515,7 @@ def __init__(
512515
self.collections = apis.AsyncCollections(self)
513516
self.integrations = apis.AsyncIntegrations(self)
514517
self.providers = apis.AsyncProviders(self)
518+
self.realtime = apis.AsyncMainRealtime(self)
515519
self.beta = self.beta(self) # type: ignore
516520

517521
if self.instrumentation:

0 commit comments

Comments
 (0)