From dc5ff2100236817c7eadba481daa25035f9069a5 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sat, 8 Nov 2025 23:44:40 +0800 Subject: [PATCH] =?UTF-8?q?update:=E4=BC=98=E5=8C=96rag=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docker-build.md | 2 +- .../impl/AgentPluginMappingServiceImpl.java | 8 +- .../controller/KnowledgeBaseController.java | 19 +- .../service/KnowledgeBaseService.java | 8 + .../impl/KnowledgeBaseServiceImpl.java | 449 ++++++++---------- main/manager-web/src/apis/module/model.js | 4 +- main/manager-web/src/components/HeaderBar.vue | 267 ++++------- .../src/components/KnowledgeBaseDialog.vue | 57 +-- 8 files changed, 328 insertions(+), 486 deletions(-) diff --git a/docs/docker-build.md b/docs/docker-build.md index 45102a7d..118ed1c9 100644 --- a/docs/docker-build.md +++ b/docs/docker-build.md @@ -17,5 +17,5 @@ docker build -t xiaozhi-esp32-server:web_latest -f ./Dockerfile-web . # 编译完成后,可以使用docker-compose启动项目 # docker-compose.yml你需要修改成自己编译的镜像版本 cd main/xiaozhi-server -docker-compose up -d +docker compose up -d ``` diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentPluginMappingServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentPluginMappingServiceImpl.java index ff9fc8e9..1ebb522a 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentPluginMappingServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentPluginMappingServiceImpl.java @@ -82,8 +82,12 @@ public class AgentPluginMappingServiceImpl extends ServiceImpl(); } + + @GetMapping("/rag-models") + @Operation(summary = "获取RAG模型列表") + @RequiresPermissions("sys:role:normal") + public Result>> getRAGModels() { + List> result = knowledgeBaseService.getRAGModels(); + return new Result>>().ok(result); + } } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/KnowledgeBaseService.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/KnowledgeBaseService.java index 7c2ffef8..75f1f5ba 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/KnowledgeBaseService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/KnowledgeBaseService.java @@ -1,5 +1,6 @@ package xiaozhi.modules.knowledge.service; +import java.util.List; import java.util.Map; import xiaozhi.common.page.PageData; @@ -82,4 +83,11 @@ public interface KnowledgeBaseService extends BaseService { * @return 默认RAG配置信息 */ Map getDefaultRAGConfig(); + + /** + * 获取RAG模型列表 + * + * @return RAG模型列表 + */ + List> getRAGModels(); } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/impl/KnowledgeBaseServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/impl/KnowledgeBaseServiceImpl.java index 34d4cf47..d0f5cd8d 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/impl/KnowledgeBaseServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/impl/KnowledgeBaseServiceImpl.java @@ -1,7 +1,7 @@ package xiaozhi.modules.knowledge.service.impl; -import java.io.IOException; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -13,9 +13,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.HttpServerErrorException; -import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.RestTemplate; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -88,8 +85,9 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl> getRAGModels() { + // 查询RAG类型的模型配置 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("model_type", Constant.RAG_CONFIG_TYPE) + .eq("is_enabled", 1) + .orderByDesc("is_default") + .orderByDesc("create_date"); + + List modelConfigs = modelConfigDao.selectList(queryWrapper); + + List> modelList = new ArrayList<>(); + for (ModelConfigEntity modelConfig : modelConfigs) { + Map modelInfo = new HashMap<>(); + modelInfo.put("id", modelConfig.getId()); + modelInfo.put("modelName", modelConfig.getModelName()); + modelList.add(modelInfo); + } + return modelList; + } + /** * 验证RAG配置中是否包含必要的参数 */ @@ -405,106 +424,90 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl ragConfig) { String datasetId = null; - try { - String baseUrl = (String) ragConfig.get("base_url"); - String apiKey = (String) ragConfig.get("api_key"); + String baseUrl = (String) ragConfig.get("base_url"); + String apiKey = (String) ragConfig.get("api_key"); - log.info("开始调用RAGFlow API创建数据集, name: {}", name); - log.debug("RAGFlow配置 - baseUrl: {}, apiKey: {}", baseUrl, StringUtils.isBlank(apiKey) ? "未配置" : "已配置"); + log.info("开始调用RAGFlow API创建数据集, name: {}", name); + log.debug("RAGFlow配置 - baseUrl: {}, apiKey: {}", baseUrl, StringUtils.isBlank(apiKey) ? "未配置" : "已配置"); - // 构建请求URL - String url = baseUrl + "/api/v1/datasets"; - log.debug("请求URL: {}", url); + // 构建请求URL + String url = baseUrl + "/api/v1/datasets"; + log.debug("请求URL: {}", url); - // 构建请求体 - Map requestBody = new HashMap<>(); - requestBody.put("name", name); - if (StringUtils.isNotBlank(description)) { - requestBody.put("description", description); - } - log.debug("请求体: {}", requestBody); - - // 设置请求头 - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.set("Authorization", "Bearer " + apiKey); - - HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); - - // 发送POST请求 - log.info("发送POST请求到RAGFlow API..."); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); - - log.info("RAGFlow API响应状态码: {}", response.getStatusCode()); - log.debug("RAGFlow API响应内容: {}", response.getBody()); - - if (!response.getStatusCode().is2xxSuccessful()) { - log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody()); - throw new RenException(ErrorCode.RAG_API_ERROR, response.getStatusCode().toString()); - } - - // 解析响应体,提取datasetId - String responseBody = response.getBody(); - if (StringUtils.isNotBlank(responseBody)) { - try { - // 解析RAGFlow API响应,支持多种可能的字段名 - ObjectMapper objectMapper = new ObjectMapper(); - Map responseMap = objectMapper.readValue(responseBody, Map.class); - - log.debug("RAGFlow API响应解析结果: {}", responseMap); - - // 首先检查响应码 - Integer code = (Integer) responseMap.get("code"); - if (code != null && code == 0) { - // 响应码为0表示成功,从data字段中获取datasetId - Object dataObj = responseMap.get("data"); - if (dataObj instanceof Map) { - Map dataMap = (Map) dataObj; - datasetId = (String) dataMap.get("id"); - - if (StringUtils.isBlank(datasetId)) { - // 如果id字段为空,尝试其他可能的字段名 - datasetId = (String) dataMap.get("dataset_id"); - datasetId = (String) dataMap.get("datasetId"); - } - } - } else { - // 如果响应码不为0,说明API调用失败 - log.error("RAGFlow API调用失败,响应码: {}, 响应内容: {}", code, responseBody); - throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API调用失败,响应码: " + code); - } - - log.info("从RAGFlow API响应中解析出datasetId: {}", datasetId); - log.debug("完整响应内容: {}", responseBody); - } catch (Exception e) { - log.error("解析RAGFlow API响应失败: {}, 响应内容: {}", e.getMessage(), responseBody); - throw new RenException(ErrorCode.RAG_API_ERROR, "解析RAGFlow响应失败: " + e.getMessage()); - } - } - - if (StringUtils.isBlank(datasetId)) { - log.error("无法从RAGFlow API响应中获取datasetId,响应内容: {}", responseBody); - throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API响应中未包含datasetId"); - } - log.info("RAGFlow数据集创建成功,datasetId: {}", datasetId); - - } catch (HttpClientErrorException e) { - log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}", - e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, - "创建RAGFlow数据集失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString()); - } catch (HttpServerErrorException e) { - log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}", - e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, - "创建RAGFlow数据集失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString()); - } catch (ResourceAccessException e) { - log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, "创建RAGFlow数据集失败: 网络连接错误 - " + e.getMessage()); - } catch (Exception e) { - log.error("RAGFlow API调用失败 - 未知错误: {}", e.getMessage(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, "创建RAGFlow数据集失败: " + e.getMessage()); + // 构建请求体 + Map requestBody = new HashMap<>(); + requestBody.put("name", name); + if (StringUtils.isNotBlank(description)) { + requestBody.put("description", description); } + log.debug("请求体: {}", requestBody); + + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Authorization", "Bearer " + apiKey); + + HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); + + // 发送POST请求 + log.info("发送POST请求到RAGFlow API..."); + ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); + + log.info("RAGFlow API响应状态码: {}", response.getStatusCode()); + log.debug("RAGFlow API响应内容: {}", response.getBody()); + + if (!response.getStatusCode().is2xxSuccessful()) { + log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody()); + throw new RenException(ErrorCode.RAG_API_ERROR, response.getStatusCode().toString()); + } + + // 解析响应体,提取datasetId + String responseBody = response.getBody(); + if (StringUtils.isNotBlank(responseBody)) { + try { + // 解析RAGFlow API响应,支持多种可能的字段名 + ObjectMapper objectMapper = new ObjectMapper(); + Map responseMap = objectMapper.readValue(responseBody, Map.class); + + log.debug("RAGFlow API响应解析结果: {}", responseMap); + + // 首先检查响应码 + Integer code = (Integer) responseMap.get("code"); + String message = (String) responseMap.get("message"); + if (code != null && code == 0) { + // 响应码为0表示成功,从data字段中获取datasetId + Object dataObj = responseMap.get("data"); + if (dataObj instanceof Map) { + Map dataMap = (Map) dataObj; + datasetId = (String) dataMap.get("id"); + + if (StringUtils.isBlank(datasetId)) { + // 如果id字段为空,尝试其他可能的字段名 + datasetId = (String) dataMap.get("dataset_id"); + datasetId = (String) dataMap.get("datasetId"); + } + } + } else { + // 如果响应码不为0,说明API调用失败 + log.error("RAGFlow API调用失败,响应码: {}, 响应内容: {}", code, message); + throw new RenException(ErrorCode.RAG_API_ERROR, + "RAGFlow API调用失败,响应码: " + code + ", 消息: " + message); + } + + log.info("从RAGFlow API响应中解析出datasetId: {}", datasetId); + log.debug("完整响应内容: {}", responseBody); + } catch (Exception e) { + log.error("解析RAGFlow API响应失败: {}", e.getMessage(), e); + throw new RenException(ErrorCode.RAG_API_ERROR, "解析响应失败: " + e.getMessage()); + } + } + + if (StringUtils.isBlank(datasetId)) { + log.error("无法从RAGFlow API响应中获取datasetId,响应内容: {}", responseBody); + throw new RenException(ErrorCode.RAG_API_ERROR, "RAGFlow API响应中未包含datasetId"); + } + log.info("RAGFlow数据集创建成功,datasetId: {}", datasetId); + return datasetId; } @@ -513,124 +516,88 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl ragConfig) { - try { - String baseUrl = (String) ragConfig.get("base_url"); - String apiKey = (String) ragConfig.get("api_key"); + String baseUrl = (String) ragConfig.get("base_url"); + String apiKey = (String) ragConfig.get("api_key"); - log.info("开始调用RAGFlow API更新数据集,datasetId: {}, name: {}", datasetId, name); - log.debug("RAGFlow配置 - baseUrl: {}, apiKey: {}", baseUrl, StringUtils.isBlank(apiKey) ? "未配置" : "已配置"); + log.info("开始调用RAGFlow API更新数据集,datasetId: {}, name: {}", datasetId, name); + log.debug("RAGFlow配置 - baseUrl: {}, apiKey: {}", baseUrl, StringUtils.isBlank(apiKey) ? "未配置" : "已配置"); - // 构建请求URL - String url = baseUrl + "/api/v1/datasets/" + datasetId; - log.debug("请求URL: {}", url); + // 构建请求URL + String url = baseUrl + "/api/v1/datasets/" + datasetId; + log.debug("请求URL: {}", url); - // 构建请求体 - Map requestBody = new HashMap<>(); - requestBody.put("dataset_id", datasetId); - requestBody.put("name", name); - if (StringUtils.isNotBlank(description)) { - requestBody.put("description", description); - } - log.debug("请求体: {}", requestBody); - - // 设置请求头 - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.set("Authorization", "Bearer " + apiKey); - - HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); - - // 发送PUT请求 - log.info("发送PUT请求到RAGFlow API..."); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.PUT, requestEntity, String.class); - - log.info("RAGFlow API响应状态码: {}", response.getStatusCode()); - log.debug("RAGFlow API响应内容: {}", response.getBody()); - - if (!response.getStatusCode().is2xxSuccessful()) { - log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody()); - throw new RenException(ErrorCode.RAG_API_ERROR); - } - - log.info("RAGFlow数据集更新成功,datasetId: {}", datasetId); - - } catch (HttpClientErrorException e) { - log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}", - e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, - "更新RAGFlow数据集失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString()); - } catch (HttpServerErrorException e) { - log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}", - e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, - "更新RAGFlow数据集失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString()); - } catch (ResourceAccessException e) { - log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, "更新RAGFlow数据集失败: 网络连接错误 - " + e.getMessage()); - } catch (Exception e) { - log.error("RAGFlow API调用失败 - 未知错误: {}", e.getMessage(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, "更新RAGFlow数据集失败: " + e.getMessage()); + // 构建请求体 + Map requestBody = new HashMap<>(); + requestBody.put("dataset_id", datasetId); + requestBody.put("name", name); + if (StringUtils.isNotBlank(description)) { + requestBody.put("description", description); } + log.debug("请求体: {}", requestBody); + + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Authorization", "Bearer " + apiKey); + + HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); + + // 发送PUT请求 + log.info("发送PUT请求到RAGFlow API..."); + ResponseEntity response = restTemplate.exchange(url, HttpMethod.PUT, requestEntity, String.class); + + log.info("RAGFlow API响应状态码: {}", response.getStatusCode()); + log.debug("RAGFlow API响应内容: {}", response.getBody()); + + if (!response.getStatusCode().is2xxSuccessful()) { + log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody()); + throw new RenException(ErrorCode.RAG_API_ERROR); + } + + log.info("RAGFlow数据集更新成功,datasetId: {}", datasetId); + } /** * 调用RAGFlow API删除数据集 */ private void deleteDatasetInRAGFlow(String datasetId, Map ragConfig) { - try { - String baseUrl = (String) ragConfig.get("base_url"); - String apiKey = (String) ragConfig.get("api_key"); + String baseUrl = (String) ragConfig.get("base_url"); + String apiKey = (String) ragConfig.get("api_key"); - log.info("开始调用RAGFlow API删除数据集,datasetId: {}", datasetId); - log.debug("RAGFlow配置 - baseUrl: {}, apiKey: {}", baseUrl, StringUtils.isBlank(apiKey) ? "未配置" : "已配置"); + log.info("开始调用RAGFlow API删除数据集,datasetId: {}", datasetId); + log.debug("RAGFlow配置 - baseUrl: {}, apiKey: {}", baseUrl, StringUtils.isBlank(apiKey) ? "未配置" : "已配置"); - // 构建请求URL - String url = baseUrl + "/api/v1/datasets"; - log.debug("请求URL: {}", url); + // 构建请求URL + String url = baseUrl + "/api/v1/datasets"; + log.debug("请求URL: {}", url); - // 构建请求体 - Map requestBody = new HashMap<>(); - requestBody.put("ids", List.of(datasetId)); - log.debug("请求体: {}", requestBody); + // 构建请求体 + Map requestBody = new HashMap<>(); + requestBody.put("ids", List.of(datasetId)); + log.debug("请求体: {}", requestBody); - // 设置请求头 - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.set("Authorization", "Bearer " + apiKey); + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Authorization", "Bearer " + apiKey); - HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); + HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); - // 发送DELETE请求 - log.info("发送DELETE请求到RAGFlow API..."); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, - String.class); + // 发送DELETE请求 + log.info("发送DELETE请求到RAGFlow API..."); + ResponseEntity response = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, + String.class); - log.info("RAGFlow API响应状态码: {}", response.getStatusCode()); - log.debug("RAGFlow API响应内容: {}", response.getBody()); + log.info("RAGFlow API响应状态码: {}", response.getStatusCode()); + log.debug("RAGFlow API响应内容: {}", response.getBody()); - if (!response.getStatusCode().is2xxSuccessful()) { - log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody()); - throw new RenException(ErrorCode.RAG_API_ERROR); - } - log.info("RAGFlow数据集删除成功,datasetId: {}", datasetId); - - } catch (HttpClientErrorException e) { - log.error("RAGFlow API调用失败 - HTTP错误: {}, 状态码: {}, 响应内容: {}", - e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, - "删除RAGFlow数据集失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString()); - } catch (HttpServerErrorException e) { - log.error("RAGFlow API调用失败 - 服务器错误: {}, 状态码: {}, 响应内容: {}", - e.getMessage(), e.getStatusCode(), e.getResponseBodyAsString(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, - "删除RAGFlow数据集失败: " + e.getMessage() + ", 响应: " + e.getResponseBodyAsString()); - } catch (ResourceAccessException e) { - log.error("RAGFlow API调用失败 - 网络连接错误: {}", e.getMessage(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, "删除RAGFlow数据集失败: 网络连接错误 - " + e.getMessage()); - } catch (Exception e) { - log.error("RAGFlow API调用失败 - 未知错误: {}", e.getMessage(), e); - throw new RenException(ErrorCode.RAG_API_ERROR, "删除RAGFlow数据集失败: " + e.getMessage()); + if (!response.getStatusCode().is2xxSuccessful()) { + log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody()); + throw new RenException(ErrorCode.RAG_API_ERROR); } + log.info("RAGFlow数据集删除成功,datasetId: {}", datasetId); + } /** @@ -688,40 +655,40 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl ragConfig = getValidatedRAGConfig(ragModelId); + String baseUrl = (String) ragConfig.get("base_url"); + String apiKey = (String) ragConfig.get("api_key"); + + // 构建请求URL - 调用RAGFlow API获取文档列表,但不返回文档详情,只获取总数 + String url = baseUrl + "/api/v1/datasets/" + datasetId + "/documents?page=1&size=1"; + log.debug("请求URL: {}", url); + + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Authorization", "Bearer " + apiKey); + + HttpEntity requestEntity = new HttpEntity<>(headers); + + // 发送GET请求 + log.info("发送GET请求到RAGFlow API获取文档数量..."); + ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class); + + log.info("RAGFlow API响应状态码: {}", response.getStatusCode()); + + if (!response.getStatusCode().is2xxSuccessful()) { + log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody()); + return 0; + } + + String responseBody = response.getBody(); + log.debug("RAGFlow API响应内容: {}", responseBody); + + // 解析响应 try { - log.info("开始获取知识库 {} 的文档数量", datasetId); - - // 获取RAG配置 - Map ragConfig = getValidatedRAGConfig(ragModelId); - String baseUrl = (String) ragConfig.get("base_url"); - String apiKey = (String) ragConfig.get("api_key"); - - // 构建请求URL - 调用RAGFlow API获取文档列表,但不返回文档详情,只获取总数 - String url = baseUrl + "/api/v1/datasets/" + datasetId + "/documents?page=1&size=1"; - log.debug("请求URL: {}", url); - - // 设置请求头 - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.set("Authorization", "Bearer " + apiKey); - - HttpEntity requestEntity = new HttpEntity<>(headers); - - // 发送GET请求 - log.info("发送GET请求到RAGFlow API获取文档数量..."); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class); - - log.info("RAGFlow API响应状态码: {}", response.getStatusCode()); - - if (!response.getStatusCode().is2xxSuccessful()) { - log.error("RAGFlow API调用失败,状态码: {}, 响应内容: {}", response.getStatusCode(), response.getBody()); - return 0; - } - - String responseBody = response.getBody(); - log.debug("RAGFlow API响应内容: {}", responseBody); - - // 解析响应 ObjectMapper objectMapper = new ObjectMapper(); Map responseMap = objectMapper.readValue(responseBody, Map.class); Integer code = (Integer) responseMap.get("code"); @@ -744,21 +711,9 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl { RequestService.clearRequestTime() diff --git a/main/manager-web/src/components/HeaderBar.vue b/main/manager-web/src/components/HeaderBar.vue index 30328f8a..42e3a520 100644 --- a/main/manager-web/src/components/HeaderBar.vue +++ b/main/manager-web/src/components/HeaderBar.vue @@ -9,82 +9,50 @@
-
+ - + ? 'brightness(0) invert(1)' + : 'None', + }" /> {{ $t("header.smartManagement") }}
-
- +
+ {{ $t("header.voiceCloneManagement") }}
- + - + ? 'brightness(0) invert(1)' + : 'None', + }" /> {{ $t("header.voiceCloneManagement") }} - + @@ -96,84 +64,56 @@ -
- +
+ {{ $t("header.modelConfig") }}
-
- + @click="goKnowledgeBaseManagement"> + {{ $t("header.knowledgeBase") }}
- + - + ? 'brightness(0) invert(1)' + : 'None', + }" /> {{ $t("header.paramDictionary") }} - + {{ $t("header.paramManagement") }} + + {{ $t("header.userManagement") }} + {{ $t("header.otaManagement") }} @@ -189,94 +129,46 @@ {{ $t("header.serverSideManagement") }} - - {{ $t("header.userManagement") }} -
-
+
- - + + -
+
{{ $t("header.searchHistory") }} - + {{ $t("header.clearHistory") }}
-
+
{{ item }} - +
- + {{ userInfo.username || "加载中..." }} - + - + @@ -871,7 +763,7 @@ export default { color: #ff4949; } -.custom-search-input >>> .el-input__inner { +.custom-search-input>>>.el-input__inner { height: 18px; border-radius: 9px; background-color: #fff; @@ -941,6 +833,7 @@ export default { color: #606266; white-space: nowrap; } + /* 添加倒三角旋转样式 */ .rotate-down { transform: rotate(180deg); diff --git a/main/manager-web/src/components/KnowledgeBaseDialog.vue b/main/manager-web/src/components/KnowledgeBaseDialog.vue index d2779395..99d01341 100644 --- a/main/manager-web/src/components/KnowledgeBaseDialog.vue +++ b/main/manager-web/src/components/KnowledgeBaseDialog.vue @@ -1,46 +1,17 @@