
    gj                    x   U d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlZd dlmZ ddlmZmZmZmZmZmZ d	d
lmZmZmZmZ d	dlmZmZmZm Z m!Z! d	dl"m#Z# d	dl$m%Z% d	dl&m'Z'm(Z( d	dl)m*Z* d	dl+m,Z, d	dl-m.Z.m/Z/ d	dl0m1Z1 d	dl2m3Z3 d	dl4m5Z5 d	dl6m7Z7 d	dl8m9Z9 erd dl:m;Z< d dl=m;Z> d	dl?m@Z@mAZA ddgZB ej                  eD      ZEdeFd<    G d de'      ZG G d de(      ZH G d d       ZI G d! d"      ZJ G d# d$      ZK G d% d&      ZL G d' d(      ZM G d) d*      ZN G d+ d,      ZO G d- d.      ZP G d/ d0      ZQ G d1 d2eQ      ZR G d3 d4eQ      ZS G d5 d6eQ      ZT G d7 d8eQ      ZU G d9 d:eQ      ZV G d; d<      ZW G d= d>eW      ZX G d? d@eW      ZY G dA dBeW      ZZ G dC dDeW      Z[ G dE dFeW      Z\y)G    )annotationsN)TracebackType)TYPE_CHECKINGAnyIteratorcast)AsyncIterator)	BaseModel   )SessionsAsyncSessionsSessionsWithRawResponseAsyncSessionsWithRawResponseSessionsWithStreamingResponse"AsyncSessionsWithStreamingResponse   )	NOT_GIVENQueryHeadersNotGiven)is_azure_clientmaybe_transformstrip_not_givenasync_maybe_transformis_async_azure_client)cached_property)construct_type_unchecked)SyncAPIResourceAsyncAPIResource)OpenAIError)_merge_mappings)session_update_event_paramresponse_create_event_param)WebsocketConnectionOptions)RealtimeClientEvent)RealtimeServerEvent)ConversationItemParam)RealtimeClientEventParam)ClientConnection)OpenAIAsyncOpenAIRealtimeAsyncRealtimezlogging.Loggerlogc                  f    e Zd Zedd       Zedd       Zed	d       Zi i i d	 	 	 	 	 	 	 	 	 d
dZy)r,   c                ,    t        | j                        S N)r   _clientselfs    \/var/www/openai/venv/lib/python3.12/site-packages/openai/resources/beta/realtime/realtime.pysessionszRealtime.sessions6   s    %%    c                    t        |       S a  
        This property can be used as a prefix for any HTTP method call to return the
        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
        )RealtimeWithRawResponser3   s    r5   with_raw_responsezRealtime.with_raw_response:   s     't,,r7   c                    t        |       S 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
        )RealtimeWithStreamingResponser3   s    r5   with_streaming_responsez Realtime.with_streaming_responseD   s     -T22r7   extra_queryextra_headerswebsocket_connection_optionsc               6    t        | j                  ||||      S 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.
        )clientrA   rB   rC   model)RealtimeConnectionManagerr2   r4   rG   rA   rB   rC   s        r5   connectzRealtime.connectM   s$    & )<<#')E
 	
r7   N)returnr   )rK   r:   )rK   r>   )
rG   strrA   r   rB   r   rC   r$   rK   rH   __name__
__module____qualname__r   r6   r;   r?   rJ    r7   r5   r,   r,   5   s    & & - - 3 3  !#CE
 
 	

 
 'A
 
#
r7   c                  f    e Zd Zedd       Zedd       Zed	d       Zi i i d	 	 	 	 	 	 	 	 	 d
dZy)r-   c                ,    t        | j                        S r1   )r   r2   r3   s    r5   r6   zAsyncRealtime.sessionsj   s    T\\**r7   c                    t        |       S r9   )AsyncRealtimeWithRawResponser3   s    r5   r;   zAsyncRealtime.with_raw_responsen   s     ,D11r7   c                    t        |       S r=   )"AsyncRealtimeWithStreamingResponser3   s    r5   r?   z%AsyncRealtime.with_streaming_responsex   s     2$77r7   r@   c               6    t        | j                  ||||      S rE   )AsyncRealtimeConnectionManagerr2   rI   s        r5   rJ   zAsyncRealtime.connect   s$    & .<<#')E
 	
