o
    )iA1                     @   s0  d Z ddlZddlZddl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 ddlmZmZ dd	lmZmZ dd
lmZmZ ddl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j%Z&eeG dd dZ'de"de"fddZ(dej)fddZ*de"fddZ+dS )z
This file contains the command line arguments for the vLLM's
OpenAI-compatible server. It is kept in a separate file for documentation
purposes.
    N)Sequence)field)LiteralOptionalUnion)	dataclass)config)AsyncEngineArgsoptional_type)ChatTemplateContentFormatOptionvalidate_chat_template)H11_MAX_HEADER_COUNT_DEFAULT%H11_MAX_INCOMPLETE_EVENT_SIZE_DEFAULT)LoRAModulePath)ToolParserManager)init_logger)FlexibleArgumentParserc                   @   sB   e Zd Z	ddejdejdeeee	e f  dee fddZ
dS )	LoRAParserActionNparser	namespacevaluesoption_stringc                 C   s   |d u rg }t |trtdg }|D ]b}|dv rqd|v r2d|vr2|d\}}|t|| qzt|}	tdi |	}
||
 W q tjyW   |	d|  Y q tyu } z|	d| dt|  W Y d }~qd }~ww t
|| j| d S )	NzExpected values to be a list)N =,z(Invalid JSON format for --lora-modules: z#Invalid fields for --lora-modules: z -  )
isinstancestr	TypeErrorsplitappendr   jsonloadsJSONDecodeErrorerrorsetattrdest)selfr   r   r   r   Z	lora_listitemnamepathZ	lora_dictZloraer   r   l/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/vllm/entrypoints/openai/cli_args.py__call__#   s4   

zLoRAParserAction.__call__N)__name__
__module____qualname__argparseArgumentParser	Namespacer   r   r   r   r-   r   r   r   r,   r   !   s    r   c                   @   s  e Zd ZU dZdZee ed< 	 dZe	ed< 	 dZ
ee ed< 	 dZed ed	< 	 d
Zeed< 	 d
Zeed< 	 edd dZee ed< 	 edd dZee ed< 	 edd dZee ed< 	 dZeee  ed< 	 dZeee  ed< 	 dZee ed< 	 dZeed< 	 dZeed< 	 dZee ed< 	 dZee ed< 	 dZee ed< 	 d
Zeed< 	 e	e j!Z"e	ed < 	 dZ#ee ed!< 	 ed"d dZ$ee ed#< 	 d
Z%eed$< 	 d
Z&eed%< 	 d
Z'eed&< 	 d
Z(eed'< 	 d
Z)eed(< 	 dZ*ee ed)< 	 d*Z+eed+< 	 dZ,ee ed,< 	 e-j.Z/ee ed-< 	 dZ0ee	 ed.< 	 d
Z1eed/< 	 d
Z2eed0< 	 d
Z3eed1< 	 d
Z4eed2< 	 d
Z5eed3< 	 d
Z6eed4< 	 e7Z8e	ed5< 	 e9Z:e	ed6< 	 e;d7e<d8e<fd9d:Z=dS );FrontendArgsz4Arguments for the OpenAI-compatible frontend server.Nhosti@  portudsinfo)debugr9   warningr$   criticaltraceuvicorn_log_levelFdisable_uvicorn_access_logallow_credentialsc                   C      dgS N*r   r   r   r   r,   <lambda>V       zFrontendArgs.<lambda>)default_factoryallowed_originsc                   C   rA   rB   r   r   r   r   r,   rD   X   rE   allowed_methodsc                   C   rA   rB   r   r   r   r   r,   rD   Z   rE   allowed_headersapi_keylora_moduleschat_templateautochat_template_content_formatZ	assistantresponse_rolessl_keyfilessl_certfilessl_ca_certsenable_ssl_refreshssl_cert_reqs	root_pathc                   C   s   g S r.   r   r   r   r   r,   rD   {   s    
middlewarereturn_tokens_as_token_ids disable_frontend_multiprocessingenable_request_id_headersenable_auto_tool_choice#exclude_tools_when_tool_choice_nonetool_call_parserr   tool_parser_plugintool_serverlog_config_filemax_log_lendisable_fastapi_docsenable_prompt_tokens_detailsenable_server_load_trackingenable_force_include_usageenable_tokenizer_info_endpointenable_log_outputsh11_max_incomplete_event_sizeh11_max_header_countr   returnc                 C   s$  ddl m} |t}tj|d d< tj|d d< tj|d d< |d d= |d d= |d d= tt|d d< t|d d	< d
|d d	< t|d d< d|d v rS|d d= g |d d< tt	j
 }d|}d| d|d d< | jdtjd}| D ]\}}|jd|dd fi | q{| S )Nr   )
