| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.R; |
| | | import com.zy.ai.entity.AiAutoTuneJob; |
| | | import com.zy.ai.entity.AiChatSession; |
| | | import com.zy.ai.entity.LlmCallLog; |
| | | import com.zy.ai.entity.LlmRouteConfig; |
| | | import com.zy.ai.enums.AiPromptScene; |
| | | import com.zy.ai.mapper.AiChatSessionMapper; |
| | | import com.zy.ai.service.AiAutoTuneJobService; |
| | | import com.zy.ai.service.LlmCallLogService; |
| | | import com.zy.ai.service.LlmRouteConfigService; |
| | | import com.zy.asrs.entity.*; |
| | |
| | | private LlmRouteConfigService llmRouteConfigService; |
| | | @Autowired |
| | | private LlmCallLogService llmCallLogService; |
| | | @Autowired |
| | | private AiAutoTuneJobService aiAutoTuneJobService; |
| | | @Autowired |
| | | private AiChatSessionMapper aiChatSessionMapper; |
| | | @Autowired |
| | |
| | | long completionTokenTotal = 0L; |
| | | long askCount = 0L; |
| | | long sessionCount = 0L; |
| | | long autoTunePromptTokenTotal = 0L; |
| | | long autoTuneCompletionTokenTotal = 0L; |
| | | long autoTuneTokenTotal = 0L; |
| | | try { |
| | | List<AiChatSession> sessions = aiChatSessionMapper.selectList(new QueryWrapper<AiChatSession>() |
| | | .select("id", "sum_prompt_tokens", "sum_completion_tokens", "sum_total_tokens", "ask_count")); |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("dashboard ai session stats load failed: {}", safeMessage(e)); |
| | | } |
| | | |
| | | try { |
| | | List<Map<String, Object>> autoTuneRows = aiAutoTuneJobService.listMaps(new QueryWrapper<AiAutoTuneJob>() |
| | | .select("COALESCE(SUM(prompt_tokens), 0) AS prompt_token_total", |
| | | "COALESCE(SUM(completion_tokens), 0) AS completion_token_total", |
| | | "COALESCE(SUM(total_tokens), 0) AS token_total") |
| | | .eq("prompt_scene_code", AiPromptScene.AUTO_TUNE_DISPATCH.getCode())); |
| | | Map<String, Object> autoTuneRow = autoTuneRows == null || autoTuneRows.isEmpty() |
| | | ? Collections.emptyMap() |
| | | : autoTuneRows.get(0); |
| | | autoTunePromptTokenTotal = toLong(autoTuneRow.get("prompt_token_total")); |
| | | autoTuneCompletionTokenTotal = toLong(autoTuneRow.get("completion_token_total")); |
| | | autoTuneTokenTotal = toLong(autoTuneRow.get("token_total")); |
| | | |
| | | // Agent 自动调参不生成 sys_ai_chat_session,会单独落到 sys_ai_auto_tune_job。 |
| | | promptTokenTotal += autoTunePromptTokenTotal; |
| | | completionTokenTotal += autoTuneCompletionTokenTotal; |
| | | tokenTotal += autoTuneTokenTotal; |
| | | } catch (Exception e) { |
| | | log.warn("dashboard ai auto tune token stats load failed: {}", safeMessage(e)); |
| | | } |
| | | |
| | | List<LlmRouteConfig> routes = Collections.emptyList(); |
| | |
| | | overview.put("tokenTotal", tokenTotal); |
| | | overview.put("promptTokenTotal", promptTokenTotal); |
| | | overview.put("completionTokenTotal", completionTokenTotal); |
| | | overview.put("autoTuneTokenTotal", autoTuneTokenTotal); |
| | | overview.put("autoTunePromptTokenTotal", autoTunePromptTokenTotal); |
| | | overview.put("autoTuneCompletionTokenTotal", autoTuneCompletionTokenTotal); |
| | | overview.put("askCount", askCount); |
| | | overview.put("sessionCount", sessionCount); |
| | | overview.put("routeTotal", routeTotal); |