feat:LLM 分析文件并生成结构化建议

This commit is contained in:
2026-10-10 04:56:28 -07:00
parent 7caf0d31da
commit b90842237f
11 changed files with 746 additions and 7 deletions
+7 -1
View File
@@ -23,6 +23,7 @@ async def lifespan(application: FastAPI):
from app.clients.decision import close_decision_engine
from app.clients.mcp import start_mcp_servers, stop_mcp_servers
from app.clients.user_center import close_user_center
from app.datafiles.insights import generate_insights, insights_enabled
from app.datafiles.service import DataFileService
from app.datafiles.storage import open_data_file_store
from app.observability.tracing import flush_tracing
@@ -36,10 +37,13 @@ async def lifespan(application: FastAPI):
application.state.conversation_store = persistence.store
mcp_processes = []
sweeper = None
data_files = None
try:
# 数据文件的元数据和会话记录用同一种存储;启动时先清理一遍过期目录,之后每小时一次
data_files = DataFileService(
await open_data_file_store(persistence.db), persistence.store
await open_data_file_store(persistence.db),
persistence.store,
insights=generate_insights if insights_enabled() else None,
)
application.state.data_file_service = data_files
sweeper = asyncio.create_task(data_files.run_sweeper())
@@ -59,6 +63,8 @@ async def lifespan(application: FastAPI):
finally:
if sweeper is not None:
sweeper.cancel()
if data_files is not None:
await data_files.aclose()
# 共享客户端只在应用退出时关闭,追踪刷新放到线程避免阻塞事件循环
try:
await stop_mcp_servers(mcp_processes)