
    	h                    :   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 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(m)Z)m*Z*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: erd dl;m<Z= d dl>m<Z? ddl@mAZAmBZB ddgZC ejD        eE          ZFdeGd<    G d de           ZH G d de!          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. d/          ZQ G d0 d1          ZR G d2 d3eR          ZS G d4 d5eR          ZT G d6 d7eR          ZU G d8 d9eR          ZV G d: d;eR          ZW G d< d=eR          ZX G d> d?          ZY G d@ dAeY          ZZ G dB dCeY          Z[ G dD dEeY          Z\ G dF dGeY          Z] G dH dIeY          Z^ G dJ dKeY          Z_dS )L    )annotationsN)TracebackType)TYPE_CHECKINGAnyIteratorcast)AsyncIterator)	BaseModel   )	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   )ClientSecretsAsyncClientSecretsClientSecretsWithRawResponse!AsyncClientSecretsWithRawResponse"ClientSecretsWithStreamingResponse'AsyncClientSecretsWithStreamingResponse)session_update_event_param)WebsocketConnectionOptions)RealtimeClientEvent)RealtimeServerEvent)ConversationItemParam)RealtimeClientEventParam)!RealtimeResponseCreateParamsParam)ClientConnection)OpenAIAsyncOpenAIRealtimeAsyncRealtimezlogging.Loggerlogc                  h    e Zd Zedd            Zedd            Zedd            Zi i i dddZdS )r,   returnr   c                *    t          | j                  S N)r   _clientselfs    o/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/openai/resources/realtime/realtime.pyclient_secretszRealtime.client_secrets7   s    T\***    RealtimeWithRawResponsec                     t          |           S a  
        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
        )r9   r4   s    r6   with_raw_responsezRealtime.with_raw_response;   s     't,,,r8   RealtimeWithStreamingResponsec                     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
        )r=   r4   s    r6   with_streaming_responsez Realtime.with_streaming_responseE   s     -T222r8   extra_queryextra_headerswebsocket_connection_optionsmodelstrrB   r   rC   r   rD   r#   RealtimeConnectionManagerc               4    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.
        )clientrB   rC   rD   rE   )rG   r3   r5   rE   rB   rC   rD   s        r6   connectzRealtime.connectN   s,    & )<#')E
 
 
 	
r8   N)r0   r   )r0   r9   )r0   r=   )
rE   rF   rB   r   rC   r   rD   r#   r0   rG   __name__
__module____qualname__r   r7   r<   r@   rL    r8   r6   r,   r,   6   s        + + + _+ - - - _- 3 3 3 _3  !#CE
 
 
 
 
 
 
 
r8   c                  h    e Zd Zedd            Zedd            Zedd            Zi i i dddZdS )r-   r0   r   c                *    t          | j                  S r2   )r   r3   r4   s    r6   r7   zAsyncRealtime.client_secretsk   s    !$,///r8   AsyncRealtimeWithRawResponsec                     t          |           S r;   )rT   r4   s    r6   r<   zAsyncRealtime.with_raw_responseo   s     ,D111r8   "AsyncRealtimeWithStreamingResponsec                     t          |           S r?   )rV   r4   s    r6   r@   z%AsyncRealtime.with_streaming_responsey   s     2$777r8   rA   rE   rF   rB   r   rC   r   rD   r#   AsyncRealtimeConnectionManagerc               4    t          | j        ||||          S rI   )rX   r3   rK   s        r6   rL   zAsyncRealtime.connect   s,    & .<#')E
 
 
 	
r8   N)r0   r   )r0   rT   )r0   rV   )
rE   rF   rB   r   rC   r   rD   r#   r0   rX   rM   rQ   r8   r6   r-   r-   j   s        0 0 0 _0 2 2 2 _2 8 8 8 _8  !#CE
 
 
 
 
 
 
 
