diff --git a/README.md b/README.md index 5ad6ea4..34ec76e 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,11 @@ OPENAI_BASE_URL: https://open.bigmodel.cn/api/paas/v4/ OPENAI_API_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx OPENAI_MODEL: glm-4.7 +# Server configuration +# Only used in router mode (python main.py) or standalone mode (python standalone.py) +# Default: 8000 +PORT: 8000 + # Root directory for all project sessions (absolute path) # Only used in standalone mode (python standalone.py) # In router mode (python main.py), this field is ignored diff --git a/config.py b/config.py index 67e717c..d48f123 100644 --- a/config.py +++ b/config.py @@ -23,6 +23,9 @@ METASO_API_KEY: str = _cfg.get("METASO_API_KEY", "") ROUTER_MODE: bool = _cfg.get("ROUTER_MODE", False) ROUTER_SECRET: str = _cfg.get("ROUTER_SECRET", "") +# Server configuration +PORT: int = _cfg.get("PORT", 8000) + _allowed_open_ids_raw = _cfg.get("ALLOWED_OPEN_IDS", []) ALLOWED_OPEN_IDS: list[str] = _allowed_open_ids_raw if isinstance(_allowed_open_ids_raw, list) else [str(_allowed_open_ids_raw)] diff --git a/keyring.example.yaml b/keyring.example.yaml index 30e7983..bd64b49 100644 --- a/keyring.example.yaml +++ b/keyring.example.yaml @@ -1,3 +1,11 @@ +# Server configuration +# Only used in router mode (python main.py) or standalone mode (python standalone.py) +# Default: 8000 +PORT: 8000 + +# Root directory for all project sessions (absolute path) +# Only used in standalone mode (python standalone.py) +# In router mode (python main.py), this field is ignored WORKING_DIR: "/path/to/working/directory" FEISHU_APP_ID: your_feishu_app_id FEISHU_APP_SECRET: your_feishu_app_secret diff --git a/main.py b/main.py index e8535d9..cfad67b 100644 --- a/main.py +++ b/main.py @@ -105,10 +105,11 @@ async def shutdown_event() -> None: if __name__ == "__main__": + from config import PORT uvicorn.run( "main:app", host="0.0.0.0", - port=8000, + port=PORT, reload=False, log_level="info", ws_ping_interval=20, diff --git a/standalone.py b/standalone.py index eb5e8cd..4637ccb 100644 --- a/standalone.py +++ b/standalone.py @@ -24,7 +24,8 @@ logger = logging.getLogger(__name__) async def run_standalone() -> None: """Run router + host client in a single process.""" secret = secrets.token_hex(16) - router_url = "ws://127.0.0.1:8000/ws/node" + from config import PORT + router_url = f"ws://127.0.0.1:{PORT}/ws/node" from router.main import create_app from host_client.main import NodeClient @@ -34,12 +35,15 @@ async def run_standalone() -> None: config.router_url = router_url config.router_secret = secret + import uvicorn + from config import PORT + app = create_app(router_secret=secret) config_obj = uvicorn.Config( app, host="0.0.0.0", - port=8000, + port=PORT, log_level="info", ws_ping_interval=20, ws_ping_timeout=60,