mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 18:23:51 +08:00
fix:增加RAG配置验证
This commit is contained in:
+41
-2
@@ -595,10 +595,49 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
|||||||
* 获取RAG配置并验证
|
* 获取RAG配置并验证
|
||||||
*/
|
*/
|
||||||
private Map<String, Object> getValidatedRAGConfig(String ragModelId) {
|
private Map<String, Object> getValidatedRAGConfig(String ragModelId) {
|
||||||
|
Map<String, Object> ragConfig;
|
||||||
if (StringUtils.isNotBlank(ragModelId)) {
|
if (StringUtils.isNotBlank(ragModelId)) {
|
||||||
return getRAGConfig(ragModelId);
|
ragConfig = getRAGConfig(ragModelId);
|
||||||
} else {
|
} else {
|
||||||
return getDefaultRAGConfig();
|
ragConfig = getDefaultRAGConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证baseUrl和apiKey
|
||||||
|
validateRAGConfigParameters(ragConfig);
|
||||||
|
|
||||||
|
return ragConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证RAG配置参数
|
||||||
|
*/
|
||||||
|
private void validateRAGConfigParameters(Map<String, Object> 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");
|
||||||
|
|
||||||
|
// 验证base_url是否存在且非空
|
||||||
|
if (StringUtils.isBlank(baseUrl)) {
|
||||||
|
throw new RenException(ErrorCode.RAG_CONFIG_MISSING_PARAMS, "RAG配置中base_url为空,请完善配置");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证apiKey是否存在且非空
|
||||||
|
if (StringUtils.isBlank(apiKey)) {
|
||||||
|
throw new RenException(ErrorCode.RAG_CONFIG_MISSING_PARAMS, "RAG配置中api_key为空,请完善配置");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证apiKey是否包含"你"字(可能是占位符)
|
||||||
|
if (apiKey.contains("你")) {
|
||||||
|
throw new RenException(ErrorCode.RAG_CONFIG_MISSING_PARAMS, "RAG配置中api_key包含占位符'你',请替换为实际的API密钥");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证baseUrl格式(基本验证)
|
||||||
|
if (!baseUrl.startsWith("http://") && !baseUrl.startsWith("https://")) {
|
||||||
|
throw new RenException(ErrorCode.RAG_CONFIG_MISSING_PARAMS, "RAG配置中base_url格式不正确,必须以http://或https://开头");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `f
|
|||||||
|
|
||||||
-- 添加RAG模型配置
|
-- 添加RAG模型配置
|
||||||
delete from `ai_model_config` where id = 'RAG_RAGFlow';
|
delete from `ai_model_config` where id = 'RAG_RAGFlow';
|
||||||
INSERT INTO `ai_model_config` VALUES ('RAG_RAGFlow', 'RAG', 'ragflow', 'RAGFlow', 1, 1, '{"type": "ragflow", "base_url": "http://localhost", "api_key": "your_api_key_here"}', 'https://github.com/infiniflow/ragflow/blob/main/README_zh.md', 'RAGFlow配置说明:
|
INSERT INTO `ai_model_config` VALUES ('RAG_RAGFlow', 'RAG', 'ragflow', 'RAGFlow', 1, 1, '{"type": "ragflow", "base_url": "http://localhost", "api_key": "你的RAG密钥"}', 'https://github.com/infiniflow/ragflow/blob/main/README_zh.md', 'RAGFlow配置说明:
|
||||||
一、快速部署教程(docker部署)
|
一、快速部署教程(docker部署)
|
||||||
1.$ sysctl vm.max_map_count
|
1.$ sysctl vm.max_map_count
|
||||||
2.$ sysctl -w vm.max_map_count=262144
|
2.$ sysctl -w vm.max_map_count=262144
|
||||||
@@ -403,12 +403,12 @@ databaseChangeLog:
|
|||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202510191042.sql
|
path: classpath:db/changelog/202510191042.sql
|
||||||
- changeSet:
|
- changeSet:
|
||||||
id: 202510250955
|
id: 202510250956
|
||||||
author: rainv123
|
author: rainv123
|
||||||
changes:
|
changes:
|
||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202510250955.sql
|
path: classpath:db/changelog/202510250956.sql
|
||||||
- changeSet:
|
- changeSet:
|
||||||
id: 202510251150
|
id: 202510251150
|
||||||
author: rainv123
|
author: rainv123
|
||||||
|
|||||||
@@ -299,16 +299,20 @@ export default {
|
|||||||
console.log('Creating knowledge base with data:', createData);
|
console.log('Creating knowledge base with data:', createData);
|
||||||
Api.knowledgeBase.createKnowledgeBase(createData, (res) => {
|
Api.knowledgeBase.createKnowledgeBase(createData, (res) => {
|
||||||
console.log('Create response:', res);
|
console.log('Create response:', res);
|
||||||
// 修复:检查 res.data.code 而不是 res.code
|
|
||||||
if (res.data && res.data.code === 0) {
|
if (res.data && res.data.code === 0) {
|
||||||
this.dialogVisible = false;
|
this.dialogVisible = false;
|
||||||
this.fetchKnowledgeBaseList();
|
this.fetchKnowledgeBaseList();
|
||||||
this.$message.success(this.$t('knowledgeBaseManagement.addSuccess'));
|
this.$message.success(this.$t('knowledgeBaseManagement.addSuccess'));
|
||||||
} else {
|
|
||||||
this.$message.error(res.data?.msg || this.$t('knowledgeBaseManagement.addFailed'));
|
|
||||||
}
|
}
|
||||||
}, () => {
|
}, (err) => {
|
||||||
this.$message.error(this.$t('knowledgeBaseManagement.addFailed'));
|
console.log('Error callback received:', err);
|
||||||
|
// 错误回调处理后端返回的错误信息
|
||||||
|
if (err && err.data) {
|
||||||
|
console.log('后端返回错误消息:', err.data.msg || err.msg);
|
||||||
|
this.$message.error(err.data.msg || err.msg || this.$t('knowledgeBaseManagement.addFailed'));
|
||||||
|
} else {
|
||||||
|
this.$message.error(this.$t('knowledgeBaseManagement.addFailed'));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -328,7 +332,6 @@ export default {
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
const ids = this.selectedKnowledgeBase.map(item => item.datasetId).join(',');
|
const ids = this.selectedKnowledgeBase.map(item => item.datasetId).join(',');
|
||||||
Api.knowledgeBase.deleteKnowledgeBases(ids, (res) => {
|
Api.knowledgeBase.deleteKnowledgeBases(ids, (res) => {
|
||||||
// 修复:检查 res.data.code 而不是 res.code
|
|
||||||
if (res.data && res.data.code === 0) {
|
if (res.data && res.data.code === 0) {
|
||||||
this.fetchKnowledgeBaseList();
|
this.fetchKnowledgeBaseList();
|
||||||
this.$message.success(this.$t('knowledgeBaseManagement.batchDeleteSuccess', { count: this.selectedKnowledgeBase.length }));
|
this.$message.success(this.$t('knowledgeBaseManagement.batchDeleteSuccess', { count: this.selectedKnowledgeBase.length }));
|
||||||
@@ -356,7 +359,6 @@ export default {
|
|||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
Api.knowledgeBase.deleteKnowledgeBase(row.datasetId, (res) => {
|
Api.knowledgeBase.deleteKnowledgeBase(row.datasetId, (res) => {
|
||||||
// 修复:检查 res.data.code 而不是 res.code
|
|
||||||
if (res.data && res.data.code === 0) {
|
if (res.data && res.data.code === 0) {
|
||||||
this.fetchKnowledgeBaseList();
|
this.fetchKnowledgeBaseList();
|
||||||
this.$message.success(this.$t('knowledgeBaseManagement.batchDeleteSuccess', { count: 1 }));
|
this.$message.success(this.$t('knowledgeBaseManagement.batchDeleteSuccess', { count: 1 }));
|
||||||
|
|||||||
Reference in New Issue
Block a user