ソースを参照

上传文件后提示接下来可输入的关键词

lamphua 5日前
コミット
bc6d35c2c0

+ 11
- 1
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/controller/CmcAgentController.java ファイルの表示

@@ -5,6 +5,7 @@ import java.util.Date;
5 5
 import java.util.List;
6 6
 import javax.servlet.http.HttpServletResponse;
7 7
 
8
+import org.noear.solon.ai.chat.message.AssistantMessage;
8 9
 import org.springframework.beans.factory.annotation.Autowired;
9 10
 import org.springframework.web.bind.annotation.GetMapping;
10 11
 import org.springframework.web.bind.annotation.PostMapping;
@@ -69,6 +70,15 @@ public class CmcAgentController extends BaseController
69 70
         return success(cmcAgentService.selectCmcAgentByAgentId(agentId));
70 71
     }
71 72
 
73
+    /**
74
+     * 获取开场白
75
+     * @return
76
+     */
77
+    @GetMapping("/opening")
78
+    public AjaxResult opening(String agentName) {
79
+        return success(new AssistantMessage(cmcAgentService.getOpening(agentName)));
80
+    }
81
+
72 82
     /**
73 83
      * 上传单文件
74 84
      * @return
@@ -76,7 +86,7 @@ public class CmcAgentController extends BaseController
76 86
     @PostMapping("/upload")
77 87
     public AjaxResult upload(MultipartFile file, String agentName) throws IOException
78 88
     {
79
-        return success(cmcAgentService.uploadDocument(file, agentName));
89
+        return success(new AssistantMessage(cmcAgentService.uploadDocument(file, agentName)));
80 90
     }
81 91
 
82 92
     /**

+ 4
- 42
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/controller/McpController.java ファイルの表示

@@ -1,25 +1,17 @@
1 1
 package com.ruoyi.web.llm.controller;
2 2
 
3
-import com.alibaba.fastjson2.JSON;
4
-import com.alibaba.fastjson2.JSONArray;
5 3
 import com.alibaba.fastjson2.JSONObject;
6
-import com.ruoyi.common.config.RuoYiConfig;
7 4
 import com.ruoyi.common.core.controller.BaseController;
8
-import com.ruoyi.common.core.domain.AjaxResult;
9
-import org.noear.solon.ai.chat.ChatConfig;
10 5
 import org.noear.solon.ai.chat.ChatModel;
11 6
 import org.noear.solon.ai.chat.ChatResponse;
12 7
 import org.noear.solon.ai.chat.message.AssistantMessage;
13 8
 import org.noear.solon.ai.chat.message.ChatMessage;
14
-import org.noear.solon.ai.chat.message.SystemMessage;
15
-import org.noear.solon.ai.chat.tool.FunctionTool;
16 9
 import org.noear.solon.ai.mcp.client.McpClientProvider;
17 10
 import org.springframework.web.bind.annotation.GetMapping;
18 11
 import org.springframework.web.bind.annotation.RequestMapping;
19 12
 import org.springframework.web.bind.annotation.RestController;
20 13
 import org.springframework.web.multipart.MultipartFile;
21 14
 
22
-import java.io.File;
23 15
 import java.io.IOException;
24 16
 import java.util.*;
25 17
 
@@ -35,11 +27,11 @@ import java.util.*;
35 27
 public class McpController extends BaseController
36 28
 {
37 29
     /**
38
-     * 获取开场白
30
+     * 同步问答
39 31
      * @return
40 32
      */
