o
    c۷ii                     @   s  d dl mZ d dlmZ d dlZd dlZd dlmZ d dlm	Z	m
Z
mZ d dlmZmZmZ d dlmZ d dlmZ ejd	e	jd
fdeeB eB dedede	dedefddZe d2ddZejdddidejdedejdejdd eD ddejjdejd ed	d!d"d#ejd$ed d%d"d#ejd&ed'd(d"d#ejd)ejd*d e	D dde	jjd+d"d#ejd,ed
d-d"d#ejd	d d'e	jjd
fdeeB deeB d.ed/ededededdfd0dZ e!d1kre  dS dS )3    )	lru_cache)PathN)FastAPI)EngineBackendSettingsget_settings)decode_routermain_routertokenize_router)ValidationMode)MistralTokenizerz	127.0.0.1<   	tokenizervalidation_mode
engine_urlengine_backendtimeoutreturnc                    sn   t tttfstdt }|t |t |t	 t
dtf fdd}|  ||jt< |S )aq  Create a Mistral-common FastAPI app with the given tokenizer and validation mode.

    Args:
        tokenizer: The tokenizer path or a MistralTokenizer instance.
        validation_mode: The validation mode to use.
        engine_url: The URL of the engine API.
        timeout: The timeout of the engine API.

    Returns:
        The Mistral-common FastAPI app.
    z8Tokenizer must be a path or a MistralTokenizer instance.r   c                     s2   t  d} ttr| _| S |  | S )N)r   r   r   )r   
isinstancer   r   _load_tokenizer)settingsr   r   r   r   r    Z/home/ubuntu/vllm_env/lib/python3.10/site-packages/mistral_common/experimental/app/main.pyget_settings_override0   s   
z)create_app.<locals>.get_settings_override)r   r   strr   
ValueErrorr   include_routerr
   r   r	   r   r   dependency_overridesr   )r   r   r   r   r   appr   r   r   r   
create_app   s   



r    c                   C   s   dS )zMistral-common CLI.Nr   r   r   r   r   cliC   s   r!   serveauto_envvar_prefixUVICORN)namecontext_settingstokenizer_path)typec                 C      g | ]}|j qS r   value.0moder   r   r   
<listcomp>M       r/   F)case_sensitive)r(   defaultz--hostzMistral-common API hostT)r(   r2   helpshow_defaultz--portzMistral-common API portz--engine-urlzhttp://127.0.0.1:8080z
Engine URLz--engine-backendc                 C   r)   r   r*   r,   r   r   r   r/   g   r0   zEngine API backendz	--timeoutTimeouthostportc                 C   s.   t | t||t||d}tj|||d dS )zOServe the Mistral-common API with the given tokenizer path and validation mode.)r   r   r   r   r   )r6   r7   N)r    r   r   uvicornrun)r'   r   r6   r7   r   r   r   r   r   r   r   r"   I   s   4__main__)r   N)"	functoolsr   pathlibr   clickr8   fastapir   &mistral_common.experimental.app.modelsr   r   r   'mistral_common.experimental.app.routersr   r	   r
   *mistral_common.protocol.instruct.validatorr   (mistral_common.tokens.tokenizers.mistralr   test	llama_cppr   intr    groupr!   commandargumentChoicer+   optionr"   __name__r   r   r   r   <module>   s    

-	
