refactor : FastAPI 懒加载单例,消除模块级副作用

- import astrai.inference 不再在模块加载时创建 FastAPI 实例
- 路由移至 APIRouter;get_app() 首次调用时懒构造单例
- _create_engine 和 run_server 的 param_path 改为必填
- 更新测试改用 get_app() 替代模块级 app
This commit is contained in:
2026-06-04 15:52:27 +08:00
parent b36a78c612
commit dc7d2cfbca
5 changed files with 54 additions and 31 deletions
+7 -3
View File
@@ -1,4 +1,8 @@
"""Inference API: protocol handler, stop checker, and FastAPI server."""
"""Inference API: protocol handler, stop checker, and FastAPI server.
``app`` is no longer a module-level global. Use :func:`get_app` to access the
lazy singleton FastAPI instance.
"""
from astrai.inference.api.protocol import GenContext, ProtocolHandler, StopChecker
from astrai.inference.api.server import (
@@ -6,7 +10,7 @@ from astrai.inference.api.server import (
ChatCompletionRequest,
ChatMessage,
MessagesRequest,
app,
get_app,
run_server,
)
@@ -18,6 +22,6 @@ __all__ = [
"ChatCompletionRequest",
"ChatMessage",
"MessagesRequest",
"app",
"get_app",
"run_server",
]