
    gZ                         d Z ddlmZmZ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lmZ dd	lmZmZ d
dlmZ  G d de      Zy)zP
Translates from OpenAI's `/v1/audio/transcriptions` to Deepgram's `/v1/listen`
    )ListOptionalUnion)HeadersResponse)BaseLLMExceptionget_secret_str)AllMessageValues&OpenAIAudioTranscriptionOptionalParams)TranscriptionResponse   )BaseAudioTranscriptionConfigLiteLLMLoggingObj   DeepgramExceptionc                       e Zd Zdedee   fdZdededededef
dZ	ded	e
d
eeef   defdZ	 ddedededededededee   defdZ	 ddee   dededee   def
dZ	 	 dd
ededee   dedee   dee   defdZy) DeepgramAudioTranscriptionConfigmodelreturnc                     dgS )Nlanguage )selfr   s     m/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/deepgram/audio_transcription/transformation.pyget_supported_openai_paramsz<DeepgramAudioTranscriptionConfig.get_supported_openai_params   s     |    non_default_paramsoptional_paramsdrop_paramsc                 l    | j                  |      }|j                         D ]  \  }}||v s|||<    |S N)r   items)r   r   r    r   r!   supported_paramskvs           r   map_openai_paramsz2DeepgramAudioTranscriptionConfig.map_openai_params   sG      ;;EB&,,.DAq$$%&" / r   error_messagestatus_codeheadersc                     t        |||      S )N)messager*   r+   r   )r   r)   r*   r+   s       r   get_error_classz0DeepgramAudioTranscriptionConfig.get_error_class+   s     !!{G
 	
r   Nraw_responsemodel_responselogging_objrequest_datalitellm_paramsapi_keyc	                 j   	 |j                         }	|	d   d   d   }
|
d   d   }|d   }t        |      }d|d<   d	|d
<   |	d   d   |d<   d|v r#|d   D cg c]  }|d   |d   |d   d c}|d<   |	|_        |S c c}w # t        $ r)}t	        dt        |       d|j                         d}~ww xY w)z_
        Transforms the raw response from Deepgram to the TranscriptionResponse format
        resultschannelsr   alternatives
transcript)text
transcribetaskenglishr   metadatadurationwordswordstartend)rA   rB   rC   z&Error transforming Deepgram response: z
Response: N)jsonr   _hidden_params	Exception
ValueErrorstrr:   )r   r   r/   r0   r1   r2   r    r3   r4   response_jsonfirst_channelfirst_alternativer:   responserA   es                   r   &transform_audio_transcription_responsezGDeepgramAudioTranscriptionConfig.transform_audio_transcription_response2   s   #	(--/M *)4Z@CM -n =a @ %\2D -$7H  ,HV Z  $1#<Z#HHZ  ++ !2' :% : "&\DM$u+V :%! '4H#O%  	8Q\M^M^L_` 	s*   AB  A;,B  ;B   	B2	$B--B2api_basestreamc                 T    |t        d      xs d}|j                  d      }| d| S )NDEEPGRAM_API_BASEzhttps://api.deepgram.com/v1/z/listen?model=)r
   rstrip)r   rO   r   r    rP   s        r   get_complete_urlz1DeepgramAudioTranscriptionConfig.get_complete_urle   s?     23T7T  ??3'>%11r   messagesc                 .    |xs t        d      }dd| iS )NDEEPGRAM_API_KEYAuthorizationzToken r	   )r   r+   r   rV   r    r4   rO   s          r   validate_environmentz5DeepgramAudioTranscriptionConfig.validate_environmentt   s*     ?^,>?vgY/
 	
r   r#   )NN)__name__
__module____qualname__rH   r   r   r   dictboolr(   intr   r   r   r.   r   r   r   r   rN   rU   r   rZ   r   r   r   r   r      s   	4	5
   	
  

 
/2
=B4==Q
	
  "&11 1 .	1
 '1 1 1 1 #1 
1p "&23-2 2 	2
 2 
2* "&"&

 
 '(	

 
 #
 3-
 

r   r   N)__doc__typingr   r   r   httpxr   r   )litellm.llms.base_llm.chat.transformationr   litellm.secret_managers.mainr
   litellm.types.llms.openair   r   litellm.types.utilsr   +base_llm.audio_transcription.transformationr   r   common_utilsr   r   r   r   r   <module>rj      s>    ) ( # F 7 6 -h
'C h
r   