Quellcode durchsuchen

智能体上传文件返回chatid及助手message

lamphua vor 3 Tagen
Ursprung
Commit
d4ce4ba520

+ 1
- 1
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/controller/CmcAgentController.java Datei anzeigen

86
     @PostMapping("/upload")
86
     @PostMapping("/upload")
87
     public AjaxResult upload(MultipartFile file, String agentName) throws IOException
87
     public AjaxResult upload(MultipartFile file, String agentName) throws IOException
88
     {
88
     {
89
-        return success(new AssistantMessage(cmcAgentService.uploadDocument(file, agentName)));
89
+        return success(cmcAgentService.uploadDocument(file, agentName));
90
     }
90
     }
91
 
91
 
92
     /**
92
     /**

+ 2
- 2
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/controller/CmcDocumentController.java Datei anzeigen

73
      * @return
73
      * @return
74
      */
74
      */
75
     @PostMapping("/upload")
75
     @PostMapping("/upload")
76
-    public AjaxResult upload(MultipartFile[] fileList, String agentName) throws IOException
76
+    public AjaxResult upload(MultipartFile[] fileList) throws IOException
77
     {
77
     {
78
-        return success(cmcDocumentService.uploadDocument(fileList, agentName));
78
+        return success(cmcDocumentService.uploadDocument(fileList));
79
     }
79
     }
80
 
80
 
81
     /**
81
     /**

+ 1
- 1
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/service/impl/LangChainMilvusServiceImpl.java Datei anzeigen

64
         File profilePath = new File( RuoYiConfig.getProfile() + "/upload/rag/knowledge/" + collectionName);
64
         File profilePath = new File( RuoYiConfig.getProfile() + "/upload/rag/knowledge/" + collectionName);
65
         if (!profilePath.exists())
65
         if (!profilePath.exists())
66
             profilePath.mkdirs();
66
             profilePath.mkdirs();
67
-        File transferFile = new File( profilePath + File.separator + file.getOriginalFilename());
67
+        File transferFile = new File( profilePath + "/" + file.getOriginalFilename());
68
         if (!transferFile.exists())
68
         if (!transferFile.exists())
69
             file.transferTo(transferFile);
69
             file.transferTo(transferFile);
70
         List<TextSegment> segments = splitDocument(file.getOriginalFilename(), transferFile);
70
         List<TextSegment> segments = splitDocument(file.getOriginalFilename(), transferFile);

+ 2
- 1
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/service/ICmcAgentService.java Datei anzeigen

3
 import java.io.IOException;
3
 import java.io.IOException;
4
 import java.util.List;
4
 import java.util.List;
5
 
5
 
6
+import com.alibaba.fastjson2.JSONObject;
6
 import com.ruoyi.llm.domain.CmcAgent;
7
 import com.ruoyi.llm.domain.CmcAgent;
7
 import org.springframework.web.multipart.MultipartFile;
8
 import org.springframework.web.multipart.MultipartFile;
8
 
9
 
44
      * @param file 文件
45
      * @param file 文件
45
      * @return 结果
46
      * @return 结果
46
      */
47
      */
47
-    public String uploadDocument(MultipartFile file, String agentName) throws IOException;
48
+    public JSONObject uploadDocument(MultipartFile file, String agentName) throws IOException;
48
 
49
 
49
     /**
50
     /**
50
      * 上传多文件
51
      * 上传多文件

+ 1
- 2
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/service/ICmcDocumentService.java Datei anzeigen

35
      * 上传外部文件
35
      * 上传外部文件
36
      *
36
      *
37
      * @param fileList 文件
37
      * @param fileList 文件
38
-     * @param agentName 智能体名称
39
      * @return 结果
38
      * @return 结果
40
      */
39
      */
41
-    public JSONObject uploadDocument(MultipartFile[] fileList, String agentName) throws IOException;
40
+    public JSONObject uploadDocument(MultipartFile[] fileList) throws IOException;
42
 
41
 
