feat(ai): Phase 1A 收尾 — 用量记录 + 健康摘要端点 + 小程序组件
- chat_handler 添加 log_usage 精确记录 token 消耗(provider + model) - SSE build_sse_stream 添加估算 token 用量记录(4 字符 ≈ 1 token) - 新增 GET /ai/health-summary 端点聚合患者洞察+分析记录 - 小程序 AiHealthSummaryCard 组件(风险等级+洞察统计+摘要列表) - 小程序 services/ai-analysis 新增 getHealthSummary API
This commit is contained in:
@@ -144,6 +144,8 @@ where
|
||||
"AI Agent chat request"
|
||||
);
|
||||
|
||||
let provider_name = provider_arc.name().to_string();
|
||||
|
||||
// 执行 Agent ReAct 循环
|
||||
let orchestrator = AgentOrchestrator::new(provider_arc, std::sync::Arc::new(registry));
|
||||
let result = orchestrator
|
||||
@@ -170,6 +172,25 @@ where
|
||||
"AI Agent response sent"
|
||||
);
|
||||
|
||||
// 记录用量的 token 消耗
|
||||
if let Err(e) = ai_state
|
||||
.usage
|
||||
.log_usage(
|
||||
ctx.tenant_id,
|
||||
&provider_name,
|
||||
&run_params.model,
|
||||
"chat",
|
||||
result.total_input_tokens as u32,
|
||||
result.total_output_tokens as u32,
|
||||
0,
|
||||
0,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::warn!(error = %e, "Failed to log chat usage");
|
||||
}
|
||||
|
||||
Ok(Json(ApiResponse::ok(ChatResponse {
|
||||
reply: result.reply,
|
||||
message_id,
|
||||
|
||||
Reference in New Issue
Block a user