o
    
۾iE9                     @   s  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
 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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)AnyLiteral)config)AsyncEngineArgsoptional_type)ChatTemplateContentFormatOptionvalidate_chat_template)H11_MAX_HEADER_COUNT_DEFAULT%H11_MAX_INCOMPLETE_EVENT_SIZE_DEFAULT)LoRAModulePath)init_logger)ToolParserManager)FlexibleArgumentParserc                
   @   s>   e Zd Z	ddejdejdeee B dB dedB 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   	lora_listitemnamepath	lora_dictloraer   r   T/home/ubuntu/.local/lib/python3.10/site-packages/vllm/entrypoints/openai/cli_args.py__call__$   s0   

zLoRAParserAction.__call__N)	__name__
__module____qualname__argparseArgumentParser	Namespacer   r   r.   r   r   r   r-   r   #   s    r   c                   @   sP  e Zd ZU dZdZedB ed< 	 dZeed< 	 dZ	edB ed< 	 dZ
ed ed	< 	 d
Zeed< 	 dZedB 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 dB ed< 	 dZee dB ed< 	 dZedB ed< 	 dZeed< 	 d
Zeed< 	 dZeeef dB ed< 	 dZeed< 	 dZ edB ed< 	 dZ!edB ed < 	 dZ"edB ed!< 	 d
Z#eed"< 	 ee$j%Z&eed#< 	 dZ'edB ed$< 	 dZ(edB 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dB ed-< 	 d.Z0eed/< 	 dZ1edB ed0< 	 e2j3Z4edB ed1< 	 dZ5edB ed2< 	 d
Z6eed3< 	 d
Z7eed4< 	 d
Z8eed5< 	 d
Z9eed6< 	 d
Z:eed7< 	 d
Z;eed8< 	 d9Z<eed:< 	 e=Z>eed;< 	 e?Z@eed<< 	 e2jAZBeed=< 	 d
ZCeed>< 	 d
ZDeed?< 	 eEd@eFdAeFfdBdCZGdS )DFrontendArgsz4Arguments for the OpenAI-compatible frontend server.Nhosti@  portudsinfo)criticalr"   warningr:   debugtraceuvicorn_log_levelFdisable_uvicorn_access_log disable_access_log_for_endpointsallow_credentialsc                   C      dgS N*r   r   r   r   r-   <lambda>]       zFrontendArgs.<lambda>)default_factoryallowed_originsc                   C   rC   rD   r   r   r   r   r-   rF   _   rG   allowed_methodsc                   C   rC   rD   r   r   r   r   r-   rF   a   rG   allowed_headersapi_keylora_moduleschat_templateautochat_template_content_formattrust_request_chat_templatedefault_chat_template_kwargs	assistantresponse_rolessl_keyfilessl_certfilessl_ca_certsenable_ssl_refreshssl_cert_reqsssl_ciphers	root_pathc                   C   s   g S r/   r   r   r   r   r-   rF      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_outputsTenable_log_deltash11_max_incomplete_event_sizeh11_max_header_countlog_error_stacktokens_onlyenable_offline_docsr   returnc                 C   sF  ddl m} |t}tj|d d< tj|d d< tj|d d< |d d= |d d= |d d= tj|d d< tt|d	 d< t|d	 d
< d|d d
< t|d d< d|d v rZ|d d= g |d d< d|d v rk|d d= tt	
 }d|}d| d|d d< | jdtjd}| D ]\}}|jd|dd fi | q| S )Nr   )
get_kwargsrI   typerJ   rK   nargsrR   rM   actionr   r\   defaultrA   r   {z,} or name registered in --tool-parser-pluginrb   metavarFrontend)titledescriptionz--_-)vllm.engine.arg_utilsrt   r6   r   r    r   r   r   listr   list_registeredjoinadd_argument_group__doc__itemsadd_argumentreplace)r   rt   frontend_kwargsvalid_tool_parsersparsers_strfrontend_groupkeyvaluer   r   r-   add_cli_args   s:   







"zFrontendArgs.add_cli_args)Hr0   r1   r2   r   r7   r   __annotations__r8   intr9   r?   r   r@   boolrA   rB   r   rI   r   rJ   rK   rL   rM   r   rN   rP   r	   rQ   rR   dictr   rT   rU   rV   rW   rX   ssl	CERT_NONErY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   envsVLLM_LOGGING_CONFIG_PATHre   rf   rg   rh   ri   rj   rk   rl   rm   r   rn   r   ro   VLLM_SERVER_DEV_MODErp   rq   rr   staticmethodr   r   r   r   r   r-   r6   E   s   
 r6   r   rs   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.
    	model_tag?z8The model tag to serve (optional if specified in config))ru   rv   helpz
--headless
store_trueFzRRun in headless mode. See multi-node data parallel documentation for more details.)rw   rx   r   z--api-server-countz-ascNzVHow many API server processes to run. Defaults to data_parallel_size if not specified.)ru   rx   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   r6   r   r   )r   r   r   r-   make_arg_parser  s4   

r   argsc                 C   sR   t | dr| jdkrdS t| j | jr| jstd| jr%| js'tddS dS )z>Quick checks for model serve args that raise prior to loading.	subparserserveNz<Error: --enable-auto-tool-choice requires --tool-call-parserz:Error: --enable-log-outputs requires --enable-log-requests)	hasattrr   r
   rN   r`   rb   r   rl   enable_log_requests)r   r   r   r-   validate_parsed_serve_args9  s   
r   c                  C   s   t dd} t| S )Nz%-m vllm.entrypoints.openai.api_server)prog)r   r   )parser_for_docsr   r   r-   create_parser_for_docsH  s   r   ))r   r3   r   r   collections.abcr   dataclassesr   typingr   r   	vllm.envsr   vllm.configr   r   r   r   vllm.entrypoints.chat_utilsr	   r
   vllm.entrypoints.constantsr   r   'vllm.entrypoints.openai.models.protocolr   vllm.loggerr   vllm.tool_parsersr   vllm.utils.argparse_utilsr   r0   loggerActionr   r6   r   r5   r   r   r   r   r   r-   <module>   s0   " L(