Skip to content

Commit c999325

Browse files
committed
Fix boolean cli flags
1 parent 83764c5 commit c999325

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

llama_cpp/server/__main__.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,31 @@ def contains_list_type(annotation) -> bool:
5858
description = field.description
5959
if field.default is not None and description is not None:
6060
description += f" (default: {field.default})"
61-
parser.add_argument(
62-
f"--{name}",
63-
dest=name,
64-
nargs="*" if contains_list_type(field.annotation) else None,
65-
type=get_base_type(field.annotation) if field.annotation is not None else str,
66-
help=description,
67-
)
61+
base_type = get_base_type(field.annotation) if field.annotation is not None else str
62+
list_type = contains_list_type(field.annotation)
63+
if base_type is not bool:
64+
parser.add_argument(
65+
f"--{name}",
66+
dest=name,
67+
nargs="*" if list_type else None,
68+
type=base_type,
69+
help=description,
70+
)
71+
if base_type is bool:
72+
parser.add_argument(
73+
f"--{name}",
74+
dest=name,
75+
action="store_true",
76+
help=f"Disable {description}",
77+
default=field.default,
78+
)
79+
parser.add_argument(
80+
f"--no-{name}",
81+
dest=name,
82+
action="store_false",
83+
help=f"Disable {description}",
84+
default=field.default,
85+
)
6886

6987
args = parser.parse_args()
7088
settings = Settings(**{k: v for k, v in vars(args).items() if v is not None})

0 commit comments

Comments
 (0)