r8   c                  .    e Zd Zd	dZed
d            ZdS )r9   realtimer,   r0   Nonec                    || _         d S r2   	_realtimer5   r[   s     r6   __init__z RealtimeWithRawResponse.__init__       !r8   r   c                4    t          | j        j                  S r2   )r   r_   r7   r4   s    r6   r7   z&RealtimeWithRawResponse.client_secrets   s    +DN,IJJJr8   Nr[   r,   r0   r\   )r0   r   rN   rO   rP   ra   r   r7   rQ   r8   r6   r9   r9      sN        " " " " K K K _K K Kr8   r9   c                  .    e Zd Zd	dZed
d            ZdS )rT   r[   r-   r0   r\   c                    || _         d S r2   r^   r`   s     r6   ra   z%AsyncRealtimeWithRawResponse.__init__   rb   r8   r   c                4    t          | j        j                  S r2   )r   r_   r7   r4   s    r6   r7   z+AsyncRealtimeWithRawResponse.client_secrets   s    01NOOOr8   Nr[   r-   r0   r\   )r0   r   re   rQ   r8   r6   rT   rT      sN        " " " " P P P _P P Pr8   rT   c                  .    e Zd Zd	dZed
d            ZdS )r=   r[   r,   r0   r\   c                    || _         d S r2   r^   r`   s     r6   ra   z&RealtimeWithStreamingResponse.__init__   rb   r8   r    c                4    t          | j        j                  S r2   )r    r_   r7   r4   s    r6   r7   z,RealtimeWithStreamingResponse.client_secrets   s    1$.2OPPPr8   Nrd   )r0   r    re   rQ   r8   r6   r=   r=      sN        " " " " Q Q Q _Q Q Qr8   r=   c                  .    e Zd Zd	dZed
d            ZdS )rV   r[   r-   r0   r\   c                    || _         d S r2   r^   r`   s     r6   ra   z+AsyncRealtimeWithStreamingResponse.__init__   rb   r8   r!   c                4    t          | j        j                  S r2   )r!   r_   r7   r4   s    r6   r7   z1AsyncRealtimeWithStreamingResponse.client_secrets   s    6t~7TUUUr8   Nri   )r0   r!   re   rQ   r8   r6   rV   rV      sN        " " " " V V V _V V Vr8   rV   c                      e Zd ZU dZded<   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d&S ).AsyncRealtimeConnection:Represents a live websocket connection to the Realtime APIAsyncRealtimeSessionResourcesessionAsyncRealtimeResponseResourceresponse%AsyncRealtimeInputAudioBufferResourceinput_audio_buffer!AsyncRealtimeConversationResourceconversation&AsyncRealtimeOutputAudioBufferResourceoutput_audio_bufferAsyncWebsocketConnection_connection
connectionr0   r\   c                    || _         t          |           | _        t          |           | _        t          |           | _        t          |           | _        t          |           | _
        d S r2   )r~   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r5   r   s     r6   ra   z AsyncRealtimeConnection.__init__   s^    %3D995d;;"G"M"M=dCC#I$#O#O   r8   "AsyncIterator[RealtimeServerEvent]c               j   K   ddl m} 	 	 |                                  d{V W V  # |$ r Y dS w xY wzq
        An infinite-iterator that will continue to yield events until
        the connection is closed.
        r   )ConnectionClosedOKTNwebsockets.exceptionsr   recvr5   r   s     r6   	__aiter__z!AsyncRealtimeConnection.__aiter__   st      
 	=<<<<<	( IIKK''''''''''(! 	 	 	FF	s   ) 22r%   c                `   K   |                      |                                  d{V           S )
        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_bytesr4   s    r6   r   zAsyncRealtimeConnection.recv   s8       doo&7&7 7 7 7 7 7 7888r8   bytesc                   K   | j                             d           d{V }t                              d|           |S )  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r5   messages     r6   r   z"AsyncRealtimeConnection.recv_bytes   sM       (--U-;;;;;;;;		3W===r8   event.RealtimeClientEvent | RealtimeClientEventParamc                   K   t          |t                    r|                    ddd          n,t          j        t          |t                     d {V           }| j                            |           d {V  d S NT)use_api_namesexclude_defaultsexclude_unset)	
isinstancer
   to_jsonjsondumpsr   r'   r~   sendr5   r   datas      r6   r   zAsyncRealtimeConnection.send   s       %++ZEMMtSWMXXX"7?W"X"XXXXXXXYY 	
 ##D)))))))))))r8      codereasonr   intr   rF   c               N   K   | j                             ||           d {V  d S Nr   r~   closer5   r   r   s      r6   r   zAsyncRealtimeConnection.close   s:      $$$v$>>>>>>>>>>>r8   r   str | bytesc           
         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   r5   r   s     r6   r   z#AsyncRealtimeConnection.parse_event  @     !9
