diff --git a/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java b/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java index 268df223..659e135a 100644 --- a/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java +++ b/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java @@ -209,4 +209,8 @@ public interface ErrorCode { int UPLOAD_FILE_ERROR = 10168; // 上传文件失败 int NO_PERMISSION = 10169; // 没有权限 int KNOWLEDGE_BASE_NAME_EXISTS = 10170; // 同名知识库已存在 + int RAG_API_ERROR_URL_NULL = 10171; // RAG配置中base_url为空,请完善配置 + int RAG_API_ERROR_API_KEY_NULL = 10172; // RAG配置中api_key为空,请完善配置 + int RAG_API_ERROR_API_KEY_INVALID = 10173; // RAG配置中api_key包含占位符,请替换为实际的API密钥 + int RAG_API_ERROR_URL_INVALID = 10174; // RAG配置中base_url格式不正确,请检查协议是否正确 } 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 80934316..b56923de 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 @@ -110,7 +110,10 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl ragConfig = getValidatedRAGConfig(knowledgeBaseDTO.getRagModelId()); deleteDatasetInRAGFlow(datasetId, ragConfig); } catch (Exception deleteException) { - log.warn("删除重复datasetId的RAGFlow数据集失败: {}", deleteException.getMessage()); + // 提供更详细的错误信息,包括异常类型和消息 + String errorMessage = "删除重复datasetId的RAGFlow数据集失败: " + deleteException.getClass().getSimpleName(); + if (deleteException.getMessage() != null) { + errorMessage += " - " + deleteException.getMessage(); + } + log.warn(errorMessage, deleteException); } throw new RenException(ErrorCode.DB_RECORD_EXISTS); } @@ -207,17 +215,27 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl ragConfig = getValidatedRAGConfig(knowledgeBaseDTO.getRagModelId()); + try { + // 先校验RAG配置 + Map ragConfig = getValidatedRAGConfig(knowledgeBaseDTO.getRagModelId()); - // 调用RAGFlow API更新数据集 - updateDatasetInRAGFlow( - knowledgeBaseDTO.getDatasetId(), - knowledgeBaseDTO.getName(), - knowledgeBaseDTO.getDescription(), - ragConfig); + // 调用RAGFlow API更新数据集 + updateDatasetInRAGFlow( + knowledgeBaseDTO.getDatasetId(), + knowledgeBaseDTO.getName(), + knowledgeBaseDTO.getDescription(), + ragConfig); - log.info("RAGFlow API更新成功,datasetId: {}", knowledgeBaseDTO.getDatasetId()); + log.info("RAGFlow API更新成功,datasetId: {}", knowledgeBaseDTO.getDatasetId()); + } catch (Exception e) { + // 提供更详细的错误信息,包括异常类型和消息 + String errorMessage = "更新RAGFlow数据集失败: " + e.getClass().getSimpleName(); + if (e.getMessage() != null) { + errorMessage += " - " + e.getMessage(); + } + log.error(errorMessage, e); + throw e; + } } else { log.warn("datasetId或ragModelId为空,跳过RAGFlow更新"); } @@ -281,7 +299,12 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl config) { if (config == null) { - throw new RenException(ErrorCode.RAG_CONFIG_NOT_FOUND); + throw new RenException(ErrorCode.RAG_CONFIG_NOT_FOUND, "RAG配置为空,请检查配置"); } // 从配置中提取必要的参数 @@ -385,7 +408,22 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl ragConfig) { - if (ragConfig == null) { - throw new RenException(ErrorCode.RAG_CONFIG_NOT_FOUND, "RAG配置为空,请检查配置"); - } - - // 从配置中提取必要的参数 - String baseUrl = (String) ragConfig.get("base_url"); - String apiKey = (String) ragConfig.get("api_key"); - - if (StringUtils.isBlank(baseUrl)) { - throw new RenException(ErrorCode.RAG_API_ERROR, "RAG配置中base_url为空,请完善配置"); - } - - if (StringUtils.isBlank(apiKey)) { - throw new RenException(ErrorCode.RAG_API_ERROR, "RAG配置中api_key为空,请完善配置"); - } - - if (apiKey.contains("你")) { - throw new RenException(ErrorCode.RAG_API_ERROR, "RAG配置中api_key包含占位符'你',请替换为实际的API密钥"); - } - - if (!baseUrl.startsWith("http://") && !baseUrl.startsWith("https://")) { - throw new RenException(ErrorCode.RAG_API_ERROR, "RAG配置中base_url格式不正确,必须以http://或https://开头"); - } - } - /** * 检查是否存在同名知识库 * @@ -805,9 +832,15 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl