
    *`iN                         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 d dlmZ d dlmZ  G d	 d
e	          Z G d dee          Z G d de          ZdefdZdS )    N)Enum)Path)Any)	BaseModel
ConfigDictfield_validator)BaseSettings)ValidationMode)MistralTokenizerc                       e Zd ZU dZeeeeeeeeeeef         z  f                  z  f                  ed<   dZ	eeeef                  dz  ed<    e
d          Zdeeef         fdZdS )	OpenAIChatCompletionRequestaS  OpenAI chat completion request.

    This class is used to parse the request body for the OpenAI chat completion endpoint.

    Attributes:
        messages: The messages to use for the chat completion.
        tools: The tools to use for the chat completion.

    Note:
        This class accepts extra fields that are not validated.
    messagesNtoolsallow)extrareturnc                       fd                                                                  D             fd j                                        D              _        S )zDrop extra fields from the model.

        This method is used to drop extra fields from the model, which are not defined in the model fields.

        Returns:
            The extra fields that were dropped from the model.
        c                 H    i | ]\  }}|t                    j        v||S  )typemodel_fields).0fieldvalueselfs      z/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/mistral_common/experimental/app/models.py
<dictcomp>zAOpenAIChatCompletionRequest.drop_extra_fields.<locals>.<dictcomp>)   s=     
 
 
)UE%W[\`WaWaWnJnJnE5JnJnJn    c                 $    i | ]\  }}|v	||S r   r   )r   kvextra_fieldss      r   r   zAOpenAIChatCompletionRequest.drop_extra_fields.<locals>.<dictcomp>-   s)    YYY$!Q1LCXCXACXCXCXr   )
model_dumpitems__dict__)r   r"   s   `@r   drop_extra_fieldsz-OpenAIChatCompletionRequest.drop_extra_fields!   st    
 
 
 
-1__->->-D-D-F-F
 
 
 ZYYY$-*=*=*?*?YYYr   )__name__
__module____qualname____doc__listdictstrr   __annotations__r   r   model_configr&   r   r   r   r   r      s         
 
 4S4S#S#X2F-F(G#HHHIJJJJ)-E4S#X$&--- :G,,,L4S>      r   r   c                       e Zd ZdZdZdS )EngineBackendzZThe engine backend to use.

    Attributes:
        llama_cpp: The llama.cpp backend.
    	llama_cppN)r'   r(   r)   r*   r2   r   r   r   r1   r1   1   s          IIIr   r1   c                       e Zd ZU dZdZeed<   ej        	                    d          Z
eed<   dZeed<   ej        Zeed<   d	Zeed
<   dZeed<    edd          ededefd                        Z edd          edeez  defd                        Zdeddf fdZdeez  deddfdZedefd            Zej        deddfd            Z xZS )Settingsa<  Settings for the Mistral-common API.

    Attributes:
        app_name: The name of the application.
        app_version: The version of the application.
        engine_url: The URL of the engine.
        engine_backend: The backend to use for the engine.
        timeout: The timeout to use for the engine API.
    zMistral-common APIapp_namezmistral-commonapp_versionz	127.0.0.1
engine_urlengine_backend api_key<   timeoutbeforemoder   r   c                 n    t          |t                    r|                    d          r
|d d         }|S )N/)
isinstancer-   endswithclsr   s     r   _validate_engine_urlzSettings._validate_engine_urlM   s;     eS!! 	ennS&9&9 	#2#JEr   c                 N    t          |t                    rt          |          }|S N)rC   r-   r1   rE   s     r   _validate_backendzSettings._validate_backendT   s(     eS!! 	)!%((Er   contextNc                 X    t                                          |           d | _        d S rI   )supermodel_post_init
_tokenizer)r   rK   	__class__s     r   rN   zSettings.model_post_init[   s&    (((37r   tokenizer_pathvalidation_modec                    |dk    rt          d          | j        t          d          t          |t                    r%t	          |          }|                                r|}t          |t                    r1|                                rt          j        ||          | _        d S t          j        t          |          |          | _        d S )Nr9   zITokenizer path must be set via the environment variable `TOKENIZER_PATH`.z'Tokenizer has already been initialized.r>   )	
ValueErrorrO   rC   r-   r   existsr   	from_filefrom_hf_hub)r   rQ   rR   candidate_tokenizer_paths       r   _load_tokenizerzSettings._load_tokenizer_   s    Rhiii_(FGGGnc** 	:'+N';';$'..00 :!9nd++ 	f0E0E0G0G 	f.8o^^^DOOO.:3~;N;NUdeeeDOOOr   c                 <    | j         t          d          | j         S )NzTokenizer not initialized.)rO   rT   )r   s    r   	tokenizerzSettings.tokenizero   s!    ?"9:::r   c                 \    t          |t                    st          d          || _        d S )Nz2Tokenizer must be an instance of MistralTokenizer.)rC   r   rT   rO   )r   r   s     r   r[   zSettings.tokenizeru   s0    %!122 	SQRRRr   ) r'   r(   r)   r*   r5   r-   r.   	importlibmetadataversionr6   r7   r1   r2   r8   r:   r<   intr   classmethodrG   rJ   r   rN   r   r
   rY   propertyr   r[   setter__classcell__)rP   s   @r   r4   r4   ;   s          )Hc((( )112BCCKCCC!J!!!$1$;NM;;;GSGS_\111     [ 21
 _%H555cM&9 m    [ 65
8s 8t 8 8 8 8 8 8fcDj f> f^b f f f f  +    X
  /  D                r   r4   r   c                      t                      S )z,Get the settings for the Mistral-common API.)r4   r   r   r   get_settingsrf   |   s    ::r   )importlib.metadatar]   enumr   pathlibr   typingr   pydanticr   r   r   pydantic_settingsr	   *mistral_common.protocol.instruct.validatorr
   (mistral_common.tokens.tokenizers.mistralr   r   r-   r1   r4   rf   r   r   r   <module>ro      sB                         ; ; ; ; ; ; ; ; ; ; * * * * * * E E E E E E E E E E E E! ! ! ! !) ! ! !H    C   >  >  >  >  > | >  >  > Bh      r   