
    i>!                         d dl mZmZmZmZ d dlZd dlmZmZ d dl	m
Z
 d dlZer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mZmZ ddlmZ  G d de      Zy)    )TYPE_CHECKINGOptionalUnioncastN)AsyncOpenAIOpenAI)	BaseModel)ClientSession)get_audio_file_name)Logging)BaseAudioTranscriptionConfig)	FileTypes)TranscriptionResponse convert_to_model_response_object extract_duration_from_srt_or_vtt   )OpenAIChatCompletionc                      e Zd Zdededeeej                  f   fdZ	de
dedeeej                  f   fdZ	 	 	 	 dded	ed
ededededededee   dee   dedee   ded   defdZ	 	 	 	 	 dd	edededededee   dee   ded   fdZy)OpenAIAudioTranscriptionopenai_aclientdatatimeoutc                    K   	  |j                   j                  j                  j                  di |d|i d{   }t	        |j
                        }|j                         }||fS 7 -# t        $ r}|d}~ww xY ww)
        Helper to:
        - call openai_aclient.audio.transcriptions.with_raw_response when litellm.return_response_headers is True
        - call openai_aclient.audio.transcriptions.create by default
        r   N )audiotranscriptionswith_raw_responsecreatedictheadersparse	Exception)selfr   r   r   raw_responser!   responsees           {/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/openai/transcriptions/handler.py(make_openai_audio_transcriptions_requestzAOpenAIAudioTranscription.make_openai_audio_transcriptions_request   s     	Rn**99KKRR $+  
 <//0G#))+HH$$  	G	s8   A>7A+ A),A+ (A>)A+ +	A;4A66A;;A>openai_clientc                 d   	 t         j                  du r] |j                  j                  j                  j
                  di |d|i}t        |j                        }|j                         }||fS  |j                  j                  j
                  di |d|i}d|fS # t        $ r}|d}~ww xY w)r   Tr   Nr   )
litellmreturn_response_headersr   r   r   r   r    r!   r"   r#   )r$   r*   r   r   r%   r!   r&   r'   s           r(   -make_sync_openai_audio_transcriptions_requestzFOpenAIAudioTranscription.make_sync_openai_audio_transcriptions_request4   s    	..$6OM''66HHOO (/ 
 |334'--/((D=..==DD]t]U\]X~% 	G	s   A.B 1-B 	B/(B**B/Nmodel
audio_fileoptional_paramslitellm_paramsmodel_responsemax_retrieslogging_objapi_keyapi_baseatranscriptionprovider_configshared_sessionr
   returnc                 \   |0|j                  ||||      }t        t        |j                        }n||d|}|du r| j	                  |||||	|
||||
      S | j                  d|	|
|||      }|j                  d|j                  |j                  j                  d|d	       | j                  |||
      \  }}t        |t              r|j                         }nt        |      j                         }|j                  t!        |      |	d|i|       |dd}t#        |||d      }|S )z4
        Handle audio transcription request
        N)r/   r0   r1   r2   )r/   fileT)
r0   r   r3   r   r6   r7   clientr4   r5   r:   F)is_asyncr6   r7   r   r4   r>   r7   r8   complete_input_dictinputr6   additional_args)r*   r   r   textrA   rC   r6   rD   original_responseopenair/   custom_llm_provideraudio_transcriptionresponse_objectmodel_response_objecthidden_paramsresponse_type)%transform_audio_transcription_requestr   r    r   async_audio_transcriptions_get_openai_clientpre_callr6   	_base_url_uri_referencer.   
isinstancer	   
model_dumpr   	post_callr   r   )r$   r/   r0   r1   r2   r3   r   r4   r5   r6   r7   r>   r8   r9   r:   transformed_datar   r*   _r&   stringified_responserP   final_responses                          r(   audio_transcriptionsz-OpenAIAudioTranscription.audio_transcriptionsO   s   ( &.TT% /-	  U   .334D"JJ/JDT!22%-!''- 3   !% 7 7# !8 !
 	!)))33BB"&'+ 	 	
 HH' I 
8 h	*#+#6#6#8 #8h#G#R#R#T  	%j12D92	 	 	
 #(I0Pau  N\  ly  I^  1_    c           	        K   	 | j                  d||||	||
      }|j                  d |j                  |j                  j                  d|d       | j                  |||       d {   \  }}||j                  d<   t        |t              r|j                         }n*t        |      }t        |      j                         }||d<   |j                  t        |      |d	|i|
       |j                  dd      }|dd}t        |||d      S 7 # t         $ r(}|j                  t"        |t%        |             |d }~ww xY ww)NT)r?   r6   r7   r   r4   r>   r:   r@   rB   )r   r   r   response_headersrE   _audio_transcription_durationrA   rG   r/   z	whisper-1rI   rJ   rL   rM   )rC   r6   rH   )rT   rU   r6   rV   rW   r)   model_call_detailsrX   r	   rY   r   r   rZ   r   getr   r#   rC   str)r$   r0   r   r3   r   r5   r6   r7   r>   r4   r:   r   r!   r&   r]   durationactual_modelrP   r'   s                      r(   rS   z3OpenAIAudioTranscription.async_audio_transcriptions   s    4	*.*A*A!'- +B +N   &.. . 8 8 G G&*+/! !  '+&S&S- 'T ' !GX
 BIK**+=>(I.'/':':'<$;HE'<('K'V'V'X$HP$%DE!!)*5!6 ="6	 "   88G[9L&28TM3DXp~  O\  lA  B  B/!0  	!!"%a& " 
 G	s<   EA%D )D*B&D ED 	E#D??EE)NFNN)NNNNN)__name__
__module____qualname__r   r    r   floathttpxTimeoutr)   r   r.   rf   r   r   intLiteLLMLoggingObjr   boolr   r_   rS   r   r`   r(   r   r      s   #  uemm+,	0  uemm+,	N $BF48UU U 	U
 U .U U U 'U #U 3-U U "">?U !1U  
!U| "&"&48AA A .	A
 A 'A #A 3-A !1Ar`   r   )typingr   r   r   r   rm   rI   r   r   pydanticr	   r,   aiohttpr
   ,litellm.litellm_core_utils.audio_utils.utilsr   *litellm.litellm_core_utils.litellm_loggingr   rp   8litellm.llms.base_llm.audio_transcription.transformationr   litellm.types.utilsr   litellm.utilsr   r   r   r   r   r   r`   r(   <module>rz      sK    7 7  &  % L S *  *M3 Mr`   