4@P@PX\]`buXvXv!w!w!w
 
 	
r8   N)r   r}   r0   r\   )r0   r   r0   r%   r0   r   r   r   r0   r\   r   r   r   rF   r0   r\   r   r   r0   r%   )rN   rO   rP   __doc____annotations__ra   r   r   r   r   r   r   rQ   r8   r6   rq   rq      s        DD))))++++====3333????))))P P P P   9 9 9 9
 
 
 
* * * * *.R ? ? ? ? ? ?
 
 
 
 
 
r8   rq   c                  6    e Zd ZdZddZddZeZddZddZdS )rX   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()
    ```
    rJ   r+   rE   rF   rB   r   rC   r   rD   r#   r0   r\   c               Z    || _         || _        d | _        || _        || _        || _        d S r2   )'_AsyncRealtimeConnectionManager__client&_AsyncRealtimeConnectionManager__model+_AsyncRealtimeConnectionManager__connection,_AsyncRealtimeConnectionManager__extra_query._AsyncRealtimeConnectionManager__extra_headers=_AsyncRealtimeConnectionManager__websocket_connection_optionsr5   rJ   rE   rB   rC   rD   s         r6   ra   z'AsyncRealtimeConnectionManager.__init__!  s8     <@(,.J+++r8   rq   c           
       K   	 ddl m} n"# t          $ r}t          d          |d}~ww xY w| j        }| j                                         d{V  | j        j        }t          | j                  r*| j        	                    | j
        |           d{V \  }}nD|                                                     i | j        j        j        d| j
        i|          }t                              d|           | j        r t                              d| j                   t%           |t'          |          f| j        j        t+          i || j                  d	| j         d{V           | _        | j        S )
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.realtime.connect(...).enter()
        # ...
        await connection.close()
        ```
        r   rL   9You need to install `openai[realtime]` to use this methodNrE   paramsConnecting to %sConnection options: %suser_agent_headeradditional_headers)websockets.asyncio.clientrL   ImportErrorr   r   r   _refresh_api_keyauth_headersr   _configure_realtimer   _prepare_url	copy_withbase_urlr   r.   r   r   rq   rF   
user_agentr   r   r   r5   rL   excrB   r   urls         r6   
__aenter__z)AsyncRealtimeConnectionManager.__aenter__1  s     	d9999999 	d 	d 	dYZZ`cc	d (m,,.........}1 // 		&*m&G&GVa&b&b b b b b b bC##%%//m,3T\  " 0  C 			$c***. 	UII.0STTT3'C
"&-":#2& (	$ $
 
 5
 
 
 
 
 
 
 

 
   s    
