Преглед на файлове

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

lamphua преди 5 дни
родител
ревизия
bc6d35c2c0

+ 11
- 1
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/controller/CmcAgentController.java Целия файл

5
 import java.util.List;
5
 import java.util.List;
6
 import javax.servlet.http.HttpServletResponse;
6
 import javax.servlet.http.HttpServletResponse;
7
 
7
 
8
+import org.noear.solon.ai.chat.message.AssistantMessage;
8
 import org.springframework.beans.factory.annotation.Autowired;
9
 import org.springframework.beans.factory.annotation.Autowired;
9
 import org.springframework.web.bind.annotation.GetMapping;
10
 import org.springframework.web.bind.annotation.GetMapping;
10
 import org.springframework.web.bind.annotation.PostMapping;
11
 import org.springframework.web.bind.annotation.PostMapping;
69
         return success(cmcAgentService.selectCmcAgentByAgentId(agentId));
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
      * @return
84
      * @return
76
     @PostMapping("/upload")
86
     @PostMapping("/upload")
77
     public AjaxResult upload(MultipartFile file, String agentName) throws IOException
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
 package com.ruoyi.web.llm.controller;
1
 package com.ruoyi.web.llm.controller;
2
 
2
 
3
-import com.alibaba.fastjson2.JSON;
4
-import com.alibaba.fastjson2.JSONArray;
5
 import com.alibaba.fastjson2.JSONObject;
3
 import com.alibaba.fastjson2.JSONObject;
6
-import com.ruoyi.common.config.RuoYiConfig;
7
 import com.ruoyi.common.core.controller.BaseController;
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
 import org.noear.solon.ai.chat.ChatModel;
5
 import org.noear.solon.ai.chat.ChatModel;
11
 import org.noear.solon.ai.chat.ChatResponse;
6
 import org.noear.solon.ai.chat.ChatResponse;
12
 import org.noear.solon.ai.chat.message.AssistantMessage;
7
 import org.noear.solon.ai.chat.message.AssistantMessage;
13
 import org.noear.solon.ai.chat.message.ChatMessage;
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
 import org.noear.solon.ai.mcp.client.McpClientProvider;
9
 import org.noear.solon.ai.mcp.client.McpClientProvider;
17
 import org.springframework.web.bind.annotation.GetMapping;
10
 import org.springframework.web.bind.annotation.GetMapping;
18
 import org.springframework.web.bind.annotation.RequestMapping;
11
 import org.springframework.web.bind.annotation.RequestMapping;
19
 import org.springframework.web.bind.annotation.RestController;
12
 import org.springframework.web.bind.annotation.RestController;
20
 import org.springframework.web.multipart.MultipartFile;
13
 import org.springframework.web.multipart.MultipartFile;
21
 
14
 
22
-import java.io.File;
23
 import java.io.IOException;
15
 import java.io.IOException;
24
 import java.util.*;
16
 import java.util.*;
25
 
17
 
35
 public class McpController extends BaseController
27
 public class McpController extends BaseController
