Junjie
7 天以前 bcabde8bfb8f16671fa5937e62668f99210e0720
#Agent自动调参
1个文件已修改
32 ■■■■■ 已修改文件
src/main/java/com/zy/system/controller/DashboardController.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/system/controller/DashboardController.java
@@ -3,10 +3,13 @@
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.*;
@@ -58,6 +61,8 @@
    private LlmRouteConfigService llmRouteConfigService;
    @Autowired
    private LlmCallLogService llmCallLogService;
    @Autowired
    private AiAutoTuneJobService aiAutoTuneJobService;
    @Autowired
    private AiChatSessionMapper aiChatSessionMapper;
    @Autowired
@@ -327,6 +332,9 @@
        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"));
@@ -341,6 +349,27 @@
            }
        } 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();
@@ -415,6 +444,9 @@
        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);