*%*	httpx.URLc                    | j         j        t          j        | j         j                  }n | j         j                            d          }|j                            d          dz   }|                    |          S Nwss)scheme   /s	   /realtime)raw_path)r   websocket_base_urlhttpxURL	_base_urlr   r   rstripr5   r   merge_raw_paths      r6   r   z+AsyncRealtimeConnectionManager._prepare_urlf  p    =+7y!ABBHH}.888FFH!*11$77,F!!>!:::r8   exc_typetype[BaseException] | Noner   BaseException | Noneexc_tbTracebackType | Nonec                Z   K   | j         !| j                                          d {V  d S d S r2   )r   r   r5   r   r   r   s       r6   	__aexit__z(AsyncRealtimeConnectionManager.__aexit__o  sF       (#))+++++++++++ )(r8   N)rJ   r+   rE   rF   rB   r   rC   r   rD   r#   r0   r\   )r0   rq   r0   r   r   r   r   r   r   r   r0   r\   )	rN   rO   rP   r   ra   r   enterr   r   rQ   r8   r6   rX   rX     sz         &K K K K 1! 1! 1! 1!f E; ; ; ;, , , , , ,r8   rX   c                      e Zd ZU dZded<   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d&S ).RealtimeConnectionrr   RealtimeSessionResourcert   RealtimeResponseResourcerv    RealtimeInputAudioBufferResourcerx   RealtimeConversationResourcerz   !RealtimeOutputAudioBufferResourcer|   WebsocketConnectionr~   r   r0   r\   c                    || _         t          |           | _        t          |           | _        t          |           | _        t          |           | _        t          |           | _
        d S r2   )r~   r   rt   r   rv   r  rx   r  rz   r  r|   r   s     r6   ra   zRealtimeConnection.__init__  s^    %.t44066"B4"H"H8>>#DT#J#J   r8   Iterator[RealtimeServerEvent]c              #  \   K   ddl m} 	 	 |                                 V  # |$ r Y dS w xY wr   r   r   s     r6   __iter__zRealtimeConnection.__iter__  s_      
 	=<<<<<	"iikk!!!"! 	 	 	FF	s   " ++r%   c                P    |                      |                                           S )r   r   r4   s    r6   r   zRealtimeConnection.recv  s"      1 1222r8   r   c                r    | j                             d          }t                              d|           |S )r   Fr   r   r   r   s     r6   r   zRealtimeConnection.recv_bytes  s7     "''u'55		3W===r8   r   r   c                    t          |t                    r|                    ddd          n&t          j        t          |t                              }| j                            |           d S r   )	r   r
   r   r   r   r   r'   r~   r   r   s      r6   r   zRealtimeConnection.send  sk     %++NEMMtSWMXXXOE3KLLMM 	
 	d#####r8   r   r   r   r   r   r   rF   c               >    | j                             ||           d S r   r   r   s      r6   r   zRealtimeConnection.close  s$    D88888r8   r   r   c           
         t          t          t          t          j        |          t          t
          t                                        S r   r   r   s     r6   r   zRealtimeConnection.parse_event  r   r8   N)r   r  r0   r\   )r0   r  r   r   r   r   r   )rN   rO   rP   r   r   ra   r  r   r   r   r   r   rQ   r8   r6   r   r   v  s        DD$$$$&&&&8888....::::$$$$K K K K   3 3 3 3
 
 
 
$ $ $ $ $(r 9 9 9 9 9 9
 
 
 
 
 
r8   r   c                  6    e Zd ZdZddZddZeZddZddZdS )rG   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()
    ```
    rJ   r*   rE   rF   rB   r   rC   r   rD   r#   r0   r\   c               Z    || _         || _        d | _        || _        || _        || _        d S r2   )"_RealtimeConnectionManager__client!_RealtimeConnectionManager__model&_RealtimeConnectionManager__connection'_RealtimeConnectionManager__extra_query)_RealtimeConnectionManager__extra_headers8_RealtimeConnectionManager__websocket_connection_optionsr   s         r6   ra   z"RealtimeConnectionManager.__init__  s8     7;(,.J+++r8   r   c           
        	 ddl m} n"# t          $ r}t          d          |d}~ww xY w| j        }| j                                         | j        j        }t          | j                  r$| j        	                    | j
        |          \  }}nD|                                                     i | j        j        j        d| j
        i|          }t                              d|           | j        r t                              d| j                   t%           |t'          |          f| j        j        t+          i || j                  d	| j                  | _        | j        S )
uv  
        👋 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()
        ```
        r   r   r   NrE   r   r   r   r   )websockets.sync.clientrL   r   r   r  r  r   r   r   r   r  r   r   r   r   r.   r   r  r   rF   r   r   r  r  r   s         r6   	__enter__z#RealtimeConnectionManager.__enter__  s   	d6666666 	d 	d 	dYZZ`cc	d (&&(((}14=)) 		 $ A A$,P[ \ \C##%%//m,3T\  " 0  C 			$c***. 	UII.0STTT.GC
"&-":#2& (	$ $
 
 5
 

 
   s   	 
(#(r   c                    | j         j        t          j        | j         j                  }n | j         j                            d          }|j                            d          dz   }|                    |          S r   )r  r   r   r   r   r   r   r   r   s      r6   r   z&RealtimeConnectionManager._prepare_url  r   r8   r   r   r   r   r   r   c                J    | j         | j                                          d S d S r2   )r  r   r   s       r6   __exit__z"RealtimeConnectionManager.__exit__#  s0     (##%%%%% )(r8   N)rJ   r*   rE   rF   rB   r   rC   r   rD   r#   r0   r\   )r0   r   r   r   )	rN   rO   rP   r   ra   r  r   r   r  rQ   r8   r6   rG   rG     sz         &K K K K 1! 1! 1! 1!f E; ; ; ;& & & & & &r8   rG   c                      e Zd ZddZdS )BaseRealtimeConnectionResourcer   r   r0   r\   c                    || _         d S r2   r~   r   s     r6   ra   z'BaseRealtimeConnectionResource.__init__+      %r8   N)r   r   r0   r\   rN   rO   rP   ra   rQ   r8   r6   r  r  *  (        & & & & & &r8   r  c                      e Zd Zedd
dZd	S )r   event_idrt   "session_update_event_param.Sessionr%  str | NotGivenr0   r\   c                   | j                             t          t          t	          d||d                               dS u  
        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)typert   r%  Nr~   r   r   r'   r   r5   rt   r%  s      r6   updatezRealtimeSessionResource.update0  sP     	()9g[c d dee 	
 	
 	
 	
 	
