
    _j_                   .   % S SK Jr  S SKrS SKrS SKrS SKrS SKJr  S SKJ	r	J
r
JrJrJrJrJr  S SKJr  S SKrS SKJr  SSKJrJrJrJrJrJr  S	S
KJrJrJrJ r   S	SK!J"r"J#r#J$r$J%r%J&r&  S	SK'J(r(  S	SK)J*r*  S	SK+J,r,J-r-  S	SK.J/r/J0r0  S	SK1J2r2  S	SK3J4r4  SSK5J6r6J7r7J8r8J9r9J:r:J;r;  S	SK<J=r=  S	SK>J?r?  S	SK@JArAJBrBJCrC  S	SKDJErE  S	SKFJGrG  S	SKHJIrI  S	SKJJKrK  S	SKLJMrM  S	SKNJOrO  S	SKPJQrQ  \	(       a  S SKRJSrT  S SKUJSrV  S	SKWJXrXJYrY  SS /rZ\R                  " \\5      r]S!\^S"'    " S# S\,5      r_ " S$ S \-5      r` " S% S&5      ra " S' S(5      rb " S) S*5      rc " S+ S,5      rd " S- S.5      re " S/ S05      rf " S1 S25      rg " S3 S45      rh " S5 S65      ri " S7 S8\i5      rj " S9 S:\i5      rk " S; S<\i5      rl " S= S>\i5      rm " S? S@\i5      rn " SA SB\i5      ro " SC SD5      rp " SE SF\p5      rq " SG SH\p5      rr " SI SJ\p5      rs " SK SL\p5      rt " SM SN\p5      ru " SO SP\p5      rvg)Q    )annotationsN)TracebackType)TYPE_CHECKINGAnyUnionCallableIterator	Awaitablecast)AsyncIterator)	BaseModel   )Calls
AsyncCallsCallsWithRawResponseAsyncCallsWithRawResponseCallsWithStreamingResponseAsyncCallsWithStreamingResponse   )OmitQueryHeadersomit)is_azure_clientmaybe_transformstrip_not_givenasync_maybe_transformis_async_azure_client)cached_property)construct_type_unchecked)SyncAPIResourceAsyncAPIResource)OpenAIErrorWebSocketConnectionClosedError)	SendQueue)_merge_mappings)ClientSecretsAsyncClientSecretsClientSecretsWithRawResponse!AsyncClientSecretsWithRawResponse"ClientSecretsWithStreamingResponse'AsyncClientSecretsWithStreamingResponse)EventHandlerRegistry)session_update_event_param)ReconnectingEventReconnectingOverridesis_recoverable_close)WebSocketConnectionOptions)RealtimeErrorEvent)RealtimeClientEvent)RealtimeServerEvent)ConversationItemParam)RealtimeClientEventParam)!RealtimeResponseCreateParamsParam)ClientConnection)OpenAIAsyncOpenAIRealtimeAsyncRealtimezlogging.Loggerlogc                      \ rS rSr\SS j5       r\SS j5       r\SS j5       r\SS j5       r\	\	0 0 0 SSSS	S
S.
                     SS jjr
Srg)r<   D   c                ,    [        U R                  5      $ N)r'   _clientselfs    W/home/rurouni/.local/lib/python3.13/site-packages/openai/resources/realtime/realtime.pyclient_secretsRealtime.client_secretsE   s    T\\**    c                2    SSK Jn  U" U R                  5      $ )Nr   )_Calls)lib._realtimerK   rC   )rE   rK   s     rF   callsRealtime.callsI   s    +dll##rI   c                    [        U 5      $ z
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.

For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
)RealtimeWithRawResponserD   s    rF   with_raw_responseRealtime.with_raw_responseO   s     't,,rI   c                    [        U 5      $ z
An alternative to `.with_raw_response` that doesn't eagerly read the response body.

For more information, see https://www.github.com/openai/openai-python#with_streaming_response
)RealtimeWithStreamingResponserD   s    rF   with_streaming_response Realtime.with_streaming_responseY   s     -T22rI   N         ?       @   
call_idmodelextra_queryextra_headerswebsocket_connection_optionson_reconnectingmax_retriesinitial_delay	max_delaymax_queue_sizec       
        <    [        U R                  UUUUUUU	U
UUS9$ a  
The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as function calling.

Some notable benefits of the API include:

- Native speech-to-speech: Skipping an intermediate text format means low latency and nuanced output.
- Natural, steerable voices: The models have natural inflection and can laugh, whisper, and adhere to tone direction.
- Simultaneous multimodal output: Text is useful for moderation; faster-than-realtime audio ensures stable playback.

The Realtime API is a stateful, event-based API that communicates over a WebSocket.
)clientr`   ra   rb   rc   rd   re   rf   rg   r^   r_   )RealtimeConnectionManagerrC   rE   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   s              rF   connectRealtime.connectb   s6    2 )<<#')E+#')
 	
rI    )returnr'   )rp   r   )rp   rQ   )rp   rV   )r^   
str | Omitr_   rq   r`   r   ra   r   rb   r2   rc   BCallable[[ReconnectingEvent], ReconnectingOverrides | None] | Nonerd   intre   floatrf   rt   rg   rs   rp   rk   __name__
__module____qualname____firstlineno__r   rG   rM   rR   rW   r   rm   __static_attributes__ro   rI   rF   r<   r<   D   s    + + $ $
 - - 3 3 # !#CE^b"'%
 %
 	%

 %
 %
 'A%
 \%
 %
 %
 %
 %
 
#%
 %
rI   c                      \ rS rSr\SS j5       r\SS j5       r\SS j5       r\SS j5       r\	\	0 0 0 SSSS	S
S.
                     SS jjr