36
 {
28
 {
37
     /**
29
     /**
38
-     * 获取开场白
30
+     * 同步问答
39
      * @return
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
         McpClientProvider clientProvider = McpClientProvider.builder()
35
         McpClientProvider clientProvider = McpClientProvider.builder()
44
                 .apiUrl("http://localhost:8080/llm/mcp/sse")
36
                 .apiUrl("http://localhost:8080/llm/mcp/sse")
45
                 .build();
37
                 .build();
48
                 .model("Qwen2.5-1.5B-Instruct")
40
                 .model("Qwen2.5-1.5B-Instruct")
49
                 .defaultToolsAdd(clientProvider)
41
                 .defaultToolsAdd(clientProvider)
50
                 .build();
42
                 .build();
51
-        ChatResponse response = chatModel.prompt(agentName + "智能体开场白").call();
43
+        ChatResponse response = chatModel.prompt(question).call();
52
         String resultContent = response.lastChoice().getMessage().getResultContent();
44
         String resultContent = response.lastChoice().getMessage().getResultContent();
53
         AssistantMessage assistantMessage = new AssistantMessage(resultContent);
45
         AssistantMessage assistantMessage = new AssistantMessage(resultContent);
54
         if (resultContent.startsWith("<tool_call>")) {
46
         if (resultContent.startsWith("<tool_call>")) {
62
         return assistantMessage;
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
     @Excel(name = "描述")
26
     @Excel(name = "描述")
27
     private String description;
27
     private String description;
28
 
28
 
29
-    /** 角色id */
30
-    @Excel(name = "角色id")
31
-    private Long roleId;
32
-
33
     public void setAgentId(Integer agentId) 
29
     public void setAgentId(Integer agentId) 
34
     {
30
     {
35
         this.agentId = agentId;
31
         this.agentId = agentId;
57
     {
53
     {
58
         return description;
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
     @Override
57
     @Override
71
     public String toString() {
58
     public String toString() {
75
             .append("description", getDescription())
62
             .append("description", getDescription())
76
             .append("createBy", getCreateBy())
63
             .append("createBy", getCreateBy())
77
             .append("createTime", getCreateTime())
64
             .append("createTime", getCreateTime())
78
-            .append("roleId", getRoleId())
79
             .toString();
65
             .toString();
80
     }
66
     }
81
 }
67
 }

+ 8
- 0
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/service/ICmcAgentService.java Целия файл

30
      */
30
      */
31
     public List<CmcAgent> selectCmcAgentList(CmcAgent cmcAgent);
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
         return cmcAgentMapper.selectCmcAgentList(cmcAgent);
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
             file.transferTo(transferFile);
82
             file.transferTo(transferFile);
69
         String[] filenameSplit = file.getOriginalFilename().split("\\.");
83
         String[] filenameSplit = file.getOriginalFilename().split("\\.");
70
         String outputFilename = "/upload/agent/" + agentName + "/" + file.getOriginalFilename().replace(filenameSplit[filenameSplit.length - 2], filenameSplit[filenameSplit.length - 2] + "_" + agentName);
84
         String outputFilename = "/upload/agent/" + agentName + "/" + file.getOriginalFilename().replace(filenameSplit[filenameSplit.length - 2], filenameSplit[filenameSplit.length - 2] + "_" + agentName);
85
+        String message = "";
71
         if (agentName.contains("技术")) {
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
             FileOutputStream out = new FileOutputStream(RuoYiConfig.getProfile() + outputFilename);
89
             FileOutputStream out = new FileOutputStream(RuoYiConfig.getProfile() + outputFilename);
75
             doc.write(out);
90
             doc.write(out);
76
-            out.close();
77
-
78
             // 关闭文档
91
             // 关闭文档
92
+            out.close();
79
             doc.close();
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
         <result property="description"    column="description"    />
10
         <result property="description"    column="description"    />
11
         <result property="createBy"    column="create_by"    />
11
         <result property="createBy"    column="create_by"    />
12
         <result property="createTime"    column="create_time"    />
12
         <result property="createTime"    column="create_time"    />
13
-        <result property="roleId"    column="role_id"    />
14
     </resultMap>
13
     </resultMap>
15
 
14
 
16
     <sql id="selectCmcAgentVo">
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
     </sql>
17
     </sql>
19
 
18
 
20
     <select id="selectCmcAgentList" parameterType="CmcAgent" resultMap="CmcAgentResult">
19
     <select id="selectCmcAgentList" parameterType="CmcAgent" resultMap="CmcAgentResult">
22
         <where>  
21
         <where>  
23
             <if test="agentName != null  and agentName != ''"> and agent_name like concat('%', #{agentName}, '%')</if>
22
             <if test="agentName != null  and agentName != ''"> and agent_name like concat('%', #{agentName}, '%')</if>
24
             <if test="description != null  and description != ''"> and description = #{description}</if>
23
             <if test="description != null  and description != ''"> and description = #{description}</if>
25
-            <if test="roleId != null "> and role_id = #{roleId}</if>
26
         </where>
24
         </where>
27
     </select>
25
     </select>
28
     
26
     
38
             <if test="description != null">description,</if>
36
             <if test="description != null">description,</if>
39
             <if test="createBy != null">create_by,</if>
37
             <if test="createBy != null">create_by,</if>
40
             <if test="createTime != null">create_time,</if>
38
             <if test="createTime != null">create_time,</if>
41
-            <if test="roleId != null">role_id,</if>
42
          </trim>
39
          </trim>
43
         <trim prefix="values (" suffix=")" suffixOverrides=",">
40
         <trim prefix="values (" suffix=")" suffixOverrides=",">
44
             <if test="agentName != null">#{agentName},</if>
41
             <if test="agentName != null">#{agentName},</if>
45
             <if test="description != null">#{description},</if>
42
             <if test="description != null">#{description},</if>
46
             <if test="createBy != null">#{createBy},</if>
43
             <if test="createBy != null">#{createBy},</if>
47
             <if test="createTime != null">#{createTime},</if>
44
             <if test="createTime != null">#{createTime},</if>
48
-            <if test="roleId != null">#{roleId},</if>
49
          </trim>
45
          </trim>
50
     </insert>
46
     </insert>
51
 
47
 
56
             <if test="description != null">description = #{description},</if>
52
             <if test="description != null">description = #{description},</if>
57
             <if test="createBy != null">create_by = #{createBy},</if>
53
             <if test="createBy != null">create_by = #{createBy},</if>
58
             <if test="createTime != null">create_time = #{createTime},</if>
54
             <if test="createTime != null">create_time = #{createTime},</if>
59
-            <if test="roleId != null">role_id = #{roleId},</if>
60
         </trim>
55
         </trim>
61
         where agent_id = #{agentId}
56
         where agent_id = #{agentId}
62
     </update>
57
     </update>

+ 9
- 0
llm-ui/src/api/llm/agent.js Целия файл

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
 /*
1
 /*
2
  * @Author: ysh
2
  * @Author: ysh
3
  * @Date: 2025-07-25 14:52:22
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
 import request from '@/utils/request'
7
 import request from '@/utils/request'
8
 
8
 
9
-//获取开场白, agentName:智能体名称
10
-export function opening(agentName) {
9
+// 同步回答
10
+export function answer(query) {
11
   return request({
11
   return request({
12
-    url: '/llm/mcp/opening',
12
+    url: '/llm/mcp/answer',
13
     method: 'get',
13
     method: 'get',
14
-    params: { agentName }
14
+    params: query
15
   })
15
   })
16
 }
16
 }

+ 4
- 4
llm-ui/src/views/llm/agent/index.vue Целия файл

1
 <!--
1
 <!--
2
  * @Author: ysh
2
  * @Author: ysh
3
  * @Date: 2025-07-17 18:16:50
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
 <template>
7
 <template>
8
   <div class="agent-container">
8
   <div class="agent-container">
114
 <script setup>
114
 <script setup>
115
 import { ref, reactive, onMounted } from 'vue'
115
 import { ref, reactive, onMounted } from 'vue'
116
 import { ElMessage, ElMessageBox } from 'element-plus'
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
 const loading = ref(false)
121
 const loading = ref(false)

Loading…
Отказ
Запис