From c999325e8e4507f6c6249dd2fb8de7f8bf57f71e Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Wed, 13 Sep 2023 22:56:10 -0400 Subject: [PATCH] Fix boolean cli flags --- llama_cpp/server/__main__.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/llama_cpp/server/__main__.py b/llama_cpp/server/__main__.py index 7c1b9f4..03691cf 100644 --- a/llama_cpp/server/__main__.py +++ b/llama_cpp/server/__main__.py @@ -58,13 +58,31 @@ if __name__ == "__main__": description = field.description if field.default is not None and description is not None: description += f" (default: {field.default})" - parser.add_argument( - f"--{name}", - dest=name, - nargs="*" if contains_list_type(field.annotation) else None, - type=get_base_type(field.annotation) if field.annotation is not None else str, - help=description, - ) + base_type = get_base_type(field.annotation) if field.annotation is not None else str + list_type = contains_list_type(field.annotation) + if base_type is not bool: + parser.add_argument( + f"--{name}", + dest=name, + nargs="*" if list_type else None, + type=base_type, + help=description, + ) + if base_type is bool: + parser.add_argument( + f"--{name}", + dest=name, + action="store_true", + help=f"Disable {description}", + default=field.default, + ) + parser.add_argument( + f"--no-{name}", + dest=name, + action="store_false", + help=f"Disable {description}", + default=field.default, + ) args = parser.parse_args() settings = Settings(**{k: v for k, v in vars(args).items() if v is not None})