r8   Nrt   r&  r%  r'  r0   r\   rN   rO   rP   r   r-  rQ   r8   r6   r   r   /  s5        `i 
 
 
 
 
 
 
 
r8   r   c                  .    e Zd ZeedddZeed	ddZdS )r   r%  rv   r%  r'  rv   ,RealtimeResponseCreateParamsParam | NotGivenr0   r\   c                   | j                             t          t          t	          d||d                               dS 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 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)r*  r%  rv   Nr+  r5   r%  rv   s      r6   createzRealtimeResponseResource.createE  sQ    B 	():^f g ghh 	
 	
 	
 	
 	
r8   r%  response_idr8  c                   | j                             t          t          t	          d||d                               dS a  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)r*  r%  r8  Nr+  r5   r%  r8  s      r6   cancelzRealtimeResponseResource.cancelm  sP     	():al m mnn 	
 	
 	
 	
 	
r8   Nr%  r'  rv   r2  r0   r\   r%  r'  r8  r'  r0   r\   rN   rO   rP   r   r6  r<  rQ   r8   r6   r   r   D  sa         $-AJ	&
 &
 &
 &
 &
 &
P 4=\e 
 
 
 
 
 
 
 
r8   r   c                  8    e Zd ZedddZedddZeddd
ZdS )r  r$  r%  r'  r0   r\   c          
         | j                             t          t          t	          d|d                               dS 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+  r5   r%  s     r6   clearz&RealtimeInputAudioBufferResource.clear  sI     	)?D^lt;u;u+v+vww	
 	
 	
 	
 	
r8   c          
         | j                             t          t          t	          d|d                               dS 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.commitrC  Nr+  rD  s     r6   commitz'RealtimeInputAudioBufferResource.commit  sI     	)?D_mu;v;v+w+wxx	
 	
 	
 	
 	
r8   audiorF   c                   | j                             t          t          t	          d||d                               dS 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. 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)r*  rI  r%  Nr+  r5   rI  r%  s      r6   appendz'RealtimeInputAudioBufferResource.append  sP    " 	()Dubj k kll 	
 	
 	
 	
 	
r8   Nr%  r'  r0   r\   rI  rF   r%  r'  r0   r\   rN   rO   rP   r   rE  rH  rM  rQ   r8   r6   r  r  ~  s}        2; 
 
 
 
 
 
 4= 
 
 
 
 
 
 @I 
 
 
 
 
 
 
 
r8   r  c                  &    e Zd Zedd            ZdS )r  r0    RealtimeConversationItemResourcec                *    t          | j                  S r2   )rR  r~   r4   s    r6   itemz!RealtimeConversationResource.item  s    /0@AAAr8   N)r0   rR  rN   rO   rP   r   rT  rQ   r8   r6   r  r    s8        B B B _B B Br8   r  c                  H    e Zd ZedddZeed	ddZedddZedddZdS )rR  r$  item_idrF   r%  r'  r0   r\   c                   | j                             t          t          t	          d||d                               dS 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*  rW  r%  Nr+  r5   rW  r%  s      r6   deletez'RealtimeConversationItemResource.delete  sQ     	()CPWem n noo 	
 	
 	
 	
 	
r8   r%  previous_item_idrT  r&   r^  c                   | j                             t          t          t	          d|||d                               dS 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*  rT  r%  r^  Nr+  r5   rT  r%  r^  s       r6   r6  z'RealtimeConversationItemResource.create  s\      	( : $$,,<	  
 
	
 	
 	
 	
 	
r8   audio_end_msr   content_indexc                   | j                             t          t          t	          d||||d                               dS 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*  rb  rc  rW  r%  Nr+  r5   rb  rc  rW  r%  s        r6   truncatez)RealtimeConversationItemResource.truncate  s_    " 	( <(4)6#*$,   	
 	
 	
 	
 	
r8   c                   | j                             t          t          t	          d||d                               dS 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.retrieverZ  Nr+  r[  s      r6   retrievez)RealtimeConversationItemResource.retrieve   sQ     	()ERYgo p pqq 	
 	
 	
 	
 	
r8   NrW  rF   r%  r'  r0   r\   rT  r&   r%  r'  r^  r'  r0   r\   
rb  r   rc  r   rW  rF   r%  r'  r0   r\   rN   rO   rP   r   r\  r6  rg  rj  rQ   r8   r6   rR  rR    s        AJ 
 
 
 
 
 
