| | |
| | | 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; |
| | |
| | | * @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"; |
| | |
| | | * @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 { |
| | |
| | | } |
| | | |
| | | // 步骤9:删除旧文件 |
| | | if(StrUtil.isNotBlank(oldFileId)){ |
| | | System.out.println("步骤9:删除旧文件"); |
| | | deleteIndexDocument(client, workspaceId, indexId, oldFileId); |
| | | } |
| | | |
| | | System.out.println("阿里云百炼知识库更新成功!"); |
| | | return indexId; |
| | |
| | | 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 { |