feat(api): 增加 LLM 统计路由

将 LLM 使用情况统计的 API 路由注册到主应用程序中,以便通过 `/api/statistic` 路径访问相关统计数据。
This commit is contained in:
minecraft1024a
2025-10-25 14:27:08 +08:00
committed by Windpicker-owo
parent a234e0b8aa
commit e44a6987f0
2 changed files with 119 additions and 2 deletions

View File

@@ -6,7 +6,7 @@ import time
import traceback
from functools import partial
from random import choices
from typing import Any
from typing import Any, Callable, Coroutine
from maim_message import MessageServer
from rich.traceback import install
@@ -401,8 +401,10 @@ MoFox_Bot(第三方修改版)
# 注册API路由
try:
from src.api.message_router import router as message_router
from src.api.statistic_router import router as llm_statistic_router
self.server.register_router(message_router, prefix="/api")
self.server.register_router(llm_statistic_router, prefix="/api")
logger.info("API路由注册成功")
except Exception as e:
logger.error(f"注册API路由失败: {e}")
@@ -517,7 +519,7 @@ MoFox_Bot(第三方修改版)
except Exception as e:
logger.error(f"日程表管理器初始化失败: {e}")
def _safe_init(self, component_name: str, init_func) -> callable:
def _safe_init(self, component_name: str, init_func) -> "Callable[[], Coroutine[Any, Any, bool]]":
"""安全初始化组件,捕获异常"""
async def wrapper():