
    j                          d dl 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
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)    )OptionalUnioncastN)AsyncOpenAIOpenAI)	BaseModel)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fdZ	 	 	 	 dd	edededededee   dee   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/backend/.venv/lib/python3.12/site-packages/litellm/llms/openai/transcriptions/handler.py(make_openai_audio_transcriptions_requestzAOpenAIAudioTranscription.make_openai_audio_transcriptions_request   s     	 Sn**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_request2   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returnc                 Z   |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-   r.   r/   r0   )r-   fileT)	r.   r   r1   r   r4   r5   clientr2   r3   Fis_asyncr4   r5   r   r2   r;   r5   r6   complete_input_dictinputr4   additional_args)r(   r   r   textr?   rA   r4   rB   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_callr4   	_base_url_uri_referencer,   
isinstancer   
model_dumpr   	post_callr	   r   )r"   r-   r.   r/   r0   r1   r   r2   r3   r4   r5   r;   r6   r7   transformed_datar   r(   _r$   stringified_responserN   final_responses                         r&   audio_transcriptionsz-OpenAIAudioTranscription.audio_transcriptionsM   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)NTr<   r>   r@   )r   r   r   response_headersrC   durationr?   rE   r-   z	whisper-1rG   rH   rJ   rK   )rA   r4   rF   )rR   rS   r4   rT   rU   r'   model_call_detailsrV   r   rW   r   r   rX   r	   getr   r!   rA   str)r"   r.   r   r1   r   r3   r4   r5   r;   r2   r   r   r$   r[   ra   actual_modelrN   r%   s                     r&   rQ   z3OpenAIAudioTranscription.async_audio_transcriptions   s    3	*.*A*A!' +B +N   &.. . 8 8 G G&*+/! !  '+&S&S- 'T ' !GX
 BIK**+=>(I.'/':':'<$;HE'<('K'V'V'X$3;$Z0!!)*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)NFN)NNNN)__name__
__module____qualname__r   r   r   floathttpxTimeoutr'   r   r,   rd   r   r   intLiteLLMLoggingObjr   boolr   r]   rQ   r   r^   r&   r   r      sm   #  uemm+,	2  uemm+,	N $BFSS S 	S
 S .S S S 'S #S 3-S S "">?S 
Sx "&"&?? ? .	?
 ? '? #? 3-?r^   r   )typingr   r   r   rj   rG   r   r   pydanticr   r*   ,litellm.litellm_core_utils.audio_utils.utilsr	   *litellm.litellm_core_utils.litellm_loggingr
   rm   8litellm.llms.base_llm.audio_transcription.transformationr   litellm.types.utilsr   litellm.utilsr   r   r   r   r   r   r^   r&   <module>rv      sE    ( (  &   L S *  *J3 Jr^   