get_kwargsrG   typerH   rI   nargsrK   actionr    rV   defaultr   {z,} or name registered in --tool-parser-pluginr\   metavarZFrontend)titledescriptionz--_-)vllm.engine.arg_utilsrj   r5   r!   r"   r
   r   r   listr   Ztool_parserskeysjoinadd_argument_group__doc__itemsadd_argumentreplace)r   rj   Zfrontend_kwargsZvalid_tool_parsersZparsers_strZfrontend_groupkeyvaluer   r   r,   add_cli_args   s4   






"zFrontendArgs.add_cli_args)>r/   r0   r1   rz   r6   r   r   __annotations__r7   intr8   r>   r   r?   boolr@   r   rG   rv   rH   rI   rJ   rK   r   rL   rN   r   rO   rP   rQ   rR   rS   ssl	CERT_NONErT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   envsZVLLM_LOGGING_CONFIG_PATHr_   r`   ra   rb   rc   rd   re   rf   r   rg   r   rh   staticmethodr   r   r   r   r   r,   r5   E   s   
 r5   r   ri   c                 C   s^   | j dtddd | j ddddd	 | j d
dtddd | j ddd t| } t| } | S )a(  Create the CLI argument parser used by the OpenAI API server.

    We rely on the helper methods of `FrontendArgs` and `AsyncEngineArgs` to
    register all arguments instead of manually enumerating them here. This
    avoids code duplication and keeps the argument definitions in one place.
    Z	model_tag?z8The model tag to serve (optional if specified in config))rk   rl   helpz
--headless
store_trueFzRRun in headless mode. See multi-node data parallel documentation for more details.)rm   rn   r   z--api-server-countz-asc   z%How many API server processes to run.)rk   rn   r   z--configzRead CLI options from a config file. Must be a YAML with the following options: https://docs.vllm.ai/en/latest/configuration/serve_args.html)r   )r|   r   r   r5   r   r	   )r   r   r   r,   make_arg_parser   s0   

r   argsc                 C   s>   t | dr| jdkrdS t| j | jr| jstddS dS )z>Quick checks for model serve args that raise prior to loading.	subparserZserveNz<Error: --enable-auto-tool-choice requires --tool-call-parser)hasattrr   r   rL   rZ   r\   r   )r   r   r   r,   validate_parsed_serve_args  s   
r   c                  C   s   t dd} t| S )Nz%-m vllm.entrypoints.openai.api_server)prog)r   r   )Zparser_for_docsr   r   r,   create_parser_for_docs  s   r   ),rz   r2   r!   r   collections.abcr   dataclassesr   typingr   r   r   Zpydantic.dataclassesr   Z	vllm.envsr   Zvllm.configr   ru   r	   r
   Zvllm.entrypoints.chat_utilsr   r   Zvllm.entrypoints.constantsr   r   Z&vllm.entrypoints.openai.serving_modelsr   Z$vllm.entrypoints.openai.tool_parsersr   Zvllm.loggerr   Z
vllm.utilsr   r/   loggerActionr   r5   r   r4   r   r   r   r   r   r,   <module>   s4   $ "