11import asyncio
2- import json
32from pathlib import Path
4- from typing import Any , get_args
3+ from typing import get_args
54
65import click
76from pydantic import ValidationError
1211from guidellm .benchmark .scenario import GenerativeTextScenario
1312from guidellm .config import print_config
1413from guidellm .scheduler import StrategyType
14+ from guidellm .utils import cli as cli_tools
1515
1616STRATEGY_PROFILE_CHOICES = set (
1717 list (get_args (ProfileType )) + list (get_args (StrategyType ))
1818)
1919
2020
21- def parse_json (ctx , param , value ): # noqa: ARG001
22- if value is None :
23- return None
24- try :
25- return json .loads (value )
26- except json .JSONDecodeError as err :
27- raise click .BadParameter (f"{ param .name } must be a valid JSON string." ) from err
28-
29-
30- def set_if_not_default (ctx : click .Context , ** kwargs ) -> dict [str , Any ]:
31- """
32- Set the value of a click option if it is not the default value.
33- This is useful for setting options that are not None by default.
34- """
35- values = {}
36- for k , v in kwargs .items ():
37- if ctx .get_parameter_source (k ) != click .core .ParameterSource .DEFAULT :
38- values [k ] = v
39-
40- return values
41-
42-
4321@click .group ()
4422def cli ():
4523 pass
@@ -50,7 +28,10 @@ def cli():
5028)
5129@click .option (
5230 "--scenario" ,
53- type = str ,
31+ type = cli_tools .Union (
32+ click .Path (exists = True , readable = True , file_okay = True , dir_okay = False ),
33+ click .STRING
34+ ),
5435 default = None ,
5536 help = ("TODO: A scenario or path to config" ),
5637)
@@ -70,7 +51,7 @@ def cli():
7051)
7152@click .option (
7253 "--backend-args" ,
73- callback = parse_json ,
54+ callback = cli_tools . parse_json ,
7455 default = GenerativeTextScenario .get_default ("backend_args" ),
7556 help = (
7657 "A JSON string containing any arguments to pass to the backend as a "
@@ -99,7 +80,7 @@ def cli():
9980@click .option (
10081 "--processor-args" ,
10182 default = GenerativeTextScenario .get_default ("processor_args" ),
102- callback = parse_json ,
83+ callback = cli_tools . parse_json ,
10384 help = (
10485 "A JSON string containing any arguments to pass to the processor constructor "
10586 "as a dict with **kwargs."
@@ -117,7 +98,7 @@ def cli():
11798@click .option (
11899 "--data-args" ,
119100 default = GenerativeTextScenario .get_default ("data_args" ),
120- callback = parse_json ,
101+ callback = cli_tools . parse_json ,
121102 help = (
122103 "A JSON string containing any arguments to pass to the dataset creation "
123104 "as a dict with **kwargs."
@@ -218,7 +199,7 @@ def cli():
218199)
219200@click .option (
220201 "--output-extras" ,
221- callback = parse_json ,
202+ callback = cli_tools . parse_json ,
222203 help = "A JSON string of extra data to save with the output benchmarks" ,
223204)
224205@click .option (
@@ -263,7 +244,7 @@ def benchmark(
263244):
264245 click_ctx = click .get_current_context ()
265246
266- overrides = set_if_not_default (
247+ overrides = cli_tools . set_if_not_default (
267248 click_ctx ,
268249 target = target ,
269250 backend_type = backend_type ,
0 commit comments