& $-+4
 
 
 
 
 
> bk
 
 
 
 
 
@ DM 
 
 
 
 
 
 
 
r8   rR  c                      e Zd ZedddZdS )	r  r$  r%  r'  r0   r\   c          
         | j                             t          t          t	          d|d                               dS a  **WebRTC 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.clearrC  Nr+  rD  s     r6   rE  z'RealtimeOutputAudioBufferResource.clear  sI     	)?D_mu;v;v+w+wxx	
 	
 	
 	
 	
r8   NrN  rN   rO   rP   r   rE  rQ   r8   r6   r  r    s5        2; 
 
 
 
 
 
 
 
r8   r  c                      e Zd ZddZdS )#BaseAsyncRealtimeConnectionResourcer   rq   r0   r\   c                    || _         d S r2   r  r   s     r6   ra   z,BaseAsyncRealtimeConnectionResource.__init__  r   r8   N)r   rq   r0   r\   r!  rQ   r8   r6   rt  rt    r"  r8   rt  c                      e Zd Zedd
dZd	S )rs   r$  rt   r&  r%  r'  r0   r\   c                  K   | j                             t          t          t	          d||d                               d{V  dS r)  r+  r,  s      r6   r-  z#AsyncRealtimeSessionResource.update$  sr       ##()9g[c d dee 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   Nr.  r/  rQ   r8   r6   rs   rs   #  s5        Yb
 
 
 
 
 
 
 
r8   rs   c                  .    e Zd ZeedddZeed	ddZdS )ru   r1  r%  r'  rv   r2  r0   r\   c                  K   | j                             t          t          t	          d||d                               d{V  dS r4  r+  r5  s      r6   r6  z$AsyncRealtimeResponseResource.create;  ss      B ##():^f g ghh 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   r7  r8  c                  K   | j                             t          t          t	          d||d                               d{V  dS r:  r+  r;  s      r6   r<  z$AsyncRealtimeResponseResource.cancelc  sr       ##():al m mnn 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   Nr=  r>  r?  rQ   r8   r6   ru   ru   :  sb         $-AJ	&
 &
 &
 &
 &
 &
P :Cbk 
 
 
 
 
 
 
 