r7   N)rK   r   )rK   rU   )rK   rW   )
rG   rL   rA   r   rB   r   rC   r$   rK   rY   rM   rQ   r7   r5   r-   r-   i   s    + + 2 2 8 8  !#CE
 
 	

 
 'A
 
(
r7   c                  &    e Zd ZddZedd       Zy)r:   c                    || _         y r1   	_realtimer4   realtimes     r5   __init__z RealtimeWithRawResponse.__init__   	    !r7   c                @    t        | j                  j                        S r1   )r   r]   r6   r3   s    r5   r6   z RealtimeWithRawResponse.sessions   s    &t~~'>'>??r7   Nr_   r,   rK   None)rK   r   rN   rO   rP   r`   r   r6   rQ   r7   r5   r:   r:      s    " @ @r7   r:   c                  &    e Zd ZddZedd       Zy)rU   c                    || _         y r1   r\   r^   s     r5   r`   z%AsyncRealtimeWithRawResponse.__init__   ra   r7   c                @    t        | j                  j                        S r1   )r   r]   r6   r3   s    r5   r6   z%AsyncRealtimeWithRawResponse.sessions   s    +DNN,C,CDDr7   Nr_   r-   rK   rd   )rK   r   re   rQ   r7   r5   rU   rU      s    " E Er7   rU   c                  &    e Zd ZddZedd       Zy)r>   c                    || _         y r1   r\   r^   s     r5   r`   z&RealtimeWithStreamingResponse.__init__   ra   r7   c                @    t        | j                  j                        S r1   )r   r]   r6   r3   s    r5   r6   z&RealtimeWithStreamingResponse.sessions   s    ,T^^-D-DEEr7   Nrc   )rK   r   re   rQ   r7   r5   r>   r>      s    " F Fr7   r>   c                  &    e Zd ZddZedd       Zy)rW   c                    || _         y r1   r\   r^   s     r5   r`   z+AsyncRealtimeWithStreamingResponse.__init__   ra   r7   c                @    t        | j                  j                        S r1   )r   r]   r6   r3   s    r5   r6   z+AsyncRealtimeWithStreamingResponse.sessions   s    1$..2I2IJJr7   Nri   )rK   r   re   rQ   r7   r5   rW   rW      s    " K Kr7   rW   c                      e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ddZddZddZddZddZ	dddddZ
ddZy)AsyncRealtimeConnection:Represents a live websocket connection to the Realtime APIAsyncRealtimeSessionResourcesessionAsyncRealtimeResponseResourceresponse!AsyncRealtimeConversationResourceconversation%AsyncRealtimeInputAudioBufferResourceinput_audio_bufferAsyncWebsocketConnection_connectionc                    || _         t        |       | _        t        |       | _        t        |       | _        t        |       | _        y r1   )	r|   rs   rt   ru   rv   rw   rx   ry   rz   r4   
connections     r5   r`   z AsyncRealtimeConnection.__init__   s<    %3D95d;=dC"G"Mr7   c               l   K   ddl m} 	 	 | j                          d{    7 # |$ r Y yw xY wwzq
        An infinite-iterator that will continue to yield events until
        the connection is closed.
        r   )ConnectionClosedOKNwebsockets.exceptionsr   recvr4   r   s     r5   	__aiter__z!AsyncRealtimeConnection.__aiter__   s;     
 	=	 IIK'' '! 		s    4) '	) 1414c                \   K   | j                  | j                          d{         S 7 w)
        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_bytesr3   s    r5   r   zAsyncRealtimeConnection.recv   s&      doo&7 788 7s   ,*	,c                   K   | j                   j                  d       d{   }t        j                  d|       t	        |t
              st        dt        |             |S 7 Cw)  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: %s9Expected `.recv(decode=False)` to return `bytes` but got r|   r   r.   debug
