
    h7                        d Z ddlmZmZmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ   e       Z! e       Z" e
       Z#e 	 	 	 	 	 	 	 dde$dedee$   dee$   dee$   dee$   dee   dee%   dee   fd       Z&	 	 dde$de$dee$   dee$   dee$   f
dZ'y) z.Abstraction function for OpenAI's realtime API    )AnyOptionalcastN)get_llm_provider)BaseRealtimeConfig)BaseLLMHTTPHandler)get_secret_str)GenericLiteLLMParams)LlmProviders)ProviderConfigManager   )get_litellm_params)Logging)AzureOpenAIRealtime)OpenAIRealtime)RealtimeQueryParams)clientmodel	websocketapi_baseapi_keyapi_versionazure_ad_tokenr   timeoutquery_paramsc	                   K   t        t        t           |	j                  d            }
t        t        t           |	j                  d            }|
i }
||
j	                  |       |	j                  d      }|	j                  dd      }t        di |	}t        di |	}t        | ||      \  } }}}|j                  | |i ||       d}|t        j                  j                         v r t        j                  | t        |            }|'t        j                  | ||||||||
		       d{    y|d
k(  r|xs+ |j                   xs t"        j                   xs t%        d      }|xs/ t"        j&                  xs t"        j(                  xs t%        d      }t*        j                  | |||ddd||	       d{    y|dk(  r|xs" |j                   xs t"        j                   xs d}|xs/ t"        j&                  xs t"        j(                  xs t%        d      }t,        j                  | ||||d||       d{    yt/        d|        7 &7 7 w)zT
    Private function to handle the realtime API call.

    For PROXY use only.
    headersextra_headersNlitellm_logging_objuser)r   r   r   )r   r    optional_paramslitellm_paramscustom_llm_provider)r   provider)	r   r   logging_objprovider_configr   r   r   r   r   azureAZURE_API_BASEAZURE_API_KEY2024-10-01-preview)	r   r   r   r   r   r   r   r   r%   openaihttps://api.openai.com/OPENAI_API_KEY)r   r   r%   r   r   r   r   r   Unsupported model:  )r   r   dictgetupdater
   r   r   update_environment_variablesr   _member_map_valuesr   get_provider_realtime_configbase_llm_http_handlerasync_realtimer   litellmr	   r   
openai_keyazure_realtimeopenai_realtime
ValueError)r   r   r   r   r   r   r   r   r   kwargsr   r   r   r    r"   litellm_params_dict_custom_llm_providerdynamic_api_keydynamic_api_baser&   s                       U/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/realtime_api/main.py
_arealtimerD      s    $ 8D>6::i#89G$O)DEM }%*0**5J*K::fd#D)3F3N,6v6EUFBE2B 44*0 5  59O|88??AA/LL!"67
 "#22++ 3 

 
	
 
	
 
	( 0&&00 ./	 	  //!!/ o.	 	 ++,+ , 

 
	
 
	
 
	) )&&)) )	 	  00!!0 ./	 	 ,,+% - 	
 		
 		
 .ug677
	
4
	
4		
s8   D+I-I.BI;I<BI?I IIIr#   c                 f  K   ddl }d}|dk(  r!t        j                  |xs d| |xs d      }n9|dk(  r&t        j                  |xs dt	        | 	      
      }nt        d|        |j                  |d|i      4 d{    	 ddd      d{    y7 7 # 1 d{  7  sw Y   yxY ww)a  
    Health check for realtime API - tries connection to the realtime API websocket

    Args:
        model: str - model name
        api_base: str - api base
        api_version: Optional[str] - api version
        api_key: str - api key
        custom_llm_provider: str - custom llm provider

    Returns:
        bool - True if connection is successful, False otherwise
    Raises:
        Exception - if the connection is not successful
    r   Nr'    r*   )r   r   r   r+   r,   )r   )r   r   r.   zapi-key)r   T)
websocketsr;   _construct_urlr<   r   r=   connect)r   r#   r   r   r   rG   urls          rC   _realtime_health_checkrK      s     , Cg%++^#;'; , 

 
	(,,:!:I\chIi - 
 .ug677!!w
 "          sH   A?B1BB1BB1BB1B1B."B%#B.*B1)NNNNNNN)NN)(__doc__typingr   r   r   r9   r   -litellm.llms.base_llm.realtime.transformationr   *litellm.llms.custom_httpx.llm_http_handlerr   litellm.secret_managers.mainr	   litellm.types.routerr
   litellm.types.utilsr   litellm.utilsr   %litellm_core_utils.get_litellm_paramsr   "litellm_core_utils.litellm_loggingr   LiteLLMLoggingllms.azure.realtime.handlerr   llms.openai.realtime.handlerr   litellm.types.realtimer   utilsr   wrapper_clientr;   r<   r7   strfloatrD   rK   r/       rC   <module>r_      sC   4 & &  $ L I 7 5 , / F J = 9 6 ,$& "*,   #!!%$( #26q8q8q8 smq8 c]	q8
 #q8 SMq8 SMq8 e_q8 ./q8 q8p #!%+++ c]+ sm	+
 #+r^   