41
-    @GetMapping("/opening")
42
-    public AssistantMessage opening(String agentName) throws IOException {
33
+    @GetMapping("/answer")
34
+    public AssistantMessage answer(String question) throws IOException {
43 35
         McpClientProvider clientProvider = McpClientProvider.builder()
44 36
                 .apiUrl("http://localhost:8080/llm/mcp/sse")
45 37
                 .build();
@@ -48,7 +40,7 @@ public class McpController extends BaseController
48 40
                 .model("Qwen2.5-1.5B-Instruct")
49 41
                 .defaultToolsAdd(clientProvider)
50 42
                 .build();
51
-        ChatResponse response = chatModel.prompt(agentName + "智能体开场白").call();
43
+        ChatResponse response = chatModel.prompt(question).call();
52 44
         String resultContent = response.lastChoice().getMessage().getResultContent();
53 45
         AssistantMessage assistantMessage = new AssistantMessage(resultContent);
54 46
         if (resultContent.startsWith("<tool_call>")) {
@@ -62,36 +54,6 @@ public class McpController extends BaseController
62 54
         return assistantMessage;
63 55
     }
64 56
 
65
-    /**
66
-     * 获取工具集
67
-     * @return
68
-     */
69
-    @GetMapping("/tools")
70
-    public AjaxResult tools() {
71
-        McpClientProvider clientProvider = McpClientProvider.builder()
72
-                .apiUrl("http://localhost:8080/llm/mcp/sse")
73
-                .build();
74
-
75
-        ChatConfig config = new ChatConfig();
76
-        config.addDefaultTools(clientProvider.getTools());
77
-        Collection<FunctionTool> tools = config.getDefaultTools();
78
-        JSONArray jsonArray = new JSONArray();
79
-        for (FunctionTool tool : tools) {
80
-            JSONObject jsonObject = new JSONObject();
81
-            jsonObject.put("description", tool.description());
82
-            JSONObject properties = JSON.parseObject(tool.inputSchema()).getJSONObject("properties");
83
-            List<String> requiredParams = JSON.parseObject(tool.inputSchema()).getList("required", String.class);
84
-            JSONArray paramArray = new JSONArray();
85
-            for (String param : requiredParams) {
86
-                JSONObject paramObject = new JSONObject();
87
-                paramObject.put("paramDescription", properties.getJSONObject(param).getString("description"));
88
-                paramArray.add(paramObject);
89
-            }
90
-            jsonObject.put("inputParam", paramArray);
91
-            jsonArray.add(jsonObject);
92
-        }
93
-        return success(jsonArray);
94
-    }
95 57
 
96 58
     /**
97 59
      * 根据招标文件要求编写投标文件技术方案

+ 0
- 14
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/domain/CmcAgent.java ファイルの表示

@@ -26,10 +26,6 @@ public class CmcAgent extends BaseEntity
26 26
     @Excel(name = "描述")
27 27
     private String description;
28 28
 
29
-    /** 角色id */
30
-    @Excel(name = "角色id")
31
-    private Long roleId;
32
-
33 29
     public void setAgentId(Integer agentId) 
34 30
     {
35 31
         this.agentId = agentId;
@@ -57,15 +53,6 @@ public class CmcAgent extends BaseEntity
57 53
     {
58 54
         return description;
59 55
     }
60
-    public void setRoleId(Long roleId) 
61
-    {
62
-        this.roleId = roleId;
63
-    }
64
-
65
-    public Long getRoleId() 
66
-    {
67
-        return roleId;
68
-    }
69 56
 
70 57
     @Override
71 58
     public String toString() {
@@ -75,7 +62,6 @@ public class CmcAgent extends BaseEntity
75 62
             .append("description", getDescription())
76 63
             .append("createBy", getCreateBy())
77 64
             .append("createTime", getCreateTime())
78
-            .append("roleId", getRoleId())
79 65
             .toString();
80 66
     }
81 67
 }

+ 8
- 0
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/service/ICmcAgentService.java ファイルの表示

@@ -30,6 +30,14 @@ public interface ICmcAgentService
30 30
      */
31 31
     public List<CmcAgent> selectCmcAgentList(CmcAgent cmcAgent);
32 32
 
33
+    /**
34
+     * 获取开场白
35
+     *
36
+     * @param agentName 智能体名称
37
+     * @return 结果
38
+     */
39
+    public String getOpening(String agentName);
40
+
33 41
     /**
34 42
      * 上传单文件
35 43
      *

+ 31
- 4
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/service/impl/CmcAgentServiceImpl.java ファイルの表示

@@ -52,6 +52,20 @@ public class CmcAgentServiceImpl implements ICmcAgentService
52 52
         return cmcAgentMapper.selectCmcAgentList(cmcAgent);
53 53
     }
54 54
 
55
+    /**
56
+     * 获取开场白
57
+     *
58
+     * @param agentName 智能体名称
59
+     * @return 结果
60
+     */
61
+    @Override
62
+    public String getOpening(String agentName) {
63
+        String content = "";
64
+        if (agentName.contains("技术"))
65
+            content = "我是投标文件写作助手,我将助您完成技术文件部分撰写。请上传招标询价文件,分析后将依招标服务要求,运用技术方案知识库,为您提供参考。";
66
+        return content;
67
+    }
68
+
55 69
     /**
56 70
      * 上传单文件
57 71
      *
@@ -68,17 +82,30 @@ public class CmcAgentServiceImpl implements ICmcAgentService
68 82
             file.transferTo(transferFile);
69 83
         String[] filenameSplit = file.getOriginalFilename().split("\\.");
70 84
         String outputFilename = "/upload/agent/" + agentName + "/" + file.getOriginalFilename().replace(filenameSplit[filenameSplit.length - 2], filenameSplit[filenameSplit.length - 2] + "_" + agentName);
85
+        String message = "";
71 86
         if (agentName.contains("技术")) {
72
-            XWPFDocument doc = new XWPFDocument(new FileInputStream(RuoYiConfig.getProfile() + "/upload/agent/technical/template/technical.docx"));
87
+            XWPFDocument doc = new XWPFDocument(new FileInputStream(RuoYiConfig.getProfile() + "/upload/agent/template/technical.docx"));
73 88
             // 保存文档到本地文件系统
74 89
             FileOutputStream out = new FileOutputStream(RuoYiConfig.getProfile() + outputFilename);
75 90
             doc.write(out);
76
-            out.close();
77
-
78 91
             // 关闭文档
92
+            out.close();
79 93
             doc.close();
94
+            
95
+            message = "好的,我已经收到您上传的招标文件,我将给您提供技术文件模板,您可点击进行预览:" +
96
+                    "【<a href='/profile" + outputFilename + "'> 模版 " + "</a>】\n\n" +
97
+                    "技术文件涉及多个章节:\n" +
98
+                    "1 项目条件及特性\n" +
99
+                    "2 项目重点和难点的分析与对策\n" +
100
+                    "3 项目策划、技术路线、工作方法、流程及措施\n" +
101
+                    "4 资源配置\n" +
102
+                    "5 进度计划及保证措施\n" +
103
+                    "6 质量保证措施\n" +
104
+                    "7 服务与技术支持\n" +
105
+                    "8 职业健康、安全生产及环保水保措施\n\n" +
106
+                    "请问您需要哪些章节撰写的帮助?";
80 107
         }
81
-        return outputFilename;
108
+        return message;
82 109
     }
83 110
 
84 111
     /**

+ 1
- 6
llm-back/ruoyi-system/src/main/resources/mapper/llm/CmcAgentMapper.xml ファイルの表示

@@ -10,11 +10,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
10 10
         <result property="description"    column="description"    />
11 11
         <result property="createBy"    column="create_by"    />
12 12
         <result property="createTime"    column="create_time"    />
13
-        <result property="roleId"    column="role_id"    />
14 13
     </resultMap>
15 14
 
16 15
     <sql id="selectCmcAgentVo">
17
-        select agent_id, agent_name, description, create_by, create_time, role_id from cmc_agent
16
+        select agent_id, agent_name, description, create_by, create_time from cmc_agent
18 17
     </sql>
19 18
 
20 19
     <select id="selectCmcAgentList" parameterType="CmcAgent" resultMap="CmcAgentResult">
@@ -22,7 +21,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
22 21
         <where>  
23 22
             <if test="agentName != null  and agentName != ''"> and agent_name like concat('%', #{agentName}, '%')</if>
24 23
             <if test="description != null  and description != ''"> and description = #{description}</if>
25
-            <if test="roleId != null "> and role_id = #{roleId}</if>
26 24
         </where>
27 25
     </select>
28 26
     
@@ -38,14 +36,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
38 36
             <if test="description != null">description,</if>
39 37
             <if test="createBy != null">create_by,</if>
40 38
             <if test="createTime != null">create_time,</if>
41
-            <if test="roleId != null">role_id,</if>
42 39
          </trim>
43 40
         <trim prefix="values (" suffix=")" suffixOverrides=",">
44 41
             <if test="agentName != null">#{agentName},</if>
45 42
             <if test="description != null">#{description},</if>
46 43
             <if test="createBy != null">#{createBy},</if>
47 44
             <if test="createTime != null">#{createTime},</if>
48
-            <if test="roleId != null">#{roleId},</if>
49 45
          </trim>
50 46
     </insert>
51 47
 
@@ -56,7 +52,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
56 52
             <if test="description != null">description = #{description},</if>
57 53
             <if test="createBy != null">create_by = #{createBy},</if>
58 54
             <if test="createTime != null">create_time = #{createTime},</if>
59
-            <if test="roleId != null">role_id = #{roleId},</if>
60 55
         </trim>
61 56
         where agent_id = #{agentId}
62 57
     </update>

+ 9
- 0
llm-ui/src/api/llm/agent.js ファイルの表示

@@ -80,3 +80,12 @@ export function uploadFileList(fileList, agentName) {
80 80
     }
81 81
   })
82 82
 }
83
+
84
+//获取开场白, agentName:智能体名称
85
+export function opening(agentName) {
86
+  return request({
87
+    url: '/llm/agent/opening',
88
+    method: 'get',
89
+    params: { agentName }
90
+  })
91
+}

+ 6
- 6
llm-ui/src/api/llm/mcp.js ファイルの表示

@@ -1,16 +1,16 @@
1 1
 /*
2 2
  * @Author: ysh
3 3
  * @Date: 2025-07-25 14:52:22
4
- * @LastEditors: 
5
- * @LastEditTime: 2025-07-25 14:53:25
4
+ * @LastEditors: wrh
5
+ * @LastEditTime: 2025-07-28 09:48:43
6 6
  */
7 7
 import request from '@/utils/request'
8 8
 
9
-//获取开场白, agentName:智能体名称
10
-export function opening(agentName) {
9
+// 同步回答
10
+export function answer(query) {
11 11
   return request({
12
-    url: '/llm/mcp/opening',
12
+    url: '/llm/mcp/answer',
13 13
     method: 'get',
14
-    params: { agentName }
14
+    params: query
15 15
   })
16 16
 }

+ 4
- 4
llm-ui/src/views/llm/agent/index.vue ファイルの表示

@@ -1,8 +1,8 @@
1 1
 <!--
2 2
  * @Author: ysh
3 3
  * @Date: 2025-07-17 18:16:50
4
- * @LastEditors: Please set LastEditors
5
- * @LastEditTime: 2025-07-25 15:30:21
4
+ * @LastEditors: wrh
5
+ * @LastEditTime: 2025-07-28 09:47:19
6 6
 -->
7 7
 <template>
8 8
   <div class="agent-container">
@@ -114,8 +114,8 @@
114 114
 <script setup>
115 115
 import { ref, reactive, onMounted } from 'vue'
116 116
 import { ElMessage, ElMessageBox } from 'element-plus'
117
-import { listAgent, addAgent, updateAgent, delAgent } from '@/api/llm/agent'
118
-import { opening } from '@/api/llm/mcp'
117
+import { listAgent, addAgent, updateAgent, delAgent, opening } from '@/api/llm/agent'
118
+import { answer } from '@/api/llm/mcp'
119 119
 
120 120
 // 响应式数据
121 121
 const loading = ref(false)

読み込み中…
キャンセル
保存