| | |
| | | package com.zy.ai.controller; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.R; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | |
| | | @GetMapping("/list/auth") |
| | | @ManagerAuth |
| | | public R list() { |
| | | EntityWrapper<LlmRouteConfig> wrapper = new EntityWrapper<>(); |
| | | wrapper.orderBy("priority", true).orderBy("id", true); |
| | | List<LlmRouteConfig> list = llmRouteConfigService.selectList(wrapper); |
| | | QueryWrapper<LlmRouteConfig> wrapper = new QueryWrapper<>(); |
| | | wrapper.orderBy(true, true, "priority").orderBy(true, true, "id"); |
| | | List<LlmRouteConfig> list = llmRouteConfigService.list(wrapper); |
| | | return R.ok(list); |
| | | } |
| | | |
| | |
| | | |
| | | if (config.getId() == null) { |
| | | llmRoutingService.fillAndNormalize(config, true); |
| | | llmRouteConfigService.insert(config); |
| | | llmRouteConfigService.save(config); |
| | | } else { |
| | | LlmRouteConfig db = llmRouteConfigService.selectById(config.getId()); |
| | | LlmRouteConfig db = llmRouteConfigService.getById(config.getId()); |
| | | if (db == null) { |
| | | return R.error("配置不存在"); |
| | | } |
| | |
| | | if (id == null) { |
| | | return R.error("id不能为空"); |
| | | } |
| | | llmRouteConfigService.deleteById(id); |
| | | llmRouteConfigService.removeById(id); |
| | | llmRoutingService.evictCache(); |
| | | return R.ok(); |
| | | } |
| | |
| | | if (id == null) { |
| | | return R.error("id不能为空"); |
| | | } |
| | | LlmRouteConfig cfg = llmRouteConfigService.selectById(id); |
| | | LlmRouteConfig cfg = llmRouteConfigService.getById(id); |
| | | if (cfg == null) { |
| | | return R.error("配置不存在"); |
| | | } |
| | |
| | | } |
| | | Map<String, Object> data = llmRoutingService.testRoute(config); |
| | | if (Boolean.TRUE.equals(data.get("ok")) && config.getId() != null) { |
| | | LlmRouteConfig db = llmRouteConfigService.selectById(config.getId()); |
| | | LlmRouteConfig db = llmRouteConfigService.getById(config.getId()); |
| | | if (db != null) { |
| | | db.setCooldownUntil(null); |
| | | db.setConsecutiveFailCount(0); |
| | |
| | | @GetMapping("/export/auth") |
| | | @ManagerAuth |
| | | public R exportConfig() { |
| | | EntityWrapper<LlmRouteConfig> wrapper = new EntityWrapper<>(); |
| | | wrapper.orderBy("priority", true).orderBy("id", true); |
| | | List<LlmRouteConfig> list = llmRouteConfigService.selectList(wrapper); |
| | | QueryWrapper<LlmRouteConfig> wrapper = new QueryWrapper<>(); |
| | | wrapper.orderBy(true, true, "priority").orderBy(true, true, "id"); |
| | | List<LlmRouteConfig> list = llmRouteConfigService.list(wrapper); |
| | | List<Map<String, Object>> routes = new ArrayList<>(); |
| | | if (list != null) { |
| | | for (LlmRouteConfig cfg : list) { |
| | |
| | | } |
| | | |
| | | if (replace) { |
| | | llmRouteConfigService.delete(new EntityWrapper<LlmRouteConfig>()); |
| | | llmRouteConfigService.remove(new QueryWrapper<LlmRouteConfig>()); |
| | | } |
| | | |
| | | HashMap<Long, LlmRouteConfig> dbById = new HashMap<>(); |
| | | if (!replace) { |
| | | List<LlmRouteConfig> current = llmRouteConfigService.selectList(new EntityWrapper<>()); |
| | | List<LlmRouteConfig> current = llmRouteConfigService.list(new QueryWrapper<>()); |
| | | if (current != null) { |
| | | for (LlmRouteConfig item : current) { |
| | | if (item != null && item.getId() != null) { |
| | |
| | | cfg.setLastUsedTime(null); |
| | | cfg.setLastError(null); |
| | | llmRoutingService.fillAndNormalize(cfg, true); |
| | | llmRouteConfigService.insert(cfg); |
| | | llmRouteConfigService.save(cfg); |
| | | inserted++; |
| | | } |
| | | |