77from getstream import Stream
88from getstream .models import StartClosedCaptionsResponse
99from getstream .plugins .sts .openai_realtime import OpenAIRealtime
10- from dataclasses import asdict
11- import json
1210
1311
1412logging .basicConfig (
@@ -26,7 +24,6 @@ async def main():
2624
2725 load_dotenv (os .path .join (os .path .dirname (__file__ ), ".." , ".env" ))
2826
29- # Initialize Stream client from env vars (STREAM_API_KEY / SECRET / BASE_URL)
3027 client = Stream .from_env ()
3128
3229 user_id = f"user-{ uuid4 ()} "
@@ -52,15 +49,14 @@ async def main():
5249
5350 sts_bot = OpenAIRealtime (
5451 api_key = os .getenv ("OPENAI_API_KEY" ),
55- model = "gpt-4o-realtime-preview" ,
52+ model = os . getenv ( "OPENAI_REALTIME_MODEL" ) ,
5653 instructions = "You are a friendly assistant; reply verbally in a short sentence." ,
5754 voice = "alloy" ,
5855 )
5956
6057 try :
6158 logging .info ("Connecting to OpenAI Realtime..." )
6259
63- # Check if API key is set
6460 if not os .getenv ("OPENAI_API_KEY" ):
6561 logging .error ("❌ OPENAI_API_KEY not found in environment" )
6662 return
@@ -88,6 +84,8 @@ async def main():
8884 },
8985 tools = tools ,
9086 )
87+
88+ await sts_bot .send_user_message ("Give a short greeting to the user." )
9189
9290 logging .info ("🎧 Listening for responses... (Press Ctrl+C to stop)" )
9391 logging .info ("💡 Try speaking in the browser – ask it something like 'start closed captions' to trigger the function call." )
@@ -111,14 +109,10 @@ async def start_closed_captions() -> StartClosedCaptionsResponse:
111109 logging .info ("🛠 Assistant requested start_closed_captions()" )
112110
113111 result = await start_closed_captions ()
114-
115- # Send the tool result back to the assistant
116112 await sts_bot .send_function_call_output (tool_call_id , result .to_json ())
117-
113+ await sts_bot . request_assistant_response ()
118114 logging .info ("🛠 Replied to tool call with result: %s" , result )
119115
120-
121-
122116 except KeyboardInterrupt : # noqa: WPS420
123117 logging .info ("\n ⏹️ Stopping OpenAI Realtime Speech to Speech bot…" )
124118 except Exception as e : # noqa: BLE001
0 commit comments