43
     /**
42
     /**
44
      * 新增cmc聊天附件
43
      * 新增cmc聊天附件

+ 19
- 3
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/service/impl/CmcAgentServiceImpl.java Datei anzeigen

6
 import java.io.IOException;
6
 import java.io.IOException;
7
 import java.util.List;
7
 import java.util.List;
8
 
8
 
9
+import com.alibaba.fastjson2.JSONObject;
9
 import com.ruoyi.common.config.RuoYiConfig;
10
 import com.ruoyi.common.config.RuoYiConfig;
10
 import com.ruoyi.common.utils.DateUtils;
11
 import com.ruoyi.common.utils.DateUtils;
12
+import com.ruoyi.common.utils.SnowFlake;
13
+import com.ruoyi.llm.domain.CmcDocument;
14
+import com.ruoyi.llm.mapper.CmcDocumentMapper;
11
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
15
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
12
 import org.springframework.beans.factory.annotation.Autowired;
16
 import org.springframework.beans.factory.annotation.Autowired;
13
 import org.springframework.stereotype.Service;
17
 import org.springframework.stereotype.Service;
28
     @Autowired
32
     @Autowired
29
     private CmcAgentMapper cmcAgentMapper;
33
     private CmcAgentMapper cmcAgentMapper;
30
 
34
 
35
+    @Autowired
36
+    private CmcDocumentMapper cmcDocumentMapper;
37
+
31
     /**
38
     /**
32
      * 查询智能体
39
      * 查询智能体
33
      * 
40
      * 
73
      * @return 结果
80
      * @return 结果
74
      */
81
      */
75
     @Override
82
     @Override
76
-    public String uploadDocument(MultipartFile file, String agentName) throws IOException {
83
+    public JSONObject uploadDocument(MultipartFile file, String agentName) throws IOException {
77
         File profilePath = new File( RuoYiConfig.getProfile() + "/upload/agent/" + agentName);
84
         File profilePath = new File( RuoYiConfig.getProfile() + "/upload/agent/" + agentName);
78
         if (!profilePath.exists())
85
         if (!profilePath.exists())
79
             profilePath.mkdirs();
86
             profilePath.mkdirs();
80
-        File transferFile = new File(profilePath + File.separator + file.getOriginalFilename());
87
+        File transferFile = new File(profilePath + "/" + file.getOriginalFilename());
81
         if (!transferFile.exists())
88
         if (!transferFile.exists())
82
             file.transferTo(transferFile);
89
             file.transferTo(transferFile);
90
+        String chatId = new SnowFlake().generateId();
91
+        JSONObject jsonObject = new JSONObject();
92
+        jsonObject.put("chatId", chatId);
83
         String[] filenameSplit = file.getOriginalFilename().split("\\.");
93
         String[] filenameSplit = file.getOriginalFilename().split("\\.");
84
         String outputFilename = "/upload/agent/" + agentName + "/" + file.getOriginalFilename().replace(filenameSplit[filenameSplit.length - 2], filenameSplit[filenameSplit.length - 2] + "_" + agentName);
94
         String outputFilename = "/upload/agent/" + agentName + "/" + file.getOriginalFilename().replace(filenameSplit[filenameSplit.length - 2], filenameSplit[filenameSplit.length - 2] + "_" + agentName);
95
+        CmcDocument cmcDocument = new CmcDocument();
96
+        cmcDocument.setDocumentId(new SnowFlake().generateId());
97
+        cmcDocument.setChatId(chatId);
98
+        cmcDocument.setPath(outputFilename);
99
+        cmcDocumentMapper.insertCmcDocument(cmcDocument);
85
         String message = "";
100
         String message = "";
86
         if (agentName.contains("技术")) {
101
         if (agentName.contains("技术")) {
87
             XWPFDocument doc = new XWPFDocument(new FileInputStream(RuoYiConfig.getProfile() + "/upload/agent/template/technical.docx"));
102
             XWPFDocument doc = new XWPFDocument(new FileInputStream(RuoYiConfig.getProfile() + "/upload/agent/template/technical.docx"));
105
                     "8 职业健康、安全生产及环保水保措施\n\n" +
120
                     "8 职业健康、安全生产及环保水保措施\n\n" +
106
                     "请问您需要哪些章节撰写的帮助?";
121
                     "请问您需要哪些章节撰写的帮助?";
107
         }
122
         }
108
-        return message;
123
+        jsonObject.put("assistantMessage", message);
124
+        return jsonObject;
109
     }
125
     }
110
 
126
 
