@@ -61,10 +61,7 @@ def __init__(self, *, websocket: WebSocketClientProtocol):
6161
6262 async def __aiter__ (self ):
6363 async for message in self ._websocket :
64- if isinstance (message , bytes ):
65- yield message
66- else :
67- yield parse_obj_as (V1SocketClientResponse , json .loads (message )) # type: ignore
64+ yield parse_obj_as (V1SocketClientResponse , json .loads (message )) # type: ignore
6865
6966 async def start_listening (self ):
7067 """
@@ -79,12 +76,9 @@ async def start_listening(self):
7976 await self ._emit_async (EventType .OPEN , None )
8077 try :
8178 async for raw_message in self ._websocket :
82- if isinstance (raw_message , bytes ):
83- await self ._emit_async (EventType .MESSAGE , raw_message )
84- else :
85- json_data = json .loads (raw_message )
86- parsed = parse_obj_as (V1SocketClientResponse , json_data ) # type: ignore
87- await self ._emit_async (EventType .MESSAGE , parsed )
79+ json_data = json .loads (raw_message )
80+ parsed = parse_obj_as (V1SocketClientResponse , json_data ) # type: ignore
81+ await self ._emit_async (EventType .MESSAGE , parsed )
8882 except (websockets .WebSocketException , JSONDecodeError ) as exc :
8983 await self ._emit_async (EventType .ERROR , exc )
9084 finally :
@@ -142,7 +136,7 @@ async def send_update_prompt(self, message: AgentV1UpdatePrompt) -> None:
142136 async def send_media (self , message : bytes ) -> None :
143137 """
144138 Send a message to the websocket connection.
145- The message will be sent as bytes.
139+ The message will be sent as a bytes.
146140 """
147141 await self ._send (message )
148142
@@ -151,8 +145,6 @@ async def recv(self) -> V1SocketClientResponse:
151145 Receive a message from the websocket connection.
152146 """
153147 data = await self ._websocket .recv ()
154- if isinstance (data , bytes ):
155- return data # Binary audio data
156148 json_data = json .loads (data )
157149 return parse_obj_as (V1SocketClientResponse , json_data ) # type: ignore
158150
@@ -178,10 +170,7 @@ def __init__(self, *, websocket: websockets_sync_connection.Connection):
178170
179171 def __iter__ (self ):
180172 for message in self ._websocket :
181- if isinstance (message , bytes ):
182- yield message
183- else :
184- yield parse_obj_as (V1SocketClientResponse , json .loads (message )) # type: ignore
173+ yield parse_obj_as (V1SocketClientResponse , json .loads (message )) # type: ignore
185174
186175 def start_listening (self ):
187176 """
@@ -196,12 +185,9 @@ def start_listening(self):
196185 self ._emit (EventType .OPEN , None )
197186 try :
198187 for raw_message in self ._websocket :
199- if isinstance (raw_message , bytes ):
200- self ._emit (EventType .MESSAGE , raw_message )
201- else :
202- json_data = json .loads (raw_message )
203- parsed = parse_obj_as (V1SocketClientResponse , json_data ) # type: ignore
204- self ._emit (EventType .MESSAGE , parsed )
188+ json_data = json .loads (raw_message )
189+ parsed = parse_obj_as (V1SocketClientResponse , json_data ) # type: ignore
190+ self ._emit (EventType .MESSAGE , parsed )
205191 except (websockets .WebSocketException , JSONDecodeError ) as exc :
206192 self ._emit (EventType .ERROR , exc )
207193 finally :
@@ -259,7 +245,7 @@ def send_update_prompt(self, message: AgentV1UpdatePrompt) -> None:
259245 def send_media (self , message : bytes ) -> None :
260246 """
261247 Send a message to the websocket connection.
262- The message will be sent as bytes.
248+ The message will be sent as a bytes.
263249 """
264250 self ._send (message )
265251
@@ -268,8 +254,6 @@ def recv(self) -> V1SocketClientResponse:
268254 Receive a message from the websocket connection.
269255 """
270256 data = self ._websocket .recv ()
271- if isinstance (data , bytes ):
272- return data # Binary audio data
273257 json_data = json .loads (data )
274258 return parse_obj_as (V1SocketClientResponse , json_data ) # type: ignore
275259
0 commit comments