| #!/usr/bin/env python | |
| """API 模块 | |
| 定义 Connexion 应用和 API 函数,供 server.yaml 引用。 | |
| """ | |
| import os | |
| from workaround_env_fix import diagnose_and_fix_thread_env_vars | |
| # 放此处:server 为应用入口(run.py 或 gunicorn 均会加载),须在 import connexion/backend 前执行 | |
| diagnose_and_fix_thread_env_vars() | |
| os.environ["TOKENIZERS_PARALLELISM"] = "false" | |
| import connexion | |
| from backend.logging_config import configure_logging | |
| from backend.api.static import register_static_routes | |
| # 导入 API 函数供 server.yaml 使用 | |
| from backend.api.analyze import analyze # noqa: F401 | |
| from backend.api.demo import ( # noqa: F401 | |
| list_demos, | |
| save_demo, | |
| delete_demo, | |
| move_demo, | |
| rename_demo, | |
| check_admin, | |
| ) | |
| from backend.api.folder import ( # noqa: F401 | |
| rename_folder_api as rename_folder, | |
| delete_folder_api as delete_folder, | |
| list_all_folders, | |
| create_folder_api, | |
| ) | |
| from backend.api.fetch_url import fetch_url # noqa: F401 | |
| from backend.api.model_switch import ( # noqa: F401 | |
| get_available_models, | |
| get_current_model, | |
| switch_model, | |
| ) | |
| # 创建 Connexion 应用 | |
| app = connexion.App(__name__) | |
| # 配置日志 | |
| configure_logging(app) | |
| # 注册路由 | |
| register_static_routes(app) | |
| app.add_api('server.yaml') | |