| """ | |
| 独立的API服务器启动脚本 | |
| 可以直接运行此脚本启动API服务器,无需通过main.py | |
| """ | |
| import sys | |
| from pathlib import Path | |
| import uvicorn | |
| # 添加项目根目录到Python路径 | |
| project_root = Path(__file__).parent.parent | |
| sys.path.insert(0, str(project_root)) | |
| # 加载第三方库 | |
| from config.paths import load_third_party | |
| load_third_party() | |
| def run_server(host: str = "0.0.0.0", port: int = 8000, reload: bool = False): | |
| """运行API服务器""" | |
| print(f""" | |
| {"=" * 80} | |
| VoiceDialogue API Server | |
| {"=" * 80} | |
| 服务器地址: http://{host}:{port} | |
| API文档: http://{host}:{port}/docs | |
| ReDoc文档: http://{host}:{port}/redoc | |
| 热重载: {'启用' if reload else '禁用'} | |
| {"=" * 80} | |
| """) | |
| uvicorn.run( | |
| "api.app:app", | |
| host=host, | |
| port=port, | |
| reload=reload, | |
| log_level="info", | |
| access_log=True | |
| ) | |
| if __name__ == "__main__": | |
| import argparse | |
| parser = argparse.ArgumentParser(description="VoiceDialogue API服务器") | |
| parser.add_argument("--host", default="0.0.0.0", help="服务器主机地址") | |
| parser.add_argument("--port", "-p", type=int, default=8000, help="服务器端口") | |
| parser.add_argument("--reload", action="store_true", help="启用热重载") | |
| args = parser.parse_args() | |
| run_server(args.host, args.port, args.reload) | |