isinstancebytes	TypeErrortyper4   messages     r5   r   z"AsyncRealtimeConnection.recv_bytes   sb      ((--U-;;		2W='5)WX\]dXeWfghh <s    A(A&AA(c                   K   t        |t              r|j                  ddd      n*t        j                  t        |t               d {         }| j                  j                  |       d {    y 7 ,7 wNT)use_api_namesexclude_defaultsexclude_unset)	r   r
   to_jsonjsondumpsr   r(   r|   sendr4   eventdatas      r5   r   zAsyncRealtimeConnection.send   sj      %+ MMtSWMX"7?W"XXY 	
 ##D))) Y)s$   AA:	A6
&A:0A81A:8A:   codereasonc               Z   K   | j                   j                  ||       d {    y 7 wNr   r|   closer4   r   r   s      r5   r   zAsyncRealtimeConnection.close   s%     $$$v$>>>s   !+)+c           
         t        t        t        t        j                  |      t        t
        t                          S z
        Converts a raw `str` or `bytes` message into a `RealtimeServerEvent` object.

        This is helpful if you're using `.recv_bytes()`.
        )valuetype_r   r&   r   r   loadsr   r4   r   s     r5   r   z#AsyncRealtimeConnection.parse_event  1     !9

4@PX\]`buXv!w
 	
r7   N)r   r{   rK   rd   )rK   z"AsyncIterator[RealtimeServerEvent]rK   r&   rK   r   r   z.RealtimeClientEvent | RealtimeClientEventParamrK   rd   r   intr   rL   rK   rd   r   zstr | bytesrK   r&   )rN   rO   rP   __doc____annotations__r`   r   r   r   r   r   r   rQ   r7   r5   rq   rq      sN    D))++33==))N9 * *.R ?
r7   rq   c                  \    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 ddZddZeZd	dZ	 	 	 	 	 	 	 	 d
dZy)rY   a3  
    Context manager over a `AsyncRealtimeConnection` that is returned by `beta.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.beta.realtime.connect(...).enter()
    # ...
    await connection.close()
    ```
    c               X    || _         || _        d | _        || _        || _        || _        y r1   )'_AsyncRealtimeConnectionManager__client&_AsyncRealtimeConnectionManager__model+_AsyncRealtimeConnectionManager__connection,_AsyncRealtimeConnectionManager__extra_query._AsyncRealtimeConnectionManager__extra_headers=_AsyncRealtimeConnectionManager__websocket_connection_optionsr4   rF   rG   rA   rB   rC   s         r5   r`   z'AsyncRealtimeConnectionManager.__init__"  s2     <@(,.J+r7   c                .  K   	 ddl m} | j                  }| j
                  j                  }t        | j
                        r1| j
                  j                  | j                  |       d{   \  }}| j                         j                  i | j
                  j                  j                  d| j                  i|      }t        j                  d|       | j                   r t        j                  d| j                          t#         |t%        |      f| j
                  j&                  t)        i |d	d
