o
    #1 i                     @   s  d dl mZ 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eef dedededede	fddZe d3d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ef deeef d/ed0ededededdfd1dZ"e#d2kre  dS dS )4    )	lru_cache)Path)UnionN)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   Z_load_tokenizer)settingsr   r   r   r   r    p/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/mistral_common/experimental/app/main.pyget_settings_override1   s   
z)create_app.<locals>.get_settings_override)r   r   strr   
ValueErrorr   Zinclude_routerr   r	   r
   r   r   Z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   cliD   s   r   serveZauto_envvar_prefixZUVICORN)nameZcontext_settingstokenizer_path)typec                 C      g | ]}|j qS r   value.0moder   r   r   
<listcomp>N       r*   F)case_sensitive)r#   defaultz--hostzMistral-common API hostT)r#   r-   helpZshow_defaultz--portzMistral-common API portz--engine-urlzhttp://127.0.0.1:8080zEnginge URLz--engine-backendc                 C   r$   r   r%   r'   r   r   r   r*   h   r+   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   )r0   r1   N)r   r   r   uvicornrun)r"   r   r0   r1   r   r   r   r   r   r   r   r    J   s   4__main__)r   N)$	functoolsr   pathlibr   typingr   Zclickr2   Zfastapir   Z&mistral_common.experimental.app.modelsr   r   r   Z'mistral_common.experimental.app.routersr	   r
   r   Z*mistral_common.protocol.instruct.validatorr   Z(mistral_common.tokens.tokenizers.mistralr   testZ	llama_cppr   intr   groupr   commandargumentZChoicer&   optionr    __name__r   r   r   r   <module>   s    
-	


