Skip to content

Commit 44a668b

Browse files
committed
Address feedback
Signed-off-by: Samuel Monson <[email protected]>
1 parent 2ea52aa commit 44a668b

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

src/guidellm/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ def benchmark():
386386
)
387387
@click.option(
388388
"--over-saturation",
389-
"--detect-saturation", # alias
390389
"over_saturation",
391390
callback=cli_tools.parse_json,
392391
default=None,
@@ -398,9 +397,11 @@ def benchmark():
398397
),
399398
)
400399
@click.option(
400+
"--detect-saturation",
401401
"--default-over-saturation",
402402
"over_saturation",
403-
flag_value={"enabled": True},
403+
callback=cli_tools.parse_json,
404+
flag_value='{"enabled": true}',
404405
help="Enable over-saturation detection with default settings.",
405406
)
406407
def run(**kwargs): # noqa: C901

src/guidellm/scheduler/constraints/request.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
from pydantic import Field, field_validator
1515

16+
from guidellm.scheduler.constraints.constraint import (
17+
Constraint,
18+
PydanticConstraintInitializer,
19+
)
20+
from guidellm.scheduler.constraints.factory import ConstraintsInitializerFactory
1621
from guidellm.scheduler.schemas import (
1722
SchedulerProgress,
1823
SchedulerState,
@@ -21,9 +26,6 @@
2126
from guidellm.schemas import RequestInfo, StandardBaseModel
2227
from guidellm.utils import InfoMixin
2328

24-
from .constraint import Constraint, PydanticConstraintInitializer
25-
from .factory import ConstraintsInitializerFactory
26-
2729
__all__ = [
2830
"MaxDurationConstraint",
2931
"MaxNumberConstraint",

src/guidellm/utils/cli.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,18 @@ def parse_list_floats(ctx, param, value):
7777
) from err
7878

7979

80-
def parse_json(ctx, param, value): # noqa: ARG001, C901, PLR0911, PLR0912
80+
def parse_json(ctx, param, value): # noqa: ARG001, C901, PLR0911
81+
if isinstance(value, dict):
82+
return value
83+
8184
if value is None or value == [None]:
8285
return None
83-
if isinstance(value, dict | list):
84-
# Already parsed (e.g., from flag_value), return as-is
85-
return value
86-
if isinstance(value, list | tuple):
87-
return [parse_json(ctx, param, val) for val in value]
8886

89-
# Handle empty strings (can occur when multiple options map to same parameter)
9087
if isinstance(value, str) and not value.strip():
9188
return None
9289

93-
# Handle string representation of dict (can occur when flag_value dict is
94-
# converted to string)
95-
if isinstance(value, str) and value.startswith("{") and value.endswith("}"):
96-
# Try to parse as JSON first
97-
try:
98-
return json.loads(value)
99-
except json.JSONDecodeError:
100-
# If JSON parsing fails, try ast.literal_eval for Python dict syntax
101-
try:
102-
import ast
103-
104-
parsed = ast.literal_eval(value)
105-
if isinstance(parsed, dict):
106-
return parsed
107-
except (ValueError, SyntaxError):
108-
pass # Fall through to normal processing
90+
if isinstance(value, list | tuple):
91+
return [parse_json(ctx, param, val) for val in value]
10992

11093
if "{" not in value and "}" not in value and "=" in value:
11194
# Treat it as a key=value pair if it doesn't look like JSON.

0 commit comments

Comments
 (0)