Srg)r=      c                ,    [        U R                  5      $ rB   )r(   rC   rD   s    rF   rG   AsyncRealtime.client_secrets   s    !$,,//rI   c                2    SSK Jn  U" U R                  5      $ )Nr   )_AsyncCalls)rL   r   rC   )rE   r   s     rF   rM   AsyncRealtime.calls   s    04<<((rI   c                    [        U 5      $ rP   )AsyncRealtimeWithRawResponserD   s    rF   rR   AsyncRealtime.with_raw_response   s     ,D11rI   c                    [        U 5      $ rU   )"AsyncRealtimeWithStreamingResponserD   s    rF   rW   %AsyncRealtime.with_streaming_response   s     2$77rI   NrY   rZ   r[   r\   r]   c       
        <    [        U R                  UUUUUUU	U
UUS9$ ri   )AsyncRealtimeConnectionManagerrC   rl   s              rF   rm   AsyncRealtime.connect   s6    2 .<<#')E+#')
 	
rI   ro   )rp   r(   )rp   r   )rp   r   )rp   r   )r^   rq   r_   rq   r`   r   ra   r   rb   r2   rc   rr   rd   rs   re   rt   rf   rt   rg   rs   rp   r   ru   ro   rI   rF   r=   r=      s    0 0 ) )
 2 2 8 8 # !#CE^b"'%
 %
 	%

 %
 %
 'A%
 \%
 %
 %
 %
 %
 
(%
 %
rI   c                  F    \ rS rSrSS jr\SS j5       r\S	S j5       rSrg)
rQ      c                    Xl         g rB   	_realtimerE   realtimes     rF   __init__ RealtimeWithRawResponse.__init__       !rI   c                @    [        U R                  R                  5      $ rB   )r)   r   rG   rD   s    rF   rG   &RealtimeWithRawResponse.client_secrets   s    +DNN,I,IJJrI   c                @    [        U R                  R                  5      $ rB   )r   r   rM   rD   s    rF   rM   RealtimeWithRawResponse.calls   s    #DNN$8$899rI   r   Nr   r<   rp   None)rp   r)   )rp   r   	rv   rw   rx   ry   r   r   rG   rM   rz   ro   rI   rF   rQ   rQ      s1    " K K : :rI   rQ   c                  F    \ rS rSrSS jr\SS j5       r\S	S j5       rSrg)
r      c                    Xl         g rB   r   r   s     rF   r   %AsyncRealtimeWithRawResponse.__init__   r   rI   c                @    [        U R                  R                  5      $ rB   )r*   r   rG   rD   s    rF   rG   +AsyncRealtimeWithRawResponse.client_secrets   s    01N1NOOrI   c                @    [        U R                  R                  5      $ rB   )r   r   rM   rD   s    rF   rM   "AsyncRealtimeWithRawResponse.calls   s    ()=)=>>rI   r   Nr   r=   rp   r   )rp   r*   )rp   r   r   ro   rI   rF   r   r      s1    " P P ? ?rI   r   c                  F    \ rS rSrSS jr\SS j5       r\S	S j5       rSrg)
rV      c                    Xl         g rB   r   r   s     rF   r   &RealtimeWithStreamingResponse.__init__   r   rI   c                @    [        U R                  R                  5      $ rB   )r+   r   rG   rD   s    rF   rG   ,RealtimeWithStreamingResponse.client_secrets   s    1$..2O2OPPrI   c                @    [        U R                  R                  5      $ rB   )r   r   rM   rD   s    rF   rM   #RealtimeWithStreamingResponse.calls   s    )$..*>*>??rI   r   Nr   )rp   r+   )rp   r   r   ro   rI   rF   rV   rV      s3    " Q Q @ @rI   rV   c                  F    \ rS rSrSS jr\SS j5       r\S	S j5       rSrg)
r      c                    Xl         g rB   r   r   s     rF   r   +AsyncRealtimeWithStreamingResponse.__init__   r   rI   c                @    [        U R                  R                  5      $ rB   )r,   r   rG   rD   s    rF   rG   1AsyncRealtimeWithStreamingResponse.client_secrets   s    6t~~7T7TUUrI   c                @    [        U R                  R                  5      $ rB   )r   r   rM   rD   s    rF   rM   (AsyncRealtimeWithStreamingResponse.calls   s    .t~~/C/CDDrI   r   Nr   )rp   r,   )rp   r   r   ro   rI   rF   r   r      s3    " V V E ErI   r   c            	      H   \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   SSSSS0 0 SS.                   S&S jjrS'S jrS(S jrS)S jr	S*S jr
S+S jrSSS.S,S jjrS-S jrS.S jrS/S  jr S0     S1S! jjrS2S" jr S0     S1S# jjrS/S$ jrS%rg)3AsyncRealtimeConnectioni  :Represents a live WebSocket connection to the Realtime APIAsyncRealtimeSessionResourcesessionAsyncRealtimeResponseResourceresponse%AsyncRealtimeInputAudioBufferResourceinput_audio_buffer!AsyncRealtimeConversationResourceconversation&AsyncRealtimeOutputAudioBufferResourceoutput_audio_bufferAsyncWebSocketConnection_connectionNrY   rZ   r[   make_wsrc   rd   re   rf   r`   ra   
send_queuec               l   Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        SU l        SU l	        U	=(       d
    [        5       U l        [        SS9U l        [        U 5      U l        [!        U 5      U l        [%        U 5      U l        [)        U 5      U l        [-        U 5      U l        g )NFuse_lock)r   _make_ws_on_reconnecting_max_retries_initial_delay
_max_delay_extra_query_extra_headers_intentionally_closed_is_reconnectingr%   _send_queuer-   _event_handler_registryr   r   r   r   r   r   r   r   r   r   
rE   
connectionr   rc   rd   re   rf   r`   ra   r   s
             rF   r    AsyncRealtimeConnection.__init__  s     & /'+#'+%*" %%4';U'K$3D95d;"G"M=dC#I$#O rI   c               (  #    SSK JnJn    U R                  5       I Sh  vN 7v   M   N	! U a     gU aV  nU R	                  U5      I Sh  vN  (       d-  U R
                  R                  5       nU(       a  [        SUS9Uee  SnANbSnAff = f7fzY
An infinite-iterator that will continue to yield events until
the connection is closed.
r   )ConnectionClosedOKConnectionClosedErrorNz0WebSocket connection closed with unsent messages)unsent_messageswebsockets.exceptionsr   r   recv
_reconnectr   drainr$   rE   r   r   excunsents        rF   	__aiter__!AsyncRealtimeConnection.__aiter__/  s     
 	T IIK'' '% ( !__S111!--335F<N,2  ##  2sL   
B, *, B, BBBB
A7B
B
BBc                \   #    U R                  U R                  5       I Sh  vN 5      $  N7f)
Receive the next message from the connection and parses it into a `RealtimeServerEvent` object.

Canceling this method is safe. There's no risk of losing data.
Nparse_event
recv_bytesrD   s    rF   r   AsyncRealtimeConnection.recvE  s%      doo&7 788 7s   ,*	,c                   #    U R                   R                  SS9I Sh  vN n[        R                  SU5        U$  N7f)Receive the next message from the connection as raw bytes.

Canceling this method is safe. There's no risk of losing data.

If you want to parse the message into a `RealtimeServerEvent` object like `.recv()` does,
then you can call `.parse_event(data)`.
FdecodeNReceived WebSocket message: %sr   r   r>   debugrE   messages     rF   r   "AsyncRealtimeConnection.recv_bytesM  s<      ((--U-;;		2W= <s   ><>c                  #    [        U[        5      (       a  UR                  SSSS9O+[        R                  " [        U[        5      I S h  vN 5      nU R                  (       a  U R                  R                  U5        g  U R                  R                  U5      I S h  vN   g  NZ N! [         a    U R                  R                  U5        e f = f7fNTuse_api_namesexclude_defaultsexclude_unset)
isinstancer   to_jsonjsondumpsr   r7   r   r   enqueuer   send	ExceptionrE   eventdatas      rF   r  AsyncRealtimeConnection.sendY  s      %++ MMtSWMX"7?W"XXY 	
   $$T*	""''--- Y . 	$$T*	s<   A
CB'5CB+ !B)"B+ &C)B+ +'CCc                   #    U R                   (       aD  [        U[        5      (       a  UOUR                  S5      nU R                  R                  U5        g U R                  R                  U5      I S h  vN   g  N7fNzutf-8r   r   strr   r   r  r   r  rE   r  raws      rF   send_raw AsyncRealtimeConnection.send_rawh  s[       $T3//$T[[5IC$$S)##D)))s   A4A>6A<7A>   codereasonc               `   #    SU l         U R                  R                  XS9I S h  vN   g  N7fNTr  r   r   closerE   r  r  s      rF   r  AsyncRealtimeConnection.closeo  s*     %)"$$$$>>>s   $.,.c           
     ~    [        [        [        [        R                  " U5      [        [
        [        5      S95      $ z
Converts a raw `str` or `bytes` message into a `RealtimeServerEvent` object.

This is helpful if you're using `.recv_bytes()`.
)valuetype_r   r5   r    r   loadsr   rE   r  s     rF   r   #AsyncRealtimeConnection.parse_events  1     !9

4@PX\]`buXv!w
 	
rI   c           
       #    SSK nU R                  b  U R                  c  gSSKJn  Sn[        X5      (       a#  UR                  b  UR                  R                  n[        U5      (       d  gSU l	        [        SU R                  S-   5       GH  n[        U R                  SUS-
  -  -  U R                  5      nS	[        R                  " 5       S
-  -   nXg-  n[!        UU R                  UUU R"                  U R$                  S9n	 U R                  U	5      n
U
b  U
R)                  S5      (       a	  SU l	          gU
b   SU
;   a
  U
S   U l        SU
;   a
  U
S   U l        [*        R-                  SUU R                  U5        UR/                  U5      I Sh  vN   U R0                  (       a	  SU l	          g U R                  U R"                  U R$                  5      I Sh  vN U l        [*        R-                  S5        SU l	        U R5                  5       I Sh  vN     g   SU l	        g! [&         a    SU l	           gf = f N Nc N,! [&         a     GM  f = f7f)Attempt to reconnect after a connection failure.

Returns ``True`` if a new connection was established, ``False`` if the
caller should re-raise the original exception.
r   NFr     Tr            ?      ?attemptmax_attemptsdelay
close_coder`   ra   abortr`   ra   ?Reconnecting to WebSocket API (attempt %d/%d) after %.1fs delayReconnected to WebSocket API)asyncior   r   r   r   r   rcvdr  r1   r   ranger   minr   r   randomr/   r   r   r  getr>   infosleepr   r   _flush_send_queue)rE   r   r3  r   r/  r,  
base_delayjitterr.  r  results              rF   r   "AsyncRealtimeConnection._reconnect}  s6     	  (DMM,A?
c11chh6JJ#J// $Q 1 1A 56GT00A'A+4FGYJFMMOd22F'E%!..% --"11E..u5
 !fjj&9&9(-%! F*(.}(=D%"f,*0*AD'HHQ!!	 --&&&))(-%)-t7H7H$J]J])^#^ 78(-%,,..._ 7f !&I  (-%( ' $_ / s   DIH&A;IH>I3)II 8IIII&H;7I:H;;I II
IIIIc                   ^ #    SU 4S jjn T R                   R                  U5      I Sh  vN   g N! [         a    [        R	                  SSS9   gf = f7f)5Send all queued messages over the current connection.c                X   >#    TR                   R                  U 5      I S h  vN   g  N7frB   r   r  r  rE   s    rF   _send8AsyncRealtimeConnection._flush_send_queue.<locals>._send  s      ""''---s   *(*N*Failed to flush send queue after reconnectTexc_info)r  r  rp   r   )r   flush_asyncr  r>   warning)rE   rE  s   ` rF   r;  )AsyncRealtimeConnection._flush_send_queue  sL     	.	U""..u555 	UKKDtKT	Us1   	A3 13 A3 AAAAc                ^   ^ ^ Ub  T R                   R                  TU5        T $ SUU 4S jjnU$ )a  Adds the handler to the end of the handlers list for the given event type.

No checks are made to see if the handler has already been added. Multiple calls
passing the same combination of event type and handler will result in the handler
being added, and called, multiple times.

Can be used as a method (returns ``self`` for chaining)::

    connection.on("conversation.created", my_handler)

Or as a decorator::

    @connection.on("conversation.created")
    async def my_handler(event): ...
c                @   > TR                   R                  TU 5        U $ rB   r   addfn
event_typerE   s    rF   	decorator-AsyncRealtimeConnection.on.<locals>.decorator      ((,,Z<IrI   rR  Callable[..., Any]rp   rX  rO  rE   rS  handlerrT  s   ``  rF   onAsyncRealtimeConnection.on  8    $ ((,,ZAK	 	 rI   c                <    U R                   R                  X5        U $ z-Remove a previously registered event handler.r   removerE   rS  rZ  s      rF   offAsyncRealtimeConnection.off      $$++J@rI   c                \   ^ ^ Ub  T R                   R                  TUSS9  T $ SUU 4S jjnU$ )RRegister a one-time event handler.

Automatically removed after first invocation.
Toncec                >   > TR                   R                  TU SS9  U $ NTrh  rO  rQ  s    rF   rT  /AsyncRealtimeConnection.once.<locals>.decorator   #    ((,,Z$,GIrI   rW  rO  rY  s   ``  rF   ri  AsyncRealtimeConnection.once  =     ((,,Zt,LK	 	 rI   c                  #    SSK nU   Sh  vN nUR                  nU R                  R                  U5      nU R                  R                  S5      nUS:X  a1  U(       d*  U(       d#  [	        U[
        5      (       a  [        SU 35      eU H-  nU" U5      nUR                  U5      (       d  M#  UI Sh  vN   M/     U H-  nU" U5      nUR                  U5      (       d  M#  UI Sh  vN   M/     M   N N? N
 g7f)aD  Run the event loop, dispatching received events to registered handlers.

Blocks until the connection is closed. This is the push-based
alternative to iterating with ``async for event in connection``.

If an ``"error"`` event arrives and no handler is registered for
``"error"`` or ``"event"``, an ``OpenAIError`` is raised.
r   Nr  errorWebSocket error: )r3  typer   get_handlersr   r3   r#   iscoroutine)rE   r3  r  rS  specificgenericrZ  r>  s           rF   dispatch_events'AsyncRealtimeConnection.dispatch_events  s      	 	!%J33@@LH22??HGW$Xge%788%(9%&ABB# &&v.. LL $
 # &&v.. LL #	! !
 !#  sV   C;C9C3C9BC;0C;5C56)C;#C;(C7)
C;3C95C;7C;9C;r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   zFCallable[[Query, Headers], Awaitable[AsyncWebSocketConnection]] | Nonerc   rr   rd   rs   re   rt   rf   rt   r`   r   ra   r   r   SendQueue | Nonerp   r   )rp   z"AsyncIterator[RealtimeServerEvent]rp   r5   rp   bytesr  z.RealtimeClientEvent | RealtimeClientEventParamrp   r   r  zbytes | strrp   r   r  rs   r  r  rp   r   r  zstr | bytesrp   r5   r   r  rp   boolrp   r   rB   )rS  r  rZ  Callable[..., Any] | Nonerp   zRUnion[AsyncRealtimeConnection, Callable[[Callable[..., Any]], Callable[..., Any]]])rS  r  rZ  rX  rp   r   )rv   rw   rx   ry   __doc____annotations__r   r   r   r   r  r  r  r   r   r;  r[  rc  ri  rx  rz   ro   rI   rF   r   r     sC   D))++==33??)) [_^b"!#'+P,P X	P
 \P P P P P P %P 
P@,9
* *.R ?
JX	U EI(A	[8 EI(A	["!rI   r   c                      \ rS rSrSr\\SSSSSS.                       SS	 jjrSS
 jr S     SS jjrSS jr	 S     SS jjr
SS jr\rSS jrSS jr        SS jrSrg)r   i%  a  
Context manager over a `AsyncRealtimeConnection` that is returned by `realtime.connect()`

This context manager ensures that the connection will be closed when it exits.

---

Note that if your application doesn't work well with the context manager approach then you
can call the `.enter()` method directly to initiate a connection.

**Warning**: You must remember to close the connection with `.close()`.

```py
connection = await client.realtime.connect(...).enter()
# ...
await connection.close()
```
NrY   rZ   r[   r\   r^   r_   rc   rd   re   rf   rg   c                   Xl         X l        X0l        S U l        X@l        XPl        X`l        Xpl        Xl        Xl	        Xl
        [        US9U l        [        SS9U l        g )N	max_bytesFr   )'_AsyncRealtimeConnectionManager__client(_AsyncRealtimeConnectionManager__call_id&_AsyncRealtimeConnectionManager__model+_AsyncRealtimeConnectionManager__connection,_AsyncRealtimeConnectionManager__extra_query._AsyncRealtimeConnectionManager__extra_headers=_AsyncRealtimeConnectionManager__websocket_connection_options0_AsyncRealtimeConnectionManager__on_reconnecting,_AsyncRealtimeConnectionManager__max_retries._AsyncRealtimeConnectionManager__initial_delay*_AsyncRealtimeConnectionManager__max_delayr%   +_AsyncRealtimeConnectionManager__send_queuer-   7_AsyncRealtimeConnectionManager__event_handler_registryrE   rj   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   s               rF   r   'AsyncRealtimeConnectionManager.__init__9  s_      <@(,.J+!0(,$%?(<e(L%rI   c                    [        U[        5      (       a  UR                  SSSS9O[        R                  " U5      nU R
                  R                  U5        gzQueue a message to be sent when the connection is established.

This can be called before entering the context manager. Queued messages
are automatically sent once the WebSocket connection opens.
Tr   N)r   r   r   r   r   r  r  r  s      rF   r  #AsyncRealtimeConnectionManager.sendV  M     %++ MMtSWMXE" 	
 	!!$'rI   c                ^   ^ ^ Ub  T R                   R                  TU5        T $ SUU 4S jjnU$ )zRegister an event handler before the connection is established.

Handlers are transferred to the connection on enter. Supports the
same method and decorator forms as ``AsyncRealtimeConnection.on``.
c                @   > TR                   R                  TU 5        U $ rB   r  rP  rQ  s    rF   rT  4AsyncRealtimeConnectionManager.on.<locals>.decoratoro      ))--j"=IrI   rW  r  rY  s   ``  rF   r[  !AsyncRealtimeConnectionManager.onc  8     ))--j'BK	 	 rI   c                <    U R                   R                  X5        U $ r_  )r  ra  rb  s      rF   rc  "AsyncRealtimeConnectionManager.offu      %%,,ZArI   c                \   ^ ^ Ub  T R                   R                  TUSS9  T $ SUU 4S jjnU$ )GRegister a one-time event handler before the connection is established.Trh  c                >   > TR                   R                  TU SS9  U $ rk  r  rQ  s    rF   rT  6AsyncRealtimeConnectionManager.once.<locals>.decorator  #    ))--j"4-HIrI   rW  r  rY  s   ``  rF   ri  #AsyncRealtimeConnectionManager.oncez  =     ))--j'-MK	 	 rI   c                  #    U R                  U R                  U R                  5      I Sh  vN n[        UU R                  b  U R                   OSU R                  U R
                  U R                  U R                  U R                  U R                  U R                  S9	U l	        U R                  R                  U R                  R                  5        U R                  R                  5       I Sh  vN   U R                  $  N N7f)a5  
If your application doesn't work well with the context manager approach then you
can call this method directly to initiate a connection.

**Warning**: You must remember to close the connection with `.close()`.

```py
connection = await client.realtime.connect(...).enter()
# ...
await connection.close()
```
Nr   )_connect_wsr  r  r   r  r  r  r  r  r  r  
merge_intor   r;  rE   wss     rF   
__aenter__)AsyncRealtimeConnectionManager.__aenter__  s      ##D$6$68L8LMM3(,(>(>(JD$$PT 22**..&&**..((

 	%%001B1B1Z1Z[11333   # N 	4s"   *DDCD2D3DDc                  #     SSK Jn  U R                  R                  5       I S h  vN   U R                  R                  nU R                  [        La  0 UESU R                  0En[        U R                  5      (       aD  U R                  nU(       d  [        S5      eU R                  R                  Xa5      I S h  vN u  puObU R                  5       R                  0 U R                  R                  R                  EU R                  [        La  SU R                  0O0 EUES9n[         R#                  SU5        U R$                  (       a   [         R#                  S	U R$                  5        U" ['        U5      4U R                  R(                  [+        0 UEU5      S
.U R$                  D6I S h  vN $ ! [         a  n[        S5      UeS nAff = f GN GN N(7fNr   )rm   z9You need to install `openai[realtime]` to use this methodr^   z*`model` is required for Azure Realtime APIr_   )paramszConnecting to %szConnection options: %s)user_agent_headeradditional_headers)websockets.asyncio.clientrm   ImportErrorr#   r  _refresh_api_keyauth_headersr  r   r   r  _configure_realtime_prepare_url	copy_withbase_urlr  r>   r   r  r  
user_agentr&   rE   r`   ra   rm   r   r  r_   urls           rF   r  *AsyncRealtimeConnectionManager._connect_ws  s    	d9 mm,,...}}11>>%D[D)T^^DK //LLE!"NOO*.--*K*KE*_$_!\##%//mm,,3326,,d2J.PR " 0 C 			$c*..II.0S0STH

"mm66." 	 

 11

 

 
	
3  	dYZ`cc	d 	/ %`

sW   GF5 GGBG=G>C2G0G1G5
G?GGGGGc                z   U R                   R                  b+  [        R                  " U R                   R                  5      nOMU R                   R                  R
                  nUS:X  a  SOSnU R                   R                  R                  US9nUR                  R                  S5      S-   nUR                  US9$ Nhttpr  wss)scheme   /s	   /realtime)raw_path)	r  websocket_base_urlhttpxURL	_base_urlr  r  r  rstriprE   r  r  	ws_schememerge_raw_paths        rF   r  +AsyncRealtimeConnectionManager._prepare_url      ==++7yy!A!ABH]],,33F && 0eI}}..88	8JH!**11$7,F!!>!::rI   c                p   #    U R                   b#  U R                   R                  5       I S h  vN   g g  N7frB   )r  r  rE   exc_typer   exc_tbs       rF   	__aexit__(AsyncRealtimeConnectionManager.__aexit__  s3      (##))+++ )+s   +646	__call_id__client__connection__event_handler_registry__extra_headers__extra_query__initial_delay__max_delay__max_retries__model__on_reconnecting__send_queue__websocket_connection_options)rj   r;   r^   rq   r_   rq   r`   r   ra   r   rb   r2   rc   rr   rd   rs   re   rt   rf   rt   rg   rs   rp   r   r  rB   )rS  r  rZ  r  rp   zYUnion[AsyncRealtimeConnectionManager, Callable[[Callable[..., Any]], Callable[..., Any]]])rS  r  rZ  rX  rp   r   )rp   r   )r`   r   ra   r   rp   r   rp   z	httpx.URLr  ztype[BaseException] | Noner   zBaseException | Noner  zTracebackType | Nonerp   r   )rv   rw   rx   ry   r  r   r   r  r[  rc  ri  r  enterr  r  r  rz   ro   rI   rF   r   r   %  s=   . #  _c"'M M 	M
 M M M 'AM \M M M M M 
M:( EI(A	b$ EI(A	b!@ E&
P	;,2,9M,Wk,	,rI   r   c            	      H   \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   SSSSS0 0 SS.                   S&S jjrS'S jrS(S jrS)S jr	S*S jr
S+S jrSSS.S,S jjrS-S jrS.S jrS/S  jr S0     S1S! jjrS2S" jr S0     S1S# jjrS/S$ jrS%rg)3RealtimeConnectioni  r   RealtimeSessionResourcer   RealtimeResponseResourcer    RealtimeInputAudioBufferResourcer   RealtimeConversationResourcer   !RealtimeOutputAudioBufferResourcer   WebSocketConnectionr   NrY   rZ   r[   r   c               l   Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        SU l        SU l	        U	=(       d
    [        5       U l        [        SS9U l        [        U 5      U l        [!        U 5      U l        [%        U 5      U l        [)        U 5      U l        [-        U 5      U l        g )NFTr   )r   r   r   r   r   r   r   r   r   r   r%   r   r-   r   r  r   r  r   r  r   r  r   r  r   r   s
             rF   r   RealtimeConnection.__init__  s     & /'+#'+%*" %%4';T'J$.t406"B4"H8>#DT#J rI   c              #     #    SSK JnJn    U R                  5       v   M  ! U a     gU aM  nU R	                  U5      (       d-  U R
                  R                  5       nU(       a  [        SUS9Uee  SnANWSnAff = f7fr   r   r   s        rF   __iter__RealtimeConnection.__iter__  s     
 	Tiik!  & ( s++!--335F<N,2  ##  ,s5   
A>! A>A;A>A;AA61A>6A;;A>c                @    U R                  U R                  5       5      $ )r   r   rD   s    rF   r   RealtimeConnection.recv%  s      122rI   c                d    U R                   R                  SS9n[        R                  SU5        U$ )r   Fr   r   r   r   s     rF   r   RealtimeConnection.recv_bytes-  s1     ""''u'5		2W=rI   c                ~   [        U[        5      (       a  UR                  SSSS9O#[        R                  " [        U[        5      5      nU R                  (       a  U R                  R                  U5        g  U R                  R                  U5        g ! [         a    U R                  R                  U5        e f = fr   )r   r   r   r   r   r   r7   r   r   r  r   r  r  r  s      rF   r  RealtimeConnection.send9  s     %++ MMtSWMXOE3KLM 	
   $$T*	!!$' 	$$T*	s   9B 'B<c                    U R                   (       aD  [        U[        5      (       a  UOUR                  S5      nU R                  R                  U5        g U R                  R                  U5        g r	  r
  r  s      rF   r  RealtimeConnection.send_rawH  sR      $T3//$T[[5IC$$S)d#rI   r  r  r  c               D    SU l         U R                  R                  XS9  g r  r  r  s      rF   r  RealtimeConnection.closeO  s!    %)"D8rI   c           
     ~    [        [        [        [        R                  " U5      [        [
        [        5      S95      $ r  r  r!  s     rF   r   RealtimeConnection.parse_eventS  r#  rI   c           
     n   U R                   b  U R                  c  gSSKJn  Sn[	        X5      (       a#  UR
                  b  UR
                  R                  n[        U5      (       d  gSU l        [        SU R                  S-   5       GHx  n[        U R                  SUS-
  -  -  U R                  5      nS[        R                  " 5       S	-  -   nXV-  n[        UU R                  UUU R                   U R"                  S
9n U R                  U5      n	U	b  U	R'                  S5      (       a	  SU l          gU	b   SU	;   a
  U	S   U l        SU	;   a
  U	S   U l        [(        R+                  SUU R                  U5        [,        R.                  " U5        U R0                  (       a	  SU l          g U R                  U R                   U R"                  5      U l        [(        R+                  S5        SU l        U R5                  5           g   SU l        g! [$         a    SU l           gf = f! [$         a     GM  f = f)r%  Fr   r&  r'  Tr   r(  r)  r*  r+  r0  r`   ra   r1  r2  )r   r   r   r   r   r4  r  r1   r   r5  r   r6  r   r   r7  r/   r   r   r  r8  r>   r9  timer:  r   r   r;  )
rE   r   r   r/  r,  r<  r=  r.  r  r>  s
             rF   r   RealtimeConnection._reconnect]  s      (DMM,A?
c11chh6JJ#J// $Q 1 1A 56GT00A'A+4FGYJFMMOd22F'E%!..% --"11E..u5
 !fjj&9&9(-%! F*(.}(=D%"f,*0*AD'HHQ!!	 JJu))(-%#'==1B1BDDWDW#X 78(-%&&(_ 7f !&I  (-%@  s%   H*AH%H"!H"%
H43H4c                   ^   T R                   R                  U 4S j5        g! [         a    [        R	                  SSS9   gf = f)rA  c                :   > TR                   R                  U 5      $ rB   rC  rD  s    rF   <lambda>6RealtimeConnection._flush_send_queue.<locals>.<lambda>  s    T5E5E5J5J45PrI   rG  TrH  N)r   
flush_syncr  r>   rK  rD   s   `rF   r;  $RealtimeConnection._flush_send_queue  s@    	U''(PQ 	UKKDtKT	Us   # AAc                ^   ^ ^ Ub  T R                   R                  TU5        T $ SUU 4S jjnU$ )a  Adds the handler to the end of the handlers list for the given event type.

No checks are made to see if the handler has already been added. Multiple calls
passing the same combination of event type and handler will result in the handler
being added, and called, multiple times.

Can be used as a method (returns ``self`` for chaining)::

    connection.on("conversation.created", my_handler)

Or as a decorator::

    @connection.on("conversation.created")
    def my_handler(event): ...
c                @   > TR                   R                  TU 5        U $ rB   rO  rQ  s    rF   rT  (RealtimeConnection.on.<locals>.decorator  rV  rI   rW  rO  rY  s   ``  rF   r[  RealtimeConnection.on  r]  rI   c                <    U R                   R                  X5        U $ r_  r`  rb  s      rF   rc  RealtimeConnection.off  re  rI   c                \   ^ ^ Ub  T R                   R                  TUSS9  T $ SUU 4S jjnU$ )rg  Trh  c                >   > TR                   R                  TU SS9  U $ rk  rO  rQ  s    rF   rT  *RealtimeConnection.once.<locals>.decorator  rm  rI   rW  rO  rY  s   ``  rF   ri  RealtimeConnection.once  ro  rI   c                L   U  H  nUR                   nU R                  R                  U5      nU R                  R                  S5      nUS:X  a1  U(       d*  U(       d#  [        U[        5      (       a  [        SU 35      eU H  nU" U5        M     U H  nU" U5        M     M     g)aQ  Run the event loop, dispatching received events to registered handlers.

Blocks the current thread until the connection is closed. This is the push-based
alternative to iterating with ``for event in connection``.

If an ``"error"`` event arrives and no handler is registered for
``"error"`` or ``"event"``, an ``OpenAIError`` is raised.
r  rq  rr  N)rs  r   rt  r   r3   r#   )rE   r  rS  rv  rw  rZ  s         rF   rx  "RealtimeConnection.dispatch_events  s     EJ33@@LH22??HGW$Xge%788%(9%&ABB# $ # # rI   rz  )r   r  r   z6Callable[[Query, Headers], WebSocketConnection] | Nonerc   rr   rd   rs   re   rt   rf   rt   r`   r   ra   r   r   r{  rp   r   )rp   zIterator[RealtimeServerEvent]r|  r}  r  r  r  r  r  r  rB   )rS  r  rZ  r  rp   zMUnion[RealtimeConnection, Callable[[Callable[..., Any]], Callable[..., Any]]])rS  r  rZ  rX  rp   r  )rv   rw   rx   ry   r  r  r   r  r   r   r  r  r  r   r   r;  r[  rc  ri  rx  rz   ro   rI   rF   r  r    sC   D$$&&88..::$$ KO^b"!#'+K'K H	K
 \K K K K K K %K 
K@,3
$ $(r 9
HTU EI(A	V8 EI(A	V"rI   r  c                      \ rS rSrSr\\SSSSSS.                       SS	 jjrSS
 jr S     SS jjrSS jr	 S     SS jjr
SS jr\rSS jrSS jr        SS jrSrg)rk   i  a  
Context manager over a `RealtimeConnection` that is returned by `realtime.connect()`

This context manager ensures that the connection will be closed when it exits.

---

Note that if your application doesn't work well with the context manager approach then you
can call the `.enter()` method directly to initiate a connection.

**Warning**: You must remember to close the connection with `.close()`.

```py
connection = client.realtime.connect(...).enter()
# ...
connection.close()
```
NrY   rZ   r[   r\   r  c                   Xl         X l        X0l        S U l        X@l        XPl        X`l        Xpl        Xl        Xl	        Xl
        [        US9U l        [        SS9U l        g )Nr  Tr   )"_RealtimeConnectionManager__client#_RealtimeConnectionManager__call_id!_RealtimeConnectionManager__model&_RealtimeConnectionManager__connection'_RealtimeConnectionManager__extra_query)_RealtimeConnectionManager__extra_headers8_RealtimeConnectionManager__websocket_connection_options+_RealtimeConnectionManager__on_reconnecting'_RealtimeConnectionManager__max_retries)_RealtimeConnectionManager__initial_delay%_RealtimeConnectionManager__max_delayr%   &_RealtimeConnectionManager__send_queuer-   2_RealtimeConnectionManager__event_handler_registryr  s               rF   r   "RealtimeConnectionManager.__init__  s_      7;(,.J+!0(,$%?(<d(K%rI   c                    [        U[        5      (       a  UR                  SSSS9O[        R                  " U5      nU R
                  R                  U5        gr  )r   r   r   r   r   r-  r  r  s      rF   r  RealtimeConnectionManager.send*  r  rI   c                ^   ^ ^ Ub  T R                   R                  TU5        T $ SUU 4S jjnU$ )zRegister an event handler before the connection is established.

Handlers are transferred to the connection on enter. Supports the
same method and decorator forms as ``RealtimeConnection.on``.
c                @   > TR                   R                  TU 5        U $ rB   r.  rP  rQ  s    rF   rT  /RealtimeConnectionManager.on.<locals>.decoratorC  r  rI   rW  r4  rY  s   ``  rF   r[  RealtimeConnectionManager.on7  r  rI   c                <    U R                   R                  X5        U $ r_  )r.  ra  rb  s      rF   rc  RealtimeConnectionManager.offI  r  rI   c                \   ^ ^ Ub  T R                   R                  TUSS9  T $ SUU 4S jjnU$ )r  Trh  c                >   > TR                   R                  TU SS9  U $ rk  r4  rQ  s    rF   rT  1RealtimeConnectionManager.once.<locals>.decoratorV  r  rI   rW  r4  rY  s   ``  rF   ri  RealtimeConnectionManager.onceN  r  rI   c                   U R                  U R                  U R                  5      n[        UU R                  b  U R                   OSU R                  U R
                  U R                  U R                  U R                  U R                  U R                  S9	U l	        U R                  R                  U R                  R                  5        U R                  R                  5         U R                  $ )a)  
If your application doesn't work well with the context manager approach then you
can call this method directly to initiate a connection.

**Warning**: You must remember to close the connection with `.close()`.

```py
connection = client.realtime.connect(...).enter()
# ...
connection.close()
```
Nr   )r  r&  r'  r  r)  r*  r+  r,  r-  r%  r.  r  r   r;  r  s     rF   	__enter__#RealtimeConnectionManager.__enter__\  s     d00$2F2FG.(,(>(>(JD$$PT 22**..&&**..((

 	%%001B1B1Z1Z[++-   rI   c                r    SSK Jn  U R                  R                  5         U R                  R                  nU R                  [        La  0 UESU R                  0En[        U R                  5      (       a<  U R                  nU(       d  [        S5      eU R                  R                  Xa5      u  puObU R                  5       R                  0 U R                  R                  R                  EU R                  [        La  SU R                  0O0 EUES9n[         R#                  SU5        U R$                  (       a   [         R#                  S	U R$                  5        U" ['        U5      4U R                  R(                  [+        0 UEU5      S
.U R$                  D6$ ! [         a  n[        S5      UeS nAff = fr  )websockets.sync.clientrm   r  r#   r"  r  r  r#  r   r   r$  r  r  r  r  r  r>   r   r(  r  r  r&   r  s           rF   r  %RealtimeConnectionManager._connect_ws~  s   	d6 	&&(}}11>>%D[D)T^^DK4==))LLE!"NOO$(MM$E$Ee$Y!\##%//mm,,3326,,d2J.PR " 0 C 			$c*..II.0S0STH

"mm66." 	 

 11

 
	
3  	dYZ`cc	ds   F 
F6%F11F6c                z   U R                   R                  b+  [        R                  " U R                   R                  5      nOMU R                   R                  R
                  nUS:X  a  SOSnU R                   R                  R                  US9nUR                  R                  S5      S-   nUR                  US9$ r  )	r"  r  r  r  r  r  r  r  r  r  s        rF   r  &RealtimeConnectionManager._prepare_url  r  rI   c                T    U R                   b  U R                   R                  5         g g rB   )r%  r  r  s       rF   __exit__"RealtimeConnectionManager.__exit__  s'     (##% )rI   r  )rj   r:   r^   rq   r_   rq   r`   r   ra   r   rb   r2   rc   rr   rd   rs   re   rt   rf   rt   rg   rs   rp   r   r  rB   )rS  r  rZ  r  rp   zTUnion[RealtimeConnectionManager, Callable[[Callable[..., Any]], Callable[..., Any]]])rS  r  rZ  rX  rp   rk   )rp   r  )r`   r   ra   r   rp   r  r  r  )rv   rw   rx   ry   r  r   r   r  r[  rc  ri  r>  r  r  r  rF  rz   ro   rI   rF   rk   rk     s=   . #  _c"'L L 	L
 L L L 'AL \L L L L L 
L:( EI(A	]$ EI(A	]!@ E&
P	;&2&9M&Wk&	&rI   rk   c                      \ rS rSrSS jrSrg)BaseRealtimeConnectionResourcei  c                    Xl         g rB   r   rE   r   s     rF   r   'BaseRealtimeConnectionResource.__init__      %rI   rK  N)r   r  rp   r   rv   rw   rx   ry   r   rz   ro   rI   rF   rI  rI        &rI   rI  c                  &    \ rS rSr\S.SS jjrSrg)r  i  event_idc               n    U R                   R                  [        [        [	        SXS.5      5      5        guW  
Send this event to update the session’s configuration.
The client may send this event at any time to update any field
except for `voice` and `model`. `voice` can be updated only if there have been no other audio outputs yet.

When the server receives a `session.update`, it will respond
with a `session.updated` event showing the full, effective configuration.
Only the fields that are present in the `session.update` are updated. To clear a field like
`instructions`, pass an empty string. To clear a field like `tools`, pass an empty array.
To clear a field like `turn_detection`, pass `null`.
zsession.update)rs  r   rS  Nr   r  r   r7   r   rE   r   rS  s      rF   updateRealtimeSessionResource.update  s1     	()9g de	
rI   ro   Nr   z"session_update_event_param.SessionrS  rq   rp   r   rv   rw   rx   ry   r   rX  rz   ro   rI   rF   r  r    s    \` 
 
rI   r  c                  <    \ rS rSr\\S.SS jjr\\S.S	S jjrSrg)
r  i  rS  r   c               n    U R                   R                  [        [        [	        SXS.5      5      5        ga7  
This event instructs the server to create a Response, which means triggering
model inference. When in Server VAD mode, the server will create Responses
automatically.

A Response will include at least one Item, and may have two, in which case
the second will be a function call. These Items will be appended to the
conversation history by default.

The server will respond with a `response.created` event, events for Items
and content created, and finally a `response.done` event to indicate the
Response is complete.

The `response.create` event includes inference configuration like
`instructions` and `tools`. If these are set, they will override the Session's
configuration for this Response only.

Responses can be created out-of-band of the default Conversation, meaning that they can
have arbitrary input, and it's possible to disable writing the output to the Conversation.
Only one Response can write to the default Conversation at a time, but otherwise multiple
Responses can be created in parallel. The `metadata` field is a good way to disambiguate
multiple simultaneous Responses.

Clients can set `conversation` to `none` to create a Response that does not write to the default
Conversation. Arbitrary input can be provided with the `input` field, which is an array accepting
raw Items and references to existing Items.
zresponse.create)rs  rS  r   NrV  rE   rS  r   s      rF   createRealtimeResponseResource.create  s1    8 	(): gh	
rI   rS  response_idc               n    U R                   R                  [        [        [	        SXS.5      5      5        gag  Send this event to cancel an in-progress response.

The server will respond
with a `response.done` event with a status of `response.status=cancelled`. If
there is no response to cancel, the server will respond with an error. It's safe
to call `response.cancel` even if no response is in progress, an error will be
returned the session will remain unaffected.
zresponse.cancel)rs  rS  rd  NrV  rE   rS  rd  s      rF   cancelRealtimeResponseResource.cancel  s1     	(): mn	
rI   ro   NrS  rq   r   z(RealtimeResponseCreateParamsParam | Omitrp   r   rS  rq   rd  rq   rp   r   rv   rw   rx   ry   r   ra  rh  rz   ro   rI   rF   r  r    s    /3jn !
F 04t 
 
rI   r  c                  J    \ rS rSr\S.SS jjr\S.SS jjr\S.S	S jjrSrg)
r  i  rR  c          
     n    U R                   R                  [        [        [	        SUS.5      5      5        gz}Send this event to clear the audio bytes in the buffer.

The server will
respond with an `input_audio_buffer.cleared` event.
zinput_audio_buffer.clearrs  rS  NrV  rE   rS  s     rF   clear&RealtimeInputAudioBufferResource.clear  s/     	)?D^lt;u+vw	
rI   c          
     n    U R                   R                  [        [        [	        SUS.5      5      5        ga(  
Send this event to commit the user input audio buffer, which will create a  new user message item in the conversation. This event will produce an error  if the input audio buffer is empty. When in Server VAD mode, the client does  not need to send this event, the server will commit the audio buffer  automatically.

Committing the input audio buffer will trigger input audio transcription  (if enabled in session configuration), but it will not create a response  from the model. The server will respond with an `input_audio_buffer.committed` event.
zinput_audio_buffer.commitrp  NrV  rq  s     rF   commit'RealtimeInputAudioBufferResource.commit  s/     	)?D_mu;v+wx	
rI   c               n    U R                   R                  [        [        [	        SXS.5      5      5        gaf  Send this event to append audio bytes to the input audio buffer.

The audio
buffer is temporary storage you can write to and later commit. A "commit" will create a new
user message item in the conversation history from the buffer content and clear the buffer.
Input audio transcription (if enabled) will be generated when the buffer is committed.

If VAD is enabled the audio buffer is used to detect speech and the server will decide
when to commit. When Server VAD is disabled, you must commit the audio buffer
manually. Input audio noise reduction operates on writes to the audio buffer.

The client may choose how much audio to place in each event up to a maximum
of 15 MiB, for example streaming smaller chunks from the client may allow the
VAD to be more responsive. Unlike most other client events, the server will
not send a confirmation response to this event.
zinput_audio_buffer.append)rs  audiorS  NrV  rE   rz  rS  s      rF   append'RealtimeInputAudioBufferResource.append  s1    " 	()Du kl	
rI   ro   NrS  rq   rp   r   rz  r  rS  rq   rp   r   	rv   rw   rx   ry   r   rr  rv  r|  rz   ro   rI   rF   r  r    s$    .2 
 04 
 <@ 
 
rI   r  c                  (    \ rS rSr\SS j5       rSrg)r  i5  c                ,    [        U R                  5      $ rB   ) RealtimeConversationItemResourcer   rD   s    rF   item!RealtimeConversationResource.item6  s    /0@0@AArI   ro   N)rp   r  rv   rw   rx   ry   r   r  rz   ro   rI   rF   r  r  5  s    B BrI   r  c                  l    \ rS rSr\S.S
S jjr\\S.       SS jjr\S.SS jjr\S.S
S jjrSr	g	)r  i;  rR  c               n    U R                   R                  [        [        [	        SXS.5      5      5        ga  Send this event when you want to remove any item from the conversation
history.

The server will respond with a `conversation.item.deleted` event,
unless the item does not exist in the conversation history, in which case the
server will respond with an error.
zconversation.item.deleters  item_idrS  NrV  rE   r  rS  s      rF   delete'RealtimeConversationItemResource.delete<  s2     	()CPW no	
rI   rS  previous_item_idc               r    U R                   R                  [        [        [	        SUUUS.5      5      5        ga  
Add a new Item to the Conversation's context, including messages, function
calls, and function call responses. This event can be used both to populate a
"history" of the conversation and to add new items mid-stream, but has the
current limitation that it cannot populate assistant audio messages.

If successful, the server will respond with a `conversation.item.created`
event, otherwise an `error` event will be sent.
zconversation.item.create)rs  r  rS  r  NrV  rE   r  rS  r  s       rF   ra  'RealtimeConversationItemResource.createK  s<     	( : $$,,<	
	
rI   c               t    U R                   R                  [        [        [	        SUUUUS.5      5      5        gu4  Send this event to truncate a previous assistant message’s audio.

The server
will produce audio faster than realtime, so this event is useful when the user
interrupts to truncate audio that has already been sent to the client but not
yet played. This will synchronize the server's understanding of the audio with
the client's playback.

Truncating audio will delete the server-side text transcript to ensure there
is not text in the context that hasn't been heard by the user.

If successful, the server will respond with a `conversation.item.truncated`
event.
zconversation.item.truncate)rs  audio_end_mscontent_indexr  rS  NrV  rE   r  r  r  rS  s        rF   truncate)RealtimeConversationItemResource.truncatee  s?     	( <(4)6#*$,	
rI   c               n    U R                   R                  [        [        [	        SXS.5      5      5        ga  
Send this event when you want to retrieve the server's representation of a specific item in the conversation history. This is useful, for example, to inspect user audio after noise cancellation and VAD.
The server will respond with a `conversation.item.retrieved` event,
unless the item does not exist in the conversation history, in which case the
server will respond with an error.
zconversation.item.retriever  NrV  r  s      rF   retrieve)RealtimeConversationItemResource.retrieve  s2     	()ERY pq	
rI   ro   Nr  r  rS  rq   rp   r   r  r6   rS  rq   r  rq   rp   r   
r  rs   r  rs   r  r  rS  rq   rp   r   
rv   rw   rx   ry   r   r  ra  r  r  rz   ro   rI   rF   r  r  ;  sV    =A 
  FJjn
,
8B
]g
	
4 gk 
< @D 
 
rI   r  c                  &    \ rS rSr\S.SS jjrSrg)r  i  rR  c          
     n    U R                   R                  [        [        [	        SUS.5      5      5        ga  **WebRTC/SIP Only:** Emit to cut off the current audio response.

This will trigger the server to
stop generating audio and emit a `output_audio_buffer.cleared` event. This
event should be preceded by a `response.cancel` client event to stop the
generation of the current response.
[Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).
zoutput_audio_buffer.clearrp  NrV  rq  s     rF   rr  'RealtimeOutputAudioBufferResource.clear  s/     	)?D_mu;v+wx	
rI   ro   Nr~  rv   rw   rx   ry   r   rr  rz   ro   rI   rF   r  r    s    .2 
 
rI   r  c                      \ rS rSrSS jrSrg)#BaseAsyncRealtimeConnectionResourcei  c                    Xl         g rB   rK  rL  s     rF   r   ,BaseAsyncRealtimeConnectionResource.__init__  rN  rI   rK  N)r   r   rp   r   rO  ro   rI   rF   r  r    rP  rI   r  c                  &    \ rS rSr\S.SS jjrSrg)r   i  rR  c                  #    U R                   R                  [        [        [	        SXS.5      5      5      I Sh  vN   g N7frU  rV  rW  s      rF   rX  #AsyncRealtimeSessionResource.update  s>      ##()9g de
 	
 	
   9AAAro   NrZ  r[  ro   rI   rF   r   r     s    bf 
 
rI   r   c                  F    \ rS rSr\\S.     SS jjr\\S.S	S jjrSrg)
r   i  r]  c                  #    U R                   R                  [        [        [	        SXS.5      5      5      I Sh  vN   g N7fr_  rV  r`  s      rF   ra  $AsyncRealtimeResponseResource.create  s>     < ##(): gh
 	
 	
r  rc  c                  #    U R                   R                  [        [        [	        SXS.5      5      5      I Sh  vN   g N7frf  rV  rg  s      rF   rh  $AsyncRealtimeResponseResource.cancel  s>      ##(): mn
 	
 	
r  ro   Nrj  rk  rl  ro   rI   rF   r   r     s8    (,cg#
%#
8`#
	#
J 6:UY 
 
rI   r   c                  J    \ rS rSr\S.SS jjr\S.SS jjr\S.S	S jjrSrg)
r   i  rR  c          
        #    U R                   R                  [        [        [	        SUS.5      5      5      I Sh  vN   g N7fro  rV  rq  s     rF   rr  +AsyncRealtimeInputAudioBufferResource.clear  s<      ##)?D^lt;u+vw
 	
 	
r  c          
        #    U R                   R                  [        [        [	        SUS.5      5      5      I Sh  vN   g N7fru  rV  rq  s     rF   rv  ,AsyncRealtimeInputAudioBufferResource.commit  s<      ##)?D_mu;v+wx
 	
 	
r  c                  #    U R                   R                  [        [        [	        SXS.5      5      5      I Sh  vN   g N7fry  rV  r{  s      rF   r|  ,AsyncRealtimeInputAudioBufferResource.append  s>     " ##()Du kl
 	
 	
r  ro   Nr~  r  r  ro   rI   rF   r   r     s%    48 
 6: 
 BF 
 
rI   r   c                  (    \ rS rSr\SS j5       rSrg)r   i   c                ,    [        U R                  5      $ rB   )%AsyncRealtimeConversationItemResourcer   rD   s    rF   r  &AsyncRealtimeConversationResource.item!  s    4T5E5EFFrI   ro   N)rp   r  r  ro   rI   rF   r   r      s    G GrI   r   c                  ~    \ rS rSr\S.S
S jjr\\S.       SS jjr\S.         SS jjr\S.S
S jjrSr	g	)r  i&  rR  c                  #    U R                   R                  [        [        [	        SXS.5      5      5      I Sh  vN   g N7fr  rV  r  s      rF   r  ,AsyncRealtimeConversationItemResource.delete'  s?      ##()CPW no
 	
 	
r  r  c                  #    U R                   R                  [        [        [	        SUUUS.5      5      5      I Sh  vN   g N7fr  rV  r  s       rF   ra  ,AsyncRealtimeConversationItemResource.create6  sI      ##( : $$,,<	

 	
 	
s   ;AAAc                  #    U R                   R                  [        [        [	        SUUUUS.5      5      5      I Sh  vN   g N7fr  rV  r  s        rF   r  .AsyncRealtimeConversationItemResource.truncateP  sL     " ##( <(4)6#*$,
 	
 	
s   <AAAc                  #    U R                   R                  [        [        [	        SXS.5      5      5      I Sh  vN   g N7fr  rV  r  s      rF   r  .AsyncRealtimeConversationItemResource.retrievep  s?      ##()ERY pq
 	
 	
r  ro   Nr  r  r  r  ro   rI   rF   r  r  &  s    CG 
  FJjn
,
8B
]g
	
6 ^b
"
36
AD
PZ
	
@ FJ 
 
rI   r  c                  &    \ rS rSr\S.SS jjrSrg)r   i  rR  c          
        #    U R                   R                  [        [        [	        SUS.5      5      5      I Sh  vN   g N7fr  rV  rq  s     rF   rr  ,AsyncRealtimeOutputAudioBufferResource.clear  s<      ##)?D_mu;v+wx
 	
 	
r  ro   Nr~  r  ro   rI   rF   r   r     s    48 
 
rI   r   )w
__future__r   r   r  r7  loggingtypesr   typingr   r   r   r   r	   r
   r   typing_extensionsr   r  pydanticr   rM   r   r   r   r   r   r   _typesr   r   r   r   _utilsr   r   r   r   r   _compatr   _modelsr    	_resourcer!   r"   _exceptionsr#   r$   r   r%   _base_clientr&   rG   r'   r(   r)   r*   r+   r,   _event_handlerr-   types.realtimer.   types.websocket_reconnectionr/   r0   r1   "types.websocket_connection_optionsr2   #types.realtime.realtime_error_eventr3   $types.realtime.realtime_client_eventr4   $types.realtime.realtime_server_eventr5   &types.realtime.conversation_item_paramr6   *types.realtime.realtime_client_event_paramr7   4types.realtime.realtime_response_create_params_paramr8   rA  r9   r  r  r   rC   r:   r;   __all__	getLoggerrv   r>   r  r<   r=   rQ   r   rV   r   r   r   r  rk   rI  r  r  r  r  r  r  r  r   r   r   r   r  r   ro   rI   rF   <module>r     s   #      Q Q Q +    1 0  ' / : F $ +  3 8 j j L E G G K R eNV.
'''1^ 1C
 C
LC
$ C
L
: 
:
? 
?
@ 
@
E 
E^! ^!B	|, |,~R Rj|& |&~& &

< 
*2
= 2
j+
'E +
\B#A BT
'E T
n
(F 
& &

#F 
*4
$G 4
n+
,O +
\G(K GV
,O V
r
-P 
rI   