11from dataclasses import dataclass
2+ import json
23from typing import Any , AsyncGenerator
34from rtclient import (
45 InputAudioBufferAppendMessage ,
@@ -47,6 +48,7 @@ async def close(self):
4748 if self .client is not None :
4849 await self .client .close ()
4950
51+ @trace
5052 async def send_user_message (self , message : str ):
5153 if self .client is None :
5254 raise Exception ("Client not set" )
@@ -68,6 +70,7 @@ async def send_user_message(self, message: str):
6870 )
6971 )
7072
73+ @trace
7174 async def send_user_message_with_response (self , message : str ):
7275 if self .client is None :
7376 raise Exception ("Client not set" )
@@ -95,11 +98,13 @@ async def send_user_message_with_response(self, message: str):
9598
9699 await self .client .send (ResponseCreateMessage (response = response ))
97100
101+ @trace
98102 async def trigger_response (self ):
99103 if self .client is None :
100104 raise Exception ("Client not set" )
101105 await self .client .send (ResponseCreateMessage ())
102106
107+ @trace
103108 async def send_system_message (self , message : str ):
104109 if self .client is None :
105110 raise Exception ("Client not set" )
@@ -121,6 +126,7 @@ async def send_system_message(self, message: str):
121126 )
122127 )
123128
129+ @trace
124130 async def send_session_update (self , instructions : str = None ):
125131 if self .client is None :
126132 raise Exception ("Client not set" )
@@ -149,7 +155,6 @@ async def send_audio_message(self, audio_data: Any):
149155
150156 await self .client .send (InputAudioBufferAppendMessage (audio = audio_data ))
151157
152- @trace (name = "realtime_loop" )
153158 async def receive_message (self ) -> AsyncGenerator [RealTimeItem , None ]:
154159 if self .client is None :
155160 raise Exception ("Client not set" )
@@ -164,9 +169,14 @@ async def receive_message(self) -> AsyncGenerator[RealTimeItem, None]:
164169 print ("Session Created Message" )
165170 print (f" Model: { message .session .model } " )
166171 print (f" Session Id: { message .session .id } " )
167- with Tracer .start ("session.created" ) as tr :
168- tr ("model" , message .session .model )
169- tr ("session_id" , message .session .id )
172+
173+ yield RealTimeItem (
174+ type = "session.created" ,
175+ content = {
176+ "model" : message .session .model ,
177+ "session" : message .session .id ,
178+ },
179+ )
170180
171181 case "error" :
172182 if self .verbose :
0 commit comments