|
| 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 | + ) |
0 commit comments