From 0eb1d3ed500932d4897004529d9dc2ec7a1b2a78 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 25 Nov 2024 16:35:58 +0100 Subject: [PATCH] Fix start api without port argument --- g4f/api/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py index a899251b0a9..01c75daeb6d 100644 --- a/g4f/api/__init__.py +++ b/g4f/api/__init__.py @@ -48,6 +48,8 @@ class Annotated: logger = logging.getLogger(__name__) +DEFAULT_PORT = 1337 + def create_app(g4f_api_key: str = None): app = FastAPI() @@ -493,7 +495,7 @@ def format_exception(e: Union[Exception, str], config: Union[ChatCompletionsConf def run_api( host: str = '0.0.0.0', - port: int = 1337, + port: int = None, bind: str = None, debug: bool = False, workers: int = None, @@ -505,6 +507,8 @@ def run_api( use_colors = debug if bind is not None: host, port = bind.split(":") + if port is None: + port = DEFAULT_PORT uvicorn.run( f"g4f.api:create_app{'_debug' if debug else ''}", host=host,