111
     /**
127
     /**

+ 1
- 5
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/service/impl/CmcDocumentServiceImpl.java Datei anzeigen

66
      * 上传外部文件
66
      * 上传外部文件
67
      *
67
      *
68
      * @param fileList 文件
68
      * @param fileList 文件
69
-     * @param agentName 智能体名称
70
      * @return 结果
69
      * @return 结果
71
      */
70
      */
72
     @Override
71
     @Override
73
-    public JSONObject uploadDocument(MultipartFile[] fileList, String agentName) throws IOException {
72
+    public JSONObject uploadDocument(MultipartFile[] fileList) throws IOException {
74
         String prefixPath = "";
73
         String prefixPath = "";
75
-        if (!agentName.equals(""))
76
-            prefixPath = "/upload/agent/" + agentName;
77
-        else
78
             prefixPath = "/upload/rag/document";
74
             prefixPath = "/upload/rag/document";
79
         File profilePath = new File( RuoYiConfig.getProfile() + prefixPath);
75
         File profilePath = new File( RuoYiConfig.getProfile() + prefixPath);
80
         if (!profilePath.exists())
76
         if (!profilePath.exists())

+ 1
- 11
llm-back/sql/cmc_llm.sql Datei anzeigen

57
 DROP TABLE IF EXISTS `cmc_topic`;
57
 DROP TABLE IF EXISTS `cmc_topic`;
58
 CREATE TABLE `cmc_topic`  (
58
 CREATE TABLE `cmc_topic`  (
59
   `topic_id` char(19) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '聊天主题id',
59
   `topic_id` char(19) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '聊天主题id',
60
+  `agent_id` int DEFAULT 0 COMMENT '智能体id',
60
   `topic` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '主题',
61
   `topic` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '主题',
61
   `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
62
   `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
62
   PRIMARY KEY (`topic_id`) USING BTREE
63
   PRIMARY KEY (`topic_id`) USING BTREE
76
   `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '描述',
77
   `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '描述',
77
   `create_by` bigint NULL DEFAULT NULL COMMENT '创建人',
78
   `create_by` bigint NULL DEFAULT NULL COMMENT '创建人',
78
   `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
79
   `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
79
-  `role_id` int NULL DEFAULT NULL COMMENT '角色id',
80
   PRIMARY KEY (`agent_id`) USING BTREE
80
   PRIMARY KEY (`agent_id`) USING BTREE
81
 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '智能体表' ROW_FORMAT = Dynamic;
81
 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '智能体表' ROW_FORMAT = Dynamic;
82
 
82
 
84
 -- Records of cmc_agent
84
 -- Records of cmc_agent
85
 -- ----------------------------
85
 -- ----------------------------
86
 
86
 
87
-DROP TABLE IF EXISTS `cmc_agent_tool`;
88
-CREATE TABLE `cmc_agent_tool`  (
89
-  `agent_tool_id` int NOT NULL COMMENT '智能体工具id',
90
-  `tool_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '工具描述',
91
-  `agent_id` int NULL DEFAULT NULL COMMENT '智能体id',
92
-  `tool_sort` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '顺序',
93
-  PRIMARY KEY (`agent_tool_id`) USING BTREE
94
-) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '智能体工具表' ROW_FORMAT = Dynamic;
95
-
96
-
97
 -- ----------------------------
87
 -- ----------------------------
98
 -- Table structure for gen_table
88
 -- Table structure for gen_table
99
 -- ----------------------------
89
 -- ----------------------------

+ 3
- 4
llm-ui/src/api/llm/document.js Datei anzeigen

1
 /*
1
 /*
2
  * @Author: ysh
2
  * @Author: ysh
3
  * @Date: 2025-06-13 10:35:45
3
  * @Date: 2025-06-13 10:35:45
4
- * @LastEditors: 
5
- * @LastEditTime: 2025-07-22 10:38:57
4
+ * @LastEditors: wrh
5
+ * @LastEditTime: 2025-07-29 17:48:55
6
  */
6
  */
7
 import request from '@/utils/request'
7
 import request from '@/utils/request'
8
 
8
 
51
 
51
 
52
 
52
 
53
 // 上传聊天外部文件
53
 // 上传聊天外部文件
54
-export function uploadDocument(fileList, agentName) {
54
+export function uploadDocument(fileList) {
55
   const formData = new FormData()
55
   const formData = new FormData()
56
   for (let f of fileList) {
56
   for (let f of fileList) {
57
     formData.append('fileList', f)
57
     formData.append('fileList', f)
58
   }
58
   }
59
-  formData.append('agentName', agentName)
60
   return request({
59
   return request({
61
     url: '/llm/document/upload',
60
     url: '/llm/document/upload',
62
     method: 'post',
61
     method: 'post',

+ 6
- 7
llm-ui/src/views/llm/agent/AgentDetail.vue Datei anzeigen

1
 <!--
1
 <!--
2
  * @Author: wrh
2
  * @Author: wrh
3
  * @Date: 2025-01-01 00:00:00
3
  * @Date: 2025-01-01 00:00:00
4
- * @LastEditors: Please set LastEditors
5
- * @LastEditTime: 2025-07-29 16:58:28
4
+ * @LastEditors: wrh
5
+ * @LastEditTime: 2025-07-29 17:45:58
6
 -->
6
 -->
7
 <template>
7
 <template>
8
   <div class="agent-detail-container" v-loading="loading">
8
   <div class="agent-detail-container" v-loading="loading">
165
 import { answer } from '@/api/llm/mcp';
165
 import { answer } from '@/api/llm/mcp';
166
 import { listTopic, getTopic, delTopic, addTopic, updateTopic } from "@/api/llm/topic";
166
 import { listTopic, getTopic, delTopic, addTopic, updateTopic } from "@/api/llm/topic";
167
 import { listChat, addChat, updateChat } from "@/api/llm/chat";
167
 import { listChat, addChat, updateChat } from "@/api/llm/chat";
168
-import { listDocument, uploadDocument } from "@/api/llm/document";
168
+import { listDocument } from "@/api/llm/document";
169
 import useUserStore from '@/store/modules/user'
169
 import useUserStore from '@/store/modules/user'
170
 
170
 
171
 const { proxy } = getCurrentInstance()
171
 const { proxy } = getCurrentInstance()
407
     const file = chatFileList.value[0].raw // 只取第一个文件
407
     const file = chatFileList.value[0].raw // 只取第一个文件
408
     const fileName = file.name;
408
     const fileName = file.name;
409
     const response = await uploadFile(file, agentInfo.value.agentName)
409
     const response = await uploadFile(file, agentInfo.value.agentName)
410
-    const fileRes = await uploadDocument([file]); // 保存上传的文件到数据库
411
-    const chatId = fileRes.data.chatId; //获取保存后的chatId
410
+    const chatId = response.data.chatId; //获取保存后的chatId
412
     // 解析返回的数据
411
     // 解析返回的数据
413
     let assistantContent = '文件上传成功!'
412
     let assistantContent = '文件上传成功!'
414
-    if (response.data && response.data.resultContent) {
413
+    if (response.data && response.data.assistantMessage) {
415
       // 格式化链接:在href前加上基础API地址
414
       // 格式化链接:在href前加上基础API地址
416
-      assistantContent = formatContentLinks(response.data.resultContent)
415
+      assistantContent = formatContentLinks(response.data.assistantMessage)
417
     }
416
     }
418
 
417
 
419
     // 添加上传成功的消息到聊天记录
418
     // 添加上传成功的消息到聊天记录

+ 2
- 2
llm-ui/src/views/llm/chat/index.vue Datei anzeigen

212
                         <el-icon class="file-icon">
212
                         <el-icon class="file-icon">
213
                           <Document />
213
                           <Document />
214
                         </el-icon>
214
                         </el-icon>
215
-                        <span class="file-name">{{ file.path }}</span>
215
+                        <span class="file-name">{{ file.path.split("/")[file.path.split("/").length - 1] }}</span>
216
                       </div>
216
                       </div>
217
                     </div>
217
                     </div>
218
                   </div>
218
                   </div>
590
     // 立即上传文件
590
     // 立即上传文件
591
     try {
591
     try {
592
       isUploading.value = true;
592
       isUploading.value = true;
593
-      let res = await uploadDocument(files, '');
593
+      let res = await uploadDocument(files);
594
       documentChatId.value = res.data.chatId;
594
       documentChatId.value = res.data.chatId;
595
       // 上传成功后,将文件添加到已上传列表
595
       // 上传成功后,将文件添加到已上传列表
596
       selectedFiles.value = [...selectedFiles.value, ...files];
596
       selectedFiles.value = [...selectedFiles.value, ...files];

Laden…
Abbrechen
Speichern