Skip to content

Commit 60eeba8

Browse files
committed
openai integration
1 parent 9f100dd commit 60eeba8

File tree

11 files changed

+1050
-4
lines changed

11 files changed

+1050
-4
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
STREAM_API_KEY=892s22ypvt6m
22
STREAM_API_SECRET=5cssrefv55rs3cnkk38kfjam2k7c2ykwn4h79dqh66ym89gm65cxy4h9jx4cypd6
33
STREAM_BASE_URL=http://127.0.0.1:3030
4+
OPENAI_API_KEY=sk-your-openai-api-key

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ bin/*
2222
lib/*
2323
shell.nix
2424
pyrightconfig.json
25+
.DS_Store

getstream/stream.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def video(self):
5353
base_url=self.base_url,
5454
token=self.token,
5555
timeout=self.timeout,
56+
stream=self,
5657
)
5758

5859
@cached_property

getstream/video/call.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ def _sync_from_response(self, data):
1616
if hasattr(data, "call") and isinstance(data.call, CallResponse):
1717
self.custom_data = data.call.custom
1818

19+
def connect_openai(self, openai_api_key, agent_user_id):
20+
from .openai import get_openai_realtime_client, ConnectionManagerWrapper
21+
22+
client = get_openai_realtime_client(openai_api_key, self.client.base_url)
23+
token = self.client.stream.create_token(agent_user_id)
24+
connection_manager = client.beta.realtime.connect(
25+
extra_query={
26+
"call_type": self.call_type,
27+
"call_id": self.id,
28+
"api_key": self.client.api_key,
29+
},
30+
model="gpt-4o-realtime-preview",
31+
extra_headers={
32+
"Authorization": f"Bearer {openai_api_key}",
33+
"OpenAI-Beta": "realtime=v1",
34+
"Stream-Authorization": token,
35+
},
36+
)
37+
38+
# Wrap the connection manager to check for errors in the first message
39+
return ConnectionManagerWrapper(connection_manager, self.call_type, self.id)
40+
1941
def get(
2042
self,
2143
members_limit: Optional[int] = None,

getstream/video/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class VideoClient(VideoRestClient):
6-
def __init__(self, api_key: str, base_url, token, timeout):
6+
def __init__(self, api_key: str, base_url, token, timeout, stream):
77
"""
88
Initializes VideoClient with BaseClient instance
99
:param api_key: A string representing the client's API key
@@ -17,6 +17,7 @@ def __init__(self, api_key: str, base_url, token, timeout):
1717
token=token,
1818
timeout=timeout,
1919
)
20+
self.stream = stream
2021

2122
def call(self, call_type: str, id: str) -> Call:
2223
return Call(self, call_type, id)

0 commit comments

Comments
 (0)