
    g                         d dl 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mZmZ d	d
lmZ  G d de      Zy)    )OptionalUnionN)AsyncOpenAIOpenAI)	BaseModel)get_audio_file_name)Logging)	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e   dee   d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           _/var/www/openai/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_request.   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model_responsemax_retrieslogging_objapi_keyapi_baseatranscriptionreturnc                 &   ||d|}d|vs|d   dk(  s|d   dk(  rd|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d}t        |||d      }|S )N)r+   fileresponse_formattextjsonverbose_jsonT)	r,   r   r.   r   r1   r2   clientr/   r0   F)is_asyncr1   r2   r   r/   r2   r3   complete_input_dictinputr1   additional_args)r&   r   r   r8   r>   r@   r1   rA   original_response	whisper-1openair+   custom_llm_provideraudio_transcriptionresponse_objectmodel_response_objecthidden_paramsresponse_type)async_audio_transcriptions_get_openai_clientpre_callr1   	_base_url_uri_referencer*   
isinstancer   
model_dumpr   	post_callr   r   )r    r+   r,   r-   r.   r   r/   r0   r1   r2   r;   r3   r   r&   _r"   stringified_responserM   final_responses                      r$   audio_transcriptionsz-OpenAIAudioTranscription.audio_transcriptionsI   s    
FoFD("#v-6G1HF1R  "# 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	 	 	
 #.hO0Pau  N\  ly  I^  1_    c
                 l  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|
       ddd}t        |||d      S 7 # t        $ r(}|j                  t         |t#        |             |d }~ww xY ww)NT)r<   r1   r2   r   r/   r;   r=   r?   )r   r   r   response_headersrB   durationr>   rC   rE   rF   rG   rI   rJ   )r@   r1   rD   )rP   rQ   r1   rR   rS   r%   model_call_detailsrT   r   rU   r   r   rV   r   r   r   r@   str)r    r,   r   r.   r   r0   r1   r2   r;   r/   r   r   r"   rX   r^   rM   r#   s                    r$   rO   z3OpenAIAudioTranscription.async_audio_transcriptions   s    0	*.*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	 "  '2(SM3DXp~  O\  lA  B  B)!*  	!!"%a& " 
 G	s<   D4A$D  (C>)BD  =D4>D   	D1	#D,,D11D4)NF)NNNN)__name__
__module____qualname__r   r   r   floathttpxTimeoutr%   r   r*   r`   r
   r   intLiteLLMLoggingObjr   boolrZ   rO   r   r[   r$   r   r      sN   #  uemm+,	0  uemm+,	L $JJ J 	J
 .J J J 'J #J 3-J J 
Jf "&"&<< < .	<
 < '< #< 3-<r[   r   )typingr   r   re   rF   r   r   pydanticr   r(   ,litellm.litellm_core_utils.audio_utils.utilsr   *litellm.litellm_core_utils.litellm_loggingr	   rh   litellm.types.utilsr
   litellm.utilsr   r   r   r   r   r   r[   r$   <module>rp      s;    "  &   L S )  *}3 }r[   