17
17
from typing import (
18
18
TYPE_CHECKING ,
19
19
Any ,
20
- Dict ,
21
20
Iterator ,
22
- List ,
23
21
Mapping ,
24
22
Optional ,
25
23
Sequence ,
57
55
try :
58
56
from websockets .typing import Subprotocol as WSSubprotocol # runtime if available
59
57
except Exception :
58
+
60
59
class WSSubprotocol (str ): # fallback, keeps runtime simple
61
60
pass
62
61
62
+
63
63
if TYPE_CHECKING :
64
64
# Not imported at runtime; only for type checkers (mypy/pyright).
65
65
from websockets .sync .client import ClientConnection as _WSClientConnection
@@ -69,7 +69,7 @@ class WSSubprotocol(str): # fallback, keeps runtime simple
69
69
else :
70
70
from typing_extensions import NotRequired # noqa: F401
71
71
72
- __all__ : List [str ] = [
72
+ __all__ : list [str ] = [
73
73
"connect" ,
74
74
"WebsocketConnectionOptions" ,
75
75
"ConnectionError" ,
@@ -339,7 +339,7 @@ def clear(self, *, event_id: Optional[str] = None) -> None:
339
339
:return: None
340
340
:rtype: None
341
341
"""
342
- event : Dict [str , Any ] = {"type" : "output_audio_buffer.clear" }
342
+ event : dict [str , Any ] = {"type" : "output_audio_buffer.clear" }
343
343
if event_id :
344
344
event ["event_id" ] = event_id
345
345
self ._connection .send (event )
@@ -357,11 +357,7 @@ def __init__(self, connection: "VoiceLiveConnection") -> None:
357
357
self ._connection = connection
358
358
359
359
def create (
360
- self ,
361
- * ,
362
- item : Mapping [str , Any ],
363
- previous_item_id : Optional [str ] = None ,
364
- event_id : Optional [str ] = None
360
+ self , * , item : Mapping [str , Any ], previous_item_id : Optional [str ] = None , event_id : Optional [str ] = None
365
361
) -> None :
366
362
"""Create a new conversation item.
367
363
@@ -477,7 +473,7 @@ def update(self, *, session: Mapping[str, Any], event_id: Optional[str] = None)
477
473
:return: None
478
474
:rtype: None
479
475
"""
480
- event : Dict [str , Any ] = {"type" : "transcription_session.update" , "session" : dict (session )}
476
+ event : dict [str , Any ] = {"type" : "transcription_session.update" , "session" : dict (session )}
481
477
if event_id :
482
478
event ["event_id" ] = event_id
483
479
self ._connection .send (event )
@@ -674,14 +670,14 @@ def __enter__(self) -> VoiceLiveConnection:
674
670
675
671
# Build headers as str->str and use list of tuples to satisfy HeadersLike
676
672
extra_headers_map : Mapping [str , Any ] = self .__extra_headers or {}
677
- merged_headers : Dict [str , str ] = {
673
+ merged_headers : dict [str , str ] = {
678
674
** self ._get_auth_headers (),
679
675
** {str (k ): str (v ) for k , v in extra_headers_map .items ()},
680
676
}
681
- headers_like : List [Tuple [str , str ]] = list (merged_headers .items ())
677
+ headers_like : list [Tuple [str , str ]] = list (merged_headers .items ())
682
678
683
679
# Build kwargs for websockets; avoid dict(Optional[...])
684
- ws_kwargs : Dict [str , Any ] = {}
680
+ ws_kwargs : dict [str , Any ] = {}
685
681
if self .__connection_options is not None :
686
682
ws_kwargs .update (cast (Mapping [str , Any ], self .__connection_options ))
687
683
@@ -715,7 +711,7 @@ def __exit__(self, exc_type, exc, exc_tb) -> None:
715
711
if self .__connection is not None :
716
712
self .__connection .close ()
717
713
718
- def _get_auth_headers (self ) -> Dict [str , str ]:
714
+ def _get_auth_headers (self ) -> dict [str , str ]:
719
715
"""Get authentication headers for WebSocket connection.
720
716
721
717
:return: A dictionary containing authentication headers.
@@ -735,7 +731,7 @@ def _prepare_url(self) -> str:
735
731
parsed = urlparse (self ._endpoint )
736
732
scheme = "wss" if parsed .scheme == "https" else ("ws" if parsed .scheme == "http" else parsed .scheme )
737
733
738
- params : Dict [str , str ] = {"model" : self .__model , "api-version" : self .__api_version }
734
+ params : dict [str , str ] = {"model" : self .__model , "api-version" : self .__api_version }
739
735
extra_query : Mapping [str , Any ] = self .__extra_query or {}
740
736
for k , v in extra_query .items ():
741
737
params [str (k )] = str (v )
@@ -746,7 +742,7 @@ def _prepare_url(self) -> str:
746
742
if key not in params :
747
743
params [key ] = value_list [0 ] if value_list else ""
748
744
749
- path = parsed .path .rstrip ("/" ) + "/voice-agent /realtime"
745
+ path = parsed .path .rstrip ("/" ) + "/voice-live /realtime"
750
746
return urlunparse ((scheme , parsed .netloc , path , parsed .params , urlencode (params ), parsed .fragment ))
751
747
752
748
0 commit comments