i| j*                        d| j                    d{         | _        | j,                  S # t        $ r}t        d      |d}~ww xY w7 &7 9w)u  
        👋 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.beta.realtime.connect(...).enter()
        # ...
        await connection.close()
        ```
        r   rJ   9You need to install `openai[realtime]` to use this methodNrG   paramsConnecting to %sConnection options: %sOpenAI-Betarealtime=v1user_agent_headeradditional_headers)websockets.asyncio.clientrJ   ImportErrorr    r   r   auth_headersr   _configure_realtimer   _prepare_url	copy_withbase_urlr   r.   r   r   rq   rL   
user_agentr!   r   r   r4   rJ   excrA   r   urls         r5   
__aenter__z)AsyncRealtimeConnectionManager.__aenter__2  s    	d9 ((}}11 /.2mm.O.OPTP\P\^i.j(j%K!++--((//  , 
 			$c*..II.0S0ST3C"&--":":#2&%} (($ 55 
    E  	dYZ`cc	d )ksG   FE3 A F*F+C.FFF3	F<FFFFc                .   | j                   j                  *t        j                  | j                   j                        }n&| j                   j                  j                  d      }|j                  j                  d      dz   }|j                  |      S Nwss)scheme   /s	   /realtime)raw_path)r   websocket_base_urlhttpxURL	_base_urlr   r   rstripr4   r   merge_raw_paths      r5   r   z+AsyncRealtimeConnectionManager._prepare_urlg  v    ==++7yy!A!ABH}}..888FH!**11$7,F!!>!::r7   c                n   K   | j                   #| j                   j                          d {    y y 7 wr1   )r   r   r4   exc_typer   exc_tbs       r5   	__aexit__z(AsyncRealtimeConnectionManager.__aexit__p  s4      (##))+++ )+s   *535N)rF   r+   rG   rL   rA   r   rB   r   rC   r$   rK   rd   )rK   rq   rK   z	httpx.URLr   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | NonerK   rd   )	rN   rO   rP   r   r`   r   enterr   r   rQ   r7   r5   rY   rY     s    &K K 	K
 K K 'AK 
K 1!f E;,2,9M,Wk,	,r7   rY   c                      e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ddZddZddZddZddZ	dddddZ
ddZy)RealtimeConnectionrr   RealtimeSessionResourcert   RealtimeResponseResourcerv   RealtimeConversationResourcerx    RealtimeInputAudioBufferResourcerz   WebsocketConnectionr|   c                    || _         t        |       | _        t        |       | _        t        |       | _        t        |       | _        y r1   )	r|   r   rt   r   rv   r   rx   r   rz   r~   s     r5   r`   zRealtimeConnection.__init__  s<    %.t4068>"B4"Hr7   c              #  V   K   ddl m} 	 	 | j                          # |$ r Y yw xY wwr   r   r   s     r5   __iter__zRealtimeConnection.__iter__  s5     
 	=	iik! ! 		s   ) &)&)c                @    | j                  | j                               S )r   r   r3   s    r5   r   zRealtimeConnection.recv  s      122r7   c                    | j                   j                  d      }t        j                  d|       t	        |t
              st        dt        |             |S )r   Fr   r   r   r   r   s     r5   r   zRealtimeConnection.recv_bytes  sV     ""''u'5		2W='5)WX\]dXeWfghhr7   c                    t        |t              r|j                  ddd      n"t        j                  t        |t                    }| j                  j                  |       y r   )	r   r
   r   r   r   r   r(   r|   r   r   s      r5   r   zRealtimeConnection.send  sR     %+ MMtSWMXOE3KLM 	
 	d#r7   r   r   r   c               >    | j                   j                  ||       y r   r   r   s      r5   r   zRealtimeConnection.close  s    D8r7   c           
         t        t        t        t        j                  |      t        t
        t                          S r   r   r   s     r5   r   zRealtimeConnection.parse_event  r   r7   N)r   r   rK   rd   )rK   zIterator[RealtimeServerEvent]r   r   r   r   r   )rN   rO   rP   r   r   r`   r  r   r   r   r   r   rQ   r7   r5   r   r   w  sN    D$$&&..88$$I3 $ $(r 9
r7   r   c                  \    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 ddZddZeZd	dZ	 	 	 	 	 	 	 	 d
dZy)rH   a"  
    Context manager over a `RealtimeConnection` that is returned by `beta.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.beta.realtime.connect(...).enter()
    # ...
    connection.close()
    ```
    c               X    || _         || _        d | _        || _        || _        || _        y r1   )"_RealtimeConnectionManager__client!_RealtimeConnectionManager__model&_RealtimeConnectionManager__connection'_RealtimeConnectionManager__extra_query)_RealtimeConnectionManager__extra_headers8_RealtimeConnectionManager__websocket_connection_optionsr   s         r5   r`   z"RealtimeConnectionManager.__init__  s2     7;(,.J+r7   c                   	 ddl m} | j                  }| j
                  j                  }t        | j
                        r)| j
                  j                  | j                  |      \  }}| j                         j                  i | j
                  j                  j                  d| j                  i|      }t        j                  d|       | j                   r t        j                  d| j                          t#         |t%        |      f| j
                  j&                  t)        i |d	d
