| | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | cfg.setName(trim(cfg.getName())); |
| | | cfg.setProviderType(trim(cfg.getProviderType())); |
| | | cfg.setProtocolType(trim(cfg.getProtocolType())); |
| | | cfg.setBaseUrl(trim(cfg.getBaseUrl())); |
| | | cfg.setEndpointPath(trim(cfg.getEndpointPath())); |
| | | cfg.setApiKey(trim(cfg.getApiKey())); |
| | | cfg.setAuthType(trim(cfg.getAuthType())); |
| | | cfg.setAuthHeaderName(trim(cfg.getAuthHeaderName())); |
| | | cfg.setModel(trim(cfg.getModel())); |
| | | cfg.setCapabilities(trim(cfg.getCapabilities())); |
| | | cfg.setRequestOptions(trim(cfg.getRequestOptions())); |
| | | cfg.setMemo(trim(cfg.getMemo())); |
| | | if (isBlank(cfg.getBaseUrl()) || isBlank(cfg.getApiKey()) || isBlank(cfg.getModel())) { |
| | | skipped++; |
| | |
| | | } |
| | | |
| | | 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++; |
| | | } |
| | | |
| | |
| | | LinkedHashMap<String, Object> row = new LinkedHashMap<>(); |
| | | row.put("id", cfg.getId()); |
| | | row.put("name", cfg.getName()); |
| | | row.put("providerType", cfg.getProviderType()); |
| | | row.put("protocolType", cfg.getProtocolType()); |
| | | row.put("baseUrl", cfg.getBaseUrl()); |
| | | row.put("endpointPath", cfg.getEndpointPath()); |
| | | row.put("apiKey", cfg.getApiKey()); |
| | | row.put("authType", cfg.getAuthType()); |
| | | row.put("authHeaderName", cfg.getAuthHeaderName()); |
| | | row.put("model", cfg.getModel()); |
| | | row.put("capabilities", cfg.getCapabilities()); |
| | | row.put("requestOptions", cfg.getRequestOptions()); |
| | | row.put("thinking", cfg.getThinking()); |
| | | row.put("priority", cfg.getPriority()); |
| | | row.put("status", cfg.getStatus()); |