r8   ru   c                  8    e Zd ZedddZedddZeddd
ZdS )rw   r$  r%  r'  r0   r\   c          
        K   | j                             t          t          t	          d|d                               d{V  dS rB  r+  rD  s     r6   rE  z+AsyncRealtimeInputAudioBufferResource.clearu  sk       ##)?D^lt;u;u+v+vww
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   c          
        K   | j                             t          t          t	          d|d                               d{V  dS rG  r+  rD  s     r6   rH  z,AsyncRealtimeInputAudioBufferResource.commit  sk       ##)?D_mu;v;v+w+wxx
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   rI  rF   c                  K   | j                             t          t          t	          d||d                               d{V  dS rK  r+  rL  s      r6   rM  z,AsyncRealtimeInputAudioBufferResource.append  sr      " ##()Dubj k kll 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   NrN  rO  rP  rQ   r8   r6   rw   rw   t  s~        8A 
 
 
 
 
 
 :C 
 
 
 
 
 
 FO 
 
 
 
 
 
 
 
r8   rw   c                  &    e Zd Zedd            ZdS )ry   r0   %AsyncRealtimeConversationItemResourcec                *    t          | j                  S r2   )r  r~   r4   s    r6   rT  z&AsyncRealtimeConversationResource.item  s    4T5EFFFr8   N)r0   r  rU  rQ   r8   r6   ry   ry     s8        G G G _G G Gr8   ry   c                  H    e Zd ZedddZeed	ddZedddZedddZdS )r  r$  rW  rF   r%  r'  r0   r\   c                  K   | j                             t          t          t	          d||d                               d{V  dS rY  r+  r[  s      r6   r\  z,AsyncRealtimeConversationItemResource.delete  ss       ##()CPWem n noo 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   r]  rT  r&   r^  c                  K   | j                             t          t          t	          d|||d                               d{V  dS r`  r+  ra  s       r6   r6  z,AsyncRealtimeConversationItemResource.create  s~        ##( : $$,,<	  
 

 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   rb  r   rc  c                  K   | j                             t          t          t	          d||||d                               d{V  dS re  r+  rf  s        r6   rg  z.AsyncRealtimeConversationItemResource.truncate  s      " ##( <(4)6#*$,   
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   c                  K   | j                             t          t          t	          d||d                               d{V  dS ri  r+  r[  s      r6   rj  z.AsyncRealtimeConversationItemResource.retrieve  ss       ##()ERYgo p pqq 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   Nrk  rl  rm  rn  rQ   r8   r6   r  r    s        GP 
 
 
 
 
 
& $-+4
 
 
 
 
 
> bk
 
 
 
 
 
@ JS 
 
 
 
 
 
 
 
r8   r  c                      e Zd ZedddZdS )	r{   r$  r%  r'  r0   r\   c          
        K   | j                             t          t          t	          d|d                               d{V  dS rq  r+  rD  s     r6   rE  z,AsyncRealtimeOutputAudioBufferResource.clear  sk       ##)?D_mu;v;v+w+wxx
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r8   NrN  rr  rQ   r8   r6   r{   r{     s5        8A 
 
 
 
 
 
 
 
r8   r{   )`
__future__r   r   loggingtypesr   typingr   r   r   r   typing_extensionsr	   r   pydanticr
   _typesr   r   r   r   _utilsr   r   r   r   r   _compatr   _modelsr   	_resourcer   r   _exceptionsr   _base_clientr   r7   r   r   r   r   r    r!   types.realtimer"   "types.websocket_connection_optionsr#   $types.realtime.realtime_client_eventr$   $types.realtime.realtime_server_eventr%   &types.realtime.conversation_item_paramr&   *types.realtime.realtime_client_event_paramr'   4types.realtime.realtime_response_create_params_paramr(   r  r)   r  r   r}   r3   r*   r+   __all__	getLoggerrN   r.   r   r,   r-   r9   rT   r=   rV   rq   rX   r   rG   r  r   r   r  r  rR  r  rt  rs   ru   rw   ry   r  r{   rQ   r8   r6   <module>r     s   # " " " " " "         5 5 5 5 5 5 5 5 5 5 5 5 + + + + + +        9 9 9 9 9 9 9 9 9 9 9 9              ' & & & & & / / / / / / : : : : : : : : & & & & & & + + + + + +                9 8 8 8 8 8 L L L L L L G G G G G G G G G G G G K K K K K K R R R R R R e e e e e e /NNNNNNVVVVVV........
''g'11 1 1 1 11
 1
 1
 1
 1
 1
 1
 1
h1
 1
 1
 1
 1
$ 1
 1
 1
hK K K K K K K KP P P P P P P PQ Q Q Q Q Q Q QV V V V V V V VH
 H
 H
 H
 H
 H
 H
 H
Vf, f, f, f, f, f, f, f,RH
 H
 H
 H
 H
 H
 H
 H
Vf& f& f& f& f& f& f& f&R& & & & & & & &

 
 
 
 
< 
 
 
*7
 7
 7
 7
 7
= 7
 7
 7
t+
 +
 +
 +
 +
'E +
 +
 +
\B B B B B#A B B BZ
 Z
 Z
 Z
 Z
'E Z
 Z
 Z
z
 
 
 
 
(F 
 
 
& & & & & & & &

 
 
 
 
#F 
 
 
.7
 7
 7
 7
 7
$G 7
 7
 7
t+
 +
 +
 +
 +
,O +
 +
 +
\G G G G G(K G G GZ
 Z
 Z
 Z
 Z
,O Z
 Z
 Z
z
 
 
 
 
-P 
 
 
 
 
r8   