i| j*                        d| j                         | _        | j,                  S # t        $ r}t        d      |d}~ww xY w)u{  
        👋 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.beta.realtime.connect(...).enter()
        # ...
        connection.close()
        ```
        r   r   r   NrG   r   r   r   r   r   r   )websockets.sync.clientrJ   r   r    r  r	  r   r   r   r
  r   r   r   r   r.   r   r  r   rL   r   r!   r  r  r   s         r5   	__enter__z#RealtimeConnectionManager.__enter__  so   	d6 ((}}114==)(,(I(I$,,Xc(d%K!++--((//  , 
 			$c*..II.0S0ST.C"&--":":#2&%} (($ 55
    E  	dYZ`cc	ds   E! !	E;*E66E;c                .   | j                   j                  *t        j                  | j                   j                        }n&| j                   j                  j                  d      }|j                  j                  d      dz   }|j                  |      S r   )r	  r   r   r   r   r   r   r   r   s      r5   r   z&RealtimeConnectionManager._prepare_url  r   r7   c                R    | j                   | j                   j                          y y r1   )r  r   r   s       r5   __exit__z"RealtimeConnectionManager.__exit__&  s'     (##% )r7   N)rF   r*   rG   rL   rA   r   rB   r   rC   r$   rK   rd   )rK   r   r   r   )	rN   rO   rP   r   r`   r  r   r   r  rQ   r7   r5   rH   rH     s    &K K 	K
 K K 'AK 
