1616sys .modules ["vllm._C" ] = MagicMock ()
1717
1818from vllm .engine .arg_utils import AsyncEngineArgs , EngineArgs # noqa: E402
19+ from vllm .entrypoints .openai .cli_args import make_arg_parser # noqa: E402
1920from vllm .utils import FlexibleArgumentParser # noqa: E402
2021
2122logger = logging .getLogger ("mkdocs" )
2425class MarkdownFormatter (HelpFormatter ):
2526 """Custom formatter that generates markdown for argument groups."""
2627
27- def __init__ (self , prog ):
28+ def __init__ (self , prog , starting_heading_level = 3 ):
2829 super ().__init__ (prog ,
2930 max_help_position = float ('inf' ),
3031 width = float ('inf' ))
32+ self ._section_heading_prefix = "#" * starting_heading_level
33+ self ._argument_heading_prefix = "#" * (starting_heading_level + 1 )
3134 self ._markdown_output = []
3235
3336 def start_section (self , heading ):
3437 if heading not in {"positional arguments" , "options" }:
35- self ._markdown_output .append (f"\n ### { heading } \n \n " )
38+ heading_md = f"\n { self ._section_heading_prefix } { heading } \n \n "
39+ self ._markdown_output .append (heading_md )
3640
3741 def end_section (self ):
3842 pass
@@ -46,9 +50,13 @@ def add_usage(self, usage, actions, groups, prefix=None):
4650
4751 def add_arguments (self , actions ):
4852 for action in actions :
53+ if (len (action .option_strings ) == 0
54+ or "--help" in action .option_strings ):
55+ continue
4956
5057 option_strings = f'`{ "`, `" .join (action .option_strings )} `'
51- self ._markdown_output .append (f"#### { option_strings } \n \n " )
58+ heading_md = f"{ self ._argument_heading_prefix } { option_strings } \n \n "
59+ self ._markdown_output .append (heading_md )
5260
5361 if choices := action .choices :
5462 choices = f'`{ "`, `" .join (str (c ) for c in choices )} `'
@@ -81,6 +89,14 @@ def create_parser(cls, **kwargs) -> FlexibleArgumentParser:
8189 return cls .add_cli_args (parser , ** kwargs )
8290
8391
92+ def create_serve_parser () -> FlexibleArgumentParser :
93+ """Create a parser for the serve command with markdown formatting."""
94+ parser = FlexibleArgumentParser ()
95+ parser .formatter_class = lambda prog : MarkdownFormatter (
96+ prog , starting_heading_level = 4 )
97+ return make_arg_parser (parser )
98+
99+
84100def on_startup (command : Literal ["build" , "gh-deploy" , "serve" ], dirty : bool ):
85101 logger .info ("Generating argparse documentation" )
86102 logger .debug ("Root directory: %s" , ROOT_DIR .resolve ())
@@ -95,6 +111,7 @@ def on_startup(command: Literal["build", "gh-deploy", "serve"], dirty: bool):
95111 "engine_args" : create_parser (EngineArgs ),
96112 "async_engine_args" : create_parser (AsyncEngineArgs ,
97113 async_args_only = True ),
114+ "serve" : create_serve_parser (),
98115 }
99116
100117 # Generate documentation for each parser
0 commit comments