From 4f85d02294b607e94be99fcf0c34b395ef368586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20=C4=90=E1=BB=A9c=20M=E1=BA=A1nh?= Date: Tue, 11 Feb 2025 00:06:30 +0700 Subject: [PATCH 1/2] Update cli.py --- g4f/cli.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/g4f/cli.py b/g4f/cli.py index 5bb5c460b28..c613876b468 100644 --- a/g4f/cli.py +++ b/g4f/cli.py @@ -29,6 +29,10 @@ def get_api_parser(): default=[], help="List of browsers to access or retrieve cookies from. (incompatible with --reload and --workers)") api_parser.add_argument("--reload", action="store_true", help="Enable reloading.") api_parser.add_argument("--demo", action="store_true", help="Enable demo mode.") + + api_parser.add_argument("--ssl-keyfile", type=str, default=None, help="Path to SSL key file for HTTPS.") + api_parser.add_argument("--ssl-certfile", type=str, default=None, help="Path to SSL certificate file for HTTPS.") + return api_parser def main(): @@ -68,7 +72,9 @@ def run_api_args(args): debug=args.debug, workers=args.workers, use_colors=not args.disable_colors, - reload=args.reload + reload=args.reload, + ssl_keyfile=args.ssl_keyfile, + ssl_certfile=args.ssl_certfile ) if __name__ == "__main__": From f2d176ccc698159b8574e8ac5f1d8429a666011c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20=C4=90=E1=BB=A9c=20M=E1=BA=A1nh?= Date: Tue, 11 Feb 2025 00:06:52 +0700 Subject: [PATCH 2/2] Update __init__.py --- g4f/api/__init__.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py index b209f0ec92b..e2f786baa2b 100644 --- a/g4f/api/__init__.py +++ b/g4f/api/__init__.py @@ -629,27 +629,36 @@ def run_api( debug: bool = False, workers: int = None, use_colors: bool = None, - reload: bool = False + reload: bool = False, + ssl_keyfile: str = None, + ssl_certfile: str = None ) -> None: print(f'Starting server... [g4f v-{g4f.version.utils.current_version}]' + (" (debug)" if debug else "")) + if use_colors is None: use_colors = debug + if bind is not None: host, port = bind.split(":") + if port is None: port = DEFAULT_PORT + if AppConfig.demo and debug: method = "create_app_with_demo_and_debug" elif AppConfig.gui and debug: method = "create_app_with_gui_and_debug" else: method = "create_app_debug" if debug else "create_app" + uvicorn.run( - f"g4f.api:{method}", - host=host, - port=int(port), - workers=workers, - use_colors=use_colors, - factory=True, - reload=reload - ) \ No newline at end of file + f"g4f.api:{method}", + host=host, + port=int(port), + workers=workers, + use_colors=use_colors, + factory=True, + reload=reload, + ssl_keyfile=ssl_keyfile, + ssl_certfile=ssl_certfile + )