K 1!f E;&2&9M&Wk&	&r7   rH   c                      e Zd ZddZy)BaseRealtimeConnectionResourcec                    || _         y r1   r|   r~   s     r5   r`   z'BaseRealtimeConnectionResource.__init__.  
    %r7   N)r   r   rK   rd   rN   rO   rP   r`   rQ   r7   r5   r  r  -      &r7   r  c                      e Zd ZedddZy)r   event_idc               p    | j                   j                  t        t        t	        d||d                   yu  Send this event to update the session’s default configuration.

        The client may
        send this event at any time to update the session configuration, and any
        field may be updated at any time, except for "voice". The server will respond
        with a `session.updated` event that shows the full effective configuration.
        Only fields that are present are updated, thus the correct way to clear a
        field like "instructions" is to pass an empty string.
        zsession.update)r   rt   r  Nr|   r   r   r(   r   r4   rt   r  s      r5   updatezRealtimeSessionResource.update3  s4     	()9g[c de	
r7   Nrt   z"session_update_event_param.Sessionr  str | NotGivenrK   rd   rN   rO   rP   r   r#  rQ   r7   r5   r   r   2  s
    `i 
r7   r   c                  6    e Zd ZeedddZeed	 	 	 	 	 ddZy)r   r  response_idc               p    | j                   j                  t        t        t	        d||d                   yzSend this event to cancel an in-progress response.

        The server will respond
        with a `response.cancelled` event or an error if there is no response to
        cancel.
        zresponse.cancel)r   r  r)  Nr!  r4   r  r)  s      r5   cancelzRealtimeResponseResource.cancelF  s4     	():al mn	
r7   r  rv   c               p    | j                   j                  t        t        t	        d||d                   ya  
        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.

        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 `temperature`. These fields will override the Session's
        configuration for this Response only.
        zresponse.create)r   r  rv   Nr!  r4   r  rv   s      r5   createzRealtimeResponseResource.createT  s4    . 	():^f gh	
r7   Nr  r%  r)  r%  rK   rd   r  r%  rv   z/response_create_event_param.Response | NotGivenrK   rd   rN   rO   rP   r   r-  r2  rQ   r7   r5   r   r   E  s9    3<\e 
" $-DM	
 !
 B	

 

r7   r   c                      e Zd Zedd       Zy)r   c                ,    t        | j                        S r1   ) RealtimeConversationItemResourcer|   r3   s    r5   itemz!RealtimeConversationResource.itemt  s    /0@0@AAr7   N)rK   r8  rN   rO   rP   r   r9  rQ   r7   r5   r   r   s  s    B Br7   r   c                  X    e Zd ZedddZeed	 	 	 	 	 	 	 ddZed	 	 	 	 	 	 	 	 	 d	dZy)
r8  r  c               p    | j                   j                  t        t        t	        d||d                   y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)r   item_idr  Nr!  r4   r>  r  s      r5   deletez'RealtimeConversationItemResource.deletez  s5     	()CPWem no	
r7   r  previous_item_idc               r    | j                   j                  t        t        t	        d|||d                   y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)r   r9  r  rB  Nr!  r4   r9  r  rB  s       r5   r2  z'RealtimeConversationItemResource.create  s<      	( : $$,,<	
	
r7   c               t    | j                   j                  t        t        t	        d||||d                   yu  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)r   audio_end_mscontent_indexr>  r  Nr!  r4   rH  rI  r>  r  s        r5   truncatez)RealtimeConversationItemResource.truncate  s?    " 	( <(4)6#*$,	
r7   Nr>  rL   r  r%  rK   rd   r9  r'   r  r%  rB  r%  rK   rd   
rH  r   rI  r   r>  rL   r  r%  rK   rd   rN   rO   rP   r   r@  r2  rK  rQ   r7   r5   r8  r8  y  ss    AJ 
& $-+4
 $
 !	

 )
 

> bk
"
36
AD
P^
	
r7   r8  c                  6    e Zd ZedddZedddZedddZy)r   r  c          
     n    | j                   j                  t        t        t	        d|d                   yzSend 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r   r  Nr!  r4   r  s     r5   clearz&RealtimeInputAudioBufferResource.clear  s/     	)?D^lt;u+vw	
r7   c          
     n    | j                   j                  t        t        t	        d|d                   yar  
        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.commitrS  Nr!  rT  s     r5   commitz'RealtimeInputAudioBufferResource.commit  s/     	)?D_mu;v+wx	
r7   c               p    | j                   j                  t        t        t	        d||d                   ya  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. In Server VAD
        mode, 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.

        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 made other client events, the server will
        not send a confirmation response to this event.
        zinput_audio_buffer.append)r   audior  Nr!  r4   r[  r  s      r5   appendz'RealtimeInputAudioBufferResource.append  s4     	()Dubj kl	
r7   Nr  r%  rK   rd   r[  rL   r  r%  rK   rd   rN   rO   rP   r   rU  rX  r]  rQ   r7   r5   r   r     s     2; 
 4= 
" @I 
r7   r   c                      e Zd ZddZy)#BaseAsyncRealtimeConnectionResourcec                    || _         y r1   r  r~   s     r5   r`   z,BaseAsyncRealtimeConnectionResource.__init__  r  r7   N)r   rq   rK   rd   r  rQ   r7   r5   rb  rb    r  r7   rb  c                  $    e Zd Zed	 	 	 	 	 ddZy)rs   r  c                  K   | j                   j                  t        t        t	        d||d                   d{    y7 wr   r!  r"  s      r5   r#  z#AsyncRealtimeSessionResource.update   sB      ##()9g[c de
 	
 	
   :AAANr$  r&  rQ   r7   r5   rs   rs     s"    Yb
<
HV
	
r7   rs   c                  6    e Zd ZeedddZeed	 	 	 	 	 ddZy)ru   r(  c                  K   | j                   j                  t        t        t	        d||d                   d{    y7 wr+  r!  r,  s      r5   r-  z$AsyncRealtimeResponseResource.cancel  sB      ##():al mn
 	
 	
rf  r.  c                  K   | j                   j                  t        t        t	        d||d                   d{    y7 wr0  r!  r1  s      r5   r2  z$AsyncRealtimeResponseResource.create#  sB     . ##():^f gh
 	
 	
rf  Nr3  r4  r5  rQ   r7   r5   ru   ru     s9    9Bbk 
" $-DM	
 !
 B	

 

r7   ru   c                      e Zd Zedd       Zy)rw   c                ,    t        | j                        S r1   )%AsyncRealtimeConversationItemResourcer|   r3   s    r5   r9  z&AsyncRealtimeConversationResource.itemC  s    4T5E5EFFr7   N)rK   rl  r:  rQ   r7   r5   rw   rw   B  s    G Gr7   rw   c                  X    e Zd ZedddZeed	 	 	 	 	 	 	 ddZed	 	 	 	 	 	 	 	 	 d	dZy)
rl  r  c                  K   | j                   j                  t        t        t	        d||d                   d{    y7 wr=  r!  r?  s      r5   r@  z,AsyncRealtimeConversationItemResource.deleteI  sC      ##()CPWem no
 	
 	
rf  rA  c                  K   | j                   j                  t        t        t	        d|||d                   d{    y7 wrD  r!  rE  s       r5   r2  z,AsyncRealtimeConversationItemResource.createX  sJ       ##( : $$,,<	

 	
 	
s   ;AAAc                  K   | j                   j                  t        t        t	        d||||d                   d{    y7 wrG  r!  rJ  s        r5   rK  z.AsyncRealtimeConversationItemResource.truncatev  sM     " ##( <(4)6#*$,
 	
 	
s   <AAANrL  rM  rN  rO  rQ   r7   r5   rl  rl  H  ss    GP 
& $-+4
 $
 !	

 )
 

> bk
"
36
AD
P^
	
r7   rl  c                  6    e Zd ZedddZedddZedddZy)ry   r  c          
        K   | j                   j                  t        t        t	        d|d                   d{    y7 wrR  r!  rT  s     r5   rU  z+AsyncRealtimeInputAudioBufferResource.clear  s=      ##)?D^lt;u+vw
 	
 	
   9AAAc          
        K   | j                   j                  t        t        t	        d|d                   d{    y7 wrW  r!  rT  s     r5   rX  z,AsyncRealtimeInputAudioBufferResource.commit  s=      ##)?D_mu;v+wx
 	
 	
rs  c                  K   | j                   j                  t        t        t	        d||d                   d{    y7 wrZ  r!  r\  s      r5   r]  z,AsyncRealtimeInputAudioBufferResource.append  sB      ##()Dubj kl
 	
 	
rf  Nr^  r_  r`  rQ   r7   r5   ry   ry     s!    8A 
 :C 
" FO 
r7   ry   )]
__future__r   r   loggingtypesr   typingr   r   r   r   typing_extensionsr	   r   pydanticr
   r6   r   r   r   r   r   r   _typesr   r   r   r   _utilsr   r   r   r   r   _compatr   _modelsr   	_resourcer   r   _exceptionsr    _base_clientr!   types.beta.realtimer"   r#   "types.websocket_connection_optionsr$   )types.beta.realtime.realtime_client_eventr%   )types.beta.realtime.realtime_server_eventr&   +types.beta.realtime.conversation_item_paramr'   /types.beta.realtime.realtime_client_event_paramr(   r  r)   r   r   r{   r2   r*   r+   __all__	getLoggerrN   r.   r   r,   r-   r:   rU   r>   rW   rq   rY   r   rH   r  r   r   r   r8  r   rb  rs   ru   rw   rl  ry   rQ   r7   r5   <module>r     s   #    5 5 +    ; :  ( 0 ; ' , [ M M M Q XNV/
''g''1^ 11
 1
h1
$ 1
h@ @E EF FK KJ
 J
Zf, f,RJ
 J
Zf& f&R& &

< 
&+
= +
\B#A BL
'E L
^/
'E /
d& &

#F 
*+
$G +
\G(K GL
,O L
^/
,O /
r7   