From 26472c5a333f7ee98d9366aa2344e15c9234cc67 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 29 Sep 2025 15:05:03 +0800
Subject: [PATCH] feat(ai): 增加知识库创建与更新时的分类ID参数支持
---
src/main/java/cc/mrbird/febs/ai/util/KnowledgeBaseUtil.java | 25 ++++++++++++++++---------
1 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/ai/util/KnowledgeBaseUtil.java b/src/main/java/cc/mrbird/febs/ai/util/KnowledgeBaseUtil.java
index d156343..0ba8f5a 100644
--- a/src/main/java/cc/mrbird/febs/ai/util/KnowledgeBaseUtil.java
+++ b/src/main/java/cc/mrbird/febs/ai/util/KnowledgeBaseUtil.java
@@ -1,5 +1,6 @@
package cc.mrbird.febs.ai.util;
+import cn.hutool.core.util.StrUtil;
import com.aliyun.bailian20231229.models.*;
import com.aliyun.teautil.models.RuntimeOptions;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -273,9 +274,11 @@
* @param name 知识库名称
* @return 如果成功,返回知识库ID;否则返回 null
*/
- public static String createKnowledgeBase(String filePath, String workspaceId, String name) {
+ public static String createKnowledgeBase(String filePath, String workspaceId, String name,String categoryId) {
// 设置默认值
- String categoryId = "default";
+ if (StrUtil.isBlank(categoryId)){
+ categoryId = "default";
+ }
String parser = "DASHSCOPE_DOCMIND";
String sourceType = "DATA_CENTER_FILE";
String structureType = "unstructured";
@@ -376,9 +379,11 @@
* @param oldFileId 需要更新的文件的FileID
* @return 如果成功,返回知识库ID;否则返回 null
*/
- public static String updateKnowledgeBase(String filePath, String workspaceId, String indexId, String oldFileId) {
+ public static String updateKnowledgeBase(String filePath, String workspaceId, String indexId, String oldFileId, String categoryId) {
// 设置默认值
- String categoryId = "default";
+ if (StrUtil.isBlank(categoryId)){
+ categoryId = "default";
+ }
String parser = "DASHSCOPE_DOCMIND";
String sourceType = "DATA_CENTER_FILE";
try {
@@ -450,8 +455,10 @@
}
// 步骤9:删除旧文件
- System.out.println("步骤9:删除旧文件");
- deleteIndexDocument(client, workspaceId, indexId, oldFileId);
+ if(StrUtil.isNotBlank(oldFileId)){
+ System.out.println("步骤9:删除旧文件");
+ deleteIndexDocument(client, workspaceId, indexId, oldFileId);
+ }
System.out.println("阿里云百炼知识库更新成功!");
return indexId;
@@ -507,11 +514,11 @@
public static void main(String[] args) {
String filePath = "D:\\项目\\大模型\\阿里云百炼\\知识库\\薪资谈判常见100问与答.md";
- String indexId = "xlmj6e7ix1"; // 即 AddFile 接口返回的 FileId。您也可以在阿里云百炼控制台的应用数据页面,单击文件名称旁的 ID 图标获取。
- String oldFileId = "file_5c9f7e4e0f3e4b4ea2bd208a1b4f5e6f_12629554";
+ String indexId = "xlmj6e7ix1";
+ String oldFileId = "file_e943bb6d305a49a5acb7781ca00d70dd_12629554";
String workspaceId = WORKSPACE_ID;
- String result = updateKnowledgeBase(filePath, workspaceId, indexId, oldFileId);
+ String result = updateKnowledgeBase(filePath, workspaceId, indexId, oldFileId,null);
if (result != null) {
System.out.println("知识库更新成功,返回知识库ID: " + result);
} else {
--
Gitblit v1.9.1