o
    -i                     @   s   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
 d dlmZ d dlmZmZmZmZmZmZmZmZmZmZ d dlmZ d d	lmZ d d
lmZ eeZG dd deZ G dd deZ!dS )    )AsyncGenerator)Request)EngineClient)RequestLogger)ErrorResponseRequestResponseMetadata)OpenAIServingModels)
TranscriptionRequestTranscriptionResponse!TranscriptionResponseStreamChoiceTranscriptionResponseVerboseTranscriptionStreamResponseTranslationRequestTranslationResponseTranslationResponseStreamChoiceTranslationResponseVerboseTranslationStreamResponse)OpenAISpeechToText)init_logger)RequestOutputc                          e Zd ZdZdddddedededB ded	ed
ef fddZde	de
dedeeB eedf B eB fddZde
deeedf  dedededeedf fddZ  ZS )OpenAIServingTranscriptionzHandles transcription requests.Freturn_tokens_as_token_idslog_error_stackenable_force_include_usageengine_clientmodelsrequest_loggerNr   r   r   c             	         t  j||||d||d d S )N
transcriber   r   r   r   	task_typer   r   super__init__selfr   r   r   r   r   r   	__class__ i/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/vllm/entrypoints/openai/translations/serving.pyr%   $      

z#OpenAIServingTranscription.__init__
audio_datarequestraw_requestreturnc                    ,   | j ||||jdkrtnt| jdI dH S )zTranscription API similar to OpenAI's API.

        See https://platform.openai.com/docs/api-reference/audio/createTranscription
        for the API specification. This API mimics the OpenAI transcription API.
        verbose_jsonr-   r.   r/   response_classstream_generator_methodN)_create_speech_to_textresponse_formatr   r
   transcription_stream_generatorr'   r-   r.   r/   r*   r*   r+   create_transcription8      
z/OpenAIServingTranscription.create_transcriptionresult_generator
request_idrequest_metadataaudio_duration_sc              
   C  :   | j |||||dttd}|2 z	3 d H W }|V  q6 d S )Nztranscription.chunkr.   list_result_generatorr=   r>   r?   chunk_object_typeresponse_stream_choice_classstream_response_class) _speech_to_text_stream_generatorr   r   r'   r.   r<   r=   r>   r?   	generatorchunkr*   r*   r+   r8   Q      
z9OpenAIServingTranscription.transcription_stream_generator)__name__
__module____qualname____doc__r   r   r   boolr%   bytesr	   r   r
   r   r   strr   r:   listr   r   floatr8   __classcell__r*   r*   r(   r+   r   !   \    


r   c                       r   )OpenAIServingTranslationzHandles translation requests.Fr   r   r   r   Nr   r   r   c             	      r   )N	translater!   r#   r&   r(   r*   r+   r%   j   r,   z!OpenAIServingTranslation.__init__r-   r.   r/   r0   c                    r1   )zTranslation API similar to OpenAI's API.

        See https://platform.openai.com/docs/api-reference/audio/createTranslation
        for the API specification. This API mimics the OpenAI translation API.
        r2   r3   N)r6   r7   r   r   translation_stream_generatorr9   r*   r*   r+   create_translation~   r;   z+OpenAIServingTranslation.create_translationr<   r=   r>   r?   c              
   C  r@   )Nztranslation.chunkrA   )rF   r   r   rG   r*   r*   r+   rX      rJ   z5OpenAIServingTranslation.translation_stream_generator)rK   rL   rM   rN   r   r   r   rO   r%   rP   r   r   r   r   r   rQ   r   rY   rR   r   r   rS   rX   rT   r*   r*   r(   r+   rV   g   rU   rV   N)"collections.abcr   fastapir   vllm.engine.protocolr   vllm.entrypoints.loggerr   'vllm.entrypoints.openai.engine.protocolr   r   &vllm.entrypoints.openai.models.servingr   -vllm.entrypoints.openai.translations.protocolr	   r
   r   r   r   r   r   r   r   r   3vllm.entrypoints.openai.translations.speech_to_textr   vllm.loggerr   vllm.outputsr   rK   loggerr   rV   r*   r*   r*   r+   <module>   s   0F