
    *`i                         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
 d dlmZmZ d dlmZ d d	lmZ  e            rd dlZ G d
 dee          Z G d de          ZdS )    N)Enum)Any)Field)LanguageAlpha2)Audio)assert_soundfile_installedis_soundfile_installed)BaseCompletionRequest)RawAudioc                       e Zd ZdZdZdZdS )StreamingModedisabledonlineofflineN)__name__
__module____qualname__DISABLEDONLINEOFFLINE     /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/mistral_common/protocol/transcription/request.pyr   r      s        HFGGGr   r   c                   $   e Zd ZU dZdZedz  ed<   dZedz  ed<   eed<    e	dd          Z
edz  ed	<   d
Zeed<    e	ej        d          Zeed<   ddededeeeeeef                  f         fdZeddeeef         dedd fd            ZdS )TranscriptionRequestav  A class representing a request for audio transcription.

    This class handles the conversion of audio data into a format suitable for transcription
    using the OpenAI API. It includes methods to convert the request to and from the OpenAI format.

    Attributes:
        id: An optional identifier for the transcription request.
        model: The model to be used for transcription.
        audio: The audio data to be transcribed.
        language: The language of the input audio in ISO-639-1 format (optional).
        strict_audio_validation: A flag indicating whether to perform strict validation of the audio data.
    Nidmodelaudio.zrThe language of the input audio. Supplying the input language in ISO-639-1 format will improve language adherence.)descriptionlanguageTstrict_audio_validationzWhether to enable streaming for the transcription request. Online streaming means the audio is streamed to the server and the transcription is streamed back. Offline streaming means the audio is passed in one go to the server.)defaultr   	streamingr   excludekwargsreturnc                    |                      dh          }t                       t          | j        j        t
                    rt          j        | j        j                  }nt          | j        j        t                    sJ t          j
        | j        j                  }t          j                    }t          j        ||j        |j        |j                   |                    d           ||d<   |                    d          |d<   |                    |           d}||z  }|D ]}|                    |d	           |S )
a9  Convert the transcription request into the OpenAI format.

        This method prepares the transcription request data for compatibility with the OpenAI API.
        It handles the conversion of audio data and additional parameters into the required format.

        Args:
            exclude: Fields to exclude from the conversion.
            kwargs: Additional parameters to be added to the request.

        Returns:
            The request in the OpenAI format.

        Raises:
            ImportError: If the required soundfile library is not installed.
        r   )r$   )formatr   filerandom_seedseed)r   
max_tokensr!   r#   N)
model_dumpr   
isinstancer   databytesioBytesIOstrr   from_base64sfwriteaudio_arraysampling_rater(   seekpopupdate)selfr$   r%   openai_requestbufferr   default_excludeks           r   	to_openaizTranscriptionRequest.to_openai9   s/     *.')K)K"$$$djou-- 		Z
00FFdjos33333%djo66EZ\\FHVU.0CELYYYYKKNNN!'v!/!3!3M!B!Bvf%%% W7"  	( 	(Aq$''''r   Fr=   strictc                     |                     d          }|                     d          } fd|                                D             }|
J |            t          |t          j                  r|                                }n|j                                        }t          j	        ||          }|
                    |j                  }t          ||j                  }	|	|d<   ||d<     d	i |S )
a  Create a TranscriptionRequest instance from an OpenAI request dictionary.

        This method converts an OpenAI request dictionary into a TranscriptionRequest instance,
        handling the conversion of audio data and other parameters.

        Args:
            openai_request: The OpenAI request dictionary.
            strict: A flag indicating whether to perform strict validation of the audio data.

        Returns:
           An instance of TranscriptionRequest.
        r)   r+   c                 :    i | ]\  }}|j         v ||dv ||S )N)temperaturetop_p)model_fields).0r@   vclss      r   
<dictcomp>z4TranscriptionRequest.from_openai.<locals>.<dictcomp>t   sF     
 
 
1S%%%qyQBZ=Z=Z q=Z=Z=Zr   N)rB   )r/   r(   r   r*   r   )getitemsr.   r1   r2   getvaluer)   readr   
from_bytes	to_base64r(   r   )
rJ   r=   rB   r)   r+   converted_dictaudio_bytesr   	audio_str	raw_audios
   `         r   from_openaiz TranscriptionRequest.from_openaid   s    !!&))!!&))
 
 
 
&,,..
 
 
 dBJ'' 	+--//KK )..**K V<<<OOEL11	)ELAAA	"+w(,}%s$$^$$$r   )r   )F)r   r   r   __doc__r   r3   __annotations__r   r   r   r    r   r!   boolr   r   r#   tupler   dictlistrA   classmethodrV   r   r   r   r   r      sZ          Bd
E3:OOO&+eC' ' 'Hnt#    %)T((($u&b     I}   ) ) )s )tCdSVX[S[nI]D]?^ ) ) ) )V "% "%c3h "% "%Rh "% "% "% ["% "% "%r   r   )r1   enumr   typingr   pydanticr   "pydantic_extra_types.language_coder   mistral_common.audior   mistral_common.importsr   r	   mistral_common.protocol.baser
   &mistral_common.protocol.instruct.chunkr   	soundfiler5   r3   r   r   r   r   r   <module>rg      s,   				                   = = = = = = & & & & & & U U U U U U U U > > > > > > ; ; ; ; ; ;     C   p% p% p% p% p%0 p% p% p% p% p%r   