Browse Source

技术标智能体开场白

lamphua 1 week ago
parent
commit
8df6743481

+ 14
- 29
llm-back/ruoyi-agent/src/main/java/com/ruoyi/agent/service/impl/McpServiceImpl.java View File

@@ -21,11 +21,6 @@ import java.util.Collections;
21 21
 @McpServerEndpoint(sseEndpoint = "/llm/mcp/sse")
22 22
 public class McpServiceImpl implements IMcpService {
23 23
 
24
-    @ToolMapping(description = "查询天气预报")
25
-    public String getWeather(@Param(description = "城市位置") String location) {
26
-        return "晴,14度";
27
-    }
28
-
29 24
     @ToolMapping(description = "查看招标文档")
30 25
     public String openDocument(@Param(description = "文件路径") String document) throws IOException {
31 26
         try (XWPFDocument doc = new XWPFDocument(new FileInputStream(document))) {
@@ -37,25 +32,21 @@ public class McpServiceImpl implements IMcpService {
37 32
         }
38 33
     }
39 34
 
40
-    @ToolMapping(description = "编制技术方案")
41
-    public String openDocument(@Param(description = "招标文件") String inviteDocument, @Param(description = "投标文件") String submitDocument) throws IOException {
42
-        try (XWPFDocument doc = new XWPFDocument(new FileInputStream(inviteDocument))) {
43
-            StringBuilder content = new StringBuilder();
44
-            for (XWPFParagraph paragraph : doc.getParagraphs()) {
45
-                content.append(paragraph.getText()).append("\n");
46
-            }
47
-            return content.toString();
48
-        }
35
+    @ToolMapping(description = "开场白")
36
+    public String opening(@Param(description = "智能体名称") String agentName) {
37
+        String content = "";
38
+        if (agentName.contains("技术"))
39
+            content = "我是投标文件写作助手,我将助您完成技术文件部分撰写。请上传招标询价文件,分析后将依招标服务要求,运用技术方案知识库,为您提供参考。";
40
+        return content;
49 41
     }
50 42
 
51 43
     @ToolMapping(description = "补全技术方案")
52 44
     public String writeTechnicalPlan(@Param(description = "文件路径") String document, @Param(description = "技术方案内容") String resultContent) throws IOException {
53 45
         // 创建临时输出文件路径
54
-        String outputPath = document.replace(".docx", "_修改" + System.currentTimeMillis() + ".docx");
55 46
 
56 47
         try (FileInputStream fis = new FileInputStream(document);
57 48
              XWPFDocument doc = new XWPFDocument(fis);
58
-             FileOutputStream fos = new FileOutputStream(outputPath)) {
49
+             FileOutputStream fos = new FileOutputStream(document)) {
59 50
 
60 51
             // 在最后添加分页符和新内容
61 52
             XWPFParagraph pageBreak = doc.createParagraph();
@@ -67,26 +58,20 @@ public class McpServiceImpl implements IMcpService {
67 58
             // 保存文档
68 59
             doc.write(fos);
69 60
 
70
-            return "技术方案添加完成,已保存到: " + outputPath;
61
+            return "技术方案添加完成,已保存到: " + document;
71 62
         } catch (IOException e) {
72 63
             throw new IOException("处理Word文档时出错: " + e.getMessage(), e);
73 64
         }
74 65
     }
75 66
 
76
-    @ResourceMapping(uri = "config://app-version", description = "获取应用版本号")
77
-    public String getAppVersion() {
78
-        return "v3.2.0";
79
-    }
80
-
81
-    @ResourceMapping(uri = "db://users/{user_id}/email", description = "根据用户ID查询邮箱")
82
-    public String getEmail(@Param(description = "用户Id") String user_id) {
83
-        return user_id + "@example.com";
84
-    }
85
-
86 67
     @PromptMapping(description = "提出技术问题")
87
-    public Collection<ChatMessage> askQuestion(@Param(description = "描述招标文件服务要求") String request) {
68
+    public Collection<ChatMessage> askQuestion(@Param(description = "描述招标文件服务要求") String request,
69
+                                               @Param(description = "参考上下文") String contexts,
70
+                                               @Param(description = "补充文字部分") String part) {
88 71
         return Collections.singletonList(
89
-                ChatMessage.ofUser("请根据以下要求:'" + request + "\n编写技术方案")
72
+                ChatMessage.ofUser("请根据以下要求:'" + request + "\n" +
73
+                        "参考上下文:'" + contexts + "\n" +
74
+                        "回答以下问题:'" + part + "\n")
90 75
         );
91 76
     }
92 77
 }

+ 3
- 0
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/controller/CmcAgentController.java View File

@@ -1,6 +1,7 @@
1 1
 package com.ruoyi.web.llm.controller;
2 2
 
3 3
 import java.io.IOException;
4
+import java.util.Date;
4 5
 import java.util.List;
5 6
 import javax.servlet.http.HttpServletResponse;
6 7
 
@@ -95,6 +96,8 @@ public class CmcAgentController extends BaseController
95 96
     @PostMapping
96 97
     public AjaxResult add(@RequestBody CmcAgent cmcAgent)
97 98
     {
99
+        cmcAgent.setCreateTime(new Date());
100
+        cmcAgent.setCreateBy(getLoginUser().getUserId().toString());
98 101
         return toAjax(cmcAgentService.insertCmcAgent(cmcAgent));
99 102
     }
100 103
 

+ 0
- 6
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/controller/CmcDocumentController.java View File

@@ -1,15 +1,9 @@
1 1
 package com.ruoyi.web.llm.controller;
2 2
 
3
-import java.io.File;
4 3
 import java.io.IOException;
5
-import java.util.ArrayList;
6 4
 import java.util.List;
7 5
 import javax.servlet.http.HttpServletResponse;
8 6
 
9
-import com.alibaba.fastjson2.JSONObject;
10
-import com.ruoyi.common.config.RuoYiConfig;
11
-import com.ruoyi.common.utils.SnowFlake;
12
-import com.ruoyi.llm.domain.CmcChat;
13 7
 import org.springframework.beans.factory.annotation.Autowired;
14 8
 import org.springframework.web.bind.annotation.GetMapping;
15 9
 import org.springframework.web.bind.annotation.PostMapping;

+ 8
- 16
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/controller/McpController.java View File

@@ -11,6 +11,7 @@ import org.noear.solon.ai.chat.ChatModel;
11 11
 import org.noear.solon.ai.chat.ChatResponse;
12 12
 import org.noear.solon.ai.chat.message.AssistantMessage;
13 13
 import org.noear.solon.ai.chat.message.ChatMessage;
14
+import org.noear.solon.ai.chat.message.SystemMessage;
14 15
 import org.noear.solon.ai.chat.tool.FunctionTool;
15 16
 import org.noear.solon.ai.mcp.client.McpClientProvider;
16 17
 import org.springframework.web.bind.annotation.GetMapping;
@@ -34,21 +35,20 @@ import java.util.*;
34 35
 public class McpController extends BaseController
35 36
 {
36 37
     /**
37
-     * 同步问答
38
+     * 获取开场白
38 39
      * @return
39 40
      */
40
-    @GetMapping("/answer")
41
-    public AssistantMessage answer(String question) throws IOException {
41
+    @GetMapping("/opening")
42
+    public AssistantMessage opening(String agentName) throws IOException {
42 43
         McpClientProvider clientProvider = McpClientProvider.builder()
43 44
                 .apiUrl("http://localhost:8080/llm/mcp/sse")
44 45
                 .build();
45
-
46 46
         ChatModel chatModel = ChatModel.of("http://192.168.28.188:8000/v1/chat/completions")
47 47
                 .provider("openai")
48 48
                 .model("Qwen2.5-1.5B-Instruct")
49 49
                 .defaultToolsAdd(clientProvider)
50 50
                 .build();
51
-        ChatResponse response = chatModel.prompt(question).call();
51
+        ChatResponse response = chatModel.prompt(agentName + "智能体开场白").call();
52 52
         String resultContent = response.lastChoice().getMessage().getResultContent();
53 53
         AssistantMessage assistantMessage = new AssistantMessage(resultContent);
54 54
         if (resultContent.startsWith("<tool_call>")) {
@@ -107,24 +107,16 @@ public class McpController extends BaseController
107 107
                 .model("DeepSeek-R1-Distill-Qwen-1.5B")
108 108
                 .defaultToolsAdd(clientProvider)
109 109
                 .build();
110
-        File profilePath = new File( RuoYiConfig.getProfile() + "/upload/knowledge");
111
-        if (!profilePath.exists())
112
-            profilePath.mkdirs();
113
-        File transferFile = new File( profilePath + File.separator + file.getOriginalFilename());
114
-        if (!transferFile.exists())
115
-            file.transferTo(transferFile);
116 110
         Map<String,Object> path = new HashMap<>();
117
-        path.put("document", transferFile.getPath());
118 111
         String content = clientProvider.callToolAsText("openDocument", path).getContent();
119 112
         Map<String,Object> request = new HashMap<>();
120 113
         request.put("request", content);
121 114
         List<ChatMessage> messages = clientProvider.getPromptAsMessages("askQuestion", request);
122 115
         ChatResponse response = chatModel.prompt(messages).call();
123 116
         System.out.println(response.getChoices().get(0).getMessage());
124
-//        Map<String,Object> write = new HashMap<>();
125
-//        write.put("document", transferFile.getPath());
126
-//        write.put("resultContent", response.getChoices().get(0).getMessage().getResultContent());
127
-//        String res = clientProvider.callToolAsText("writeTechnicalPlan", write).getContent();
117
+        Map<String,Object> write = new HashMap<>();
118
+        write.put("resultContent", response.getChoices().get(0).getMessage().getResultContent());
119
+        String res = clientProvider.callToolAsText("writeTechnicalPlan", write).getContent();
128 120
         return response.getChoices().get(0).getMessage();
129 121
     }
130 122
 

+ 3
- 3
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/service/impl/LangChainMilvusServiceImpl.java View File

@@ -176,11 +176,11 @@ public class LangChainMilvusServiceImpl implements ILangChainMilvusService
176 176
         StringBuilder sb = new StringBuilder();
177 177
         sb.append("问题: ").append(question).append("\n\n");
178 178
         sb.append("根据以下上下文回答问题:\n\n");
179
-        for (int i = 0; i < contexts.size(); i++) {
179
+        for (JSONObject context : contexts) {
180 180
             sb.append("文件").append(": ")
181
-                    .append(contexts.get(i).getString("file_name")).append("\n\n")
181
+                    .append(context.getString("file_name")).append("\n\n")
182 182
                     .append("上下文").append(": ")
183
-                    .append(contexts.get(i).getString("content")).append("\n\n");
183
+                    .append(context.getString("content")).append("\n\n");
184 184
         }
185 185
         return generateAnswer(topicId, sb.toString(), llmServiceUrl);
186 186
     }

+ 0
- 1
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/service/ICmcAgentService.java View File

@@ -3,7 +3,6 @@ package com.ruoyi.llm.service;
3 3
 import java.io.IOException;
4 4
 import java.util.List;
5 5
 
6
-import com.alibaba.fastjson2.JSONObject;
7 6
 import com.ruoyi.llm.domain.CmcAgent;
8 7
 import org.springframework.web.multipart.MultipartFile;
9 8
 

+ 15
- 1
llm-back/ruoyi-system/src/main/java/com/ruoyi/llm/service/impl/CmcAgentServiceImpl.java View File

@@ -1,11 +1,14 @@
1 1
 package com.ruoyi.llm.service.impl;
2 2
 
3 3
 import java.io.File;
4
+import java.io.FileInputStream;
5
+import java.io.FileOutputStream;
4 6
 import java.io.IOException;
5 7
 import java.util.List;
6 8
 
7 9
 import com.ruoyi.common.config.RuoYiConfig;
8 10
 import com.ruoyi.common.utils.DateUtils;
11
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
9 12
 import org.springframework.beans.factory.annotation.Autowired;
10 13
 import org.springframework.stereotype.Service;
11 14
 import com.ruoyi.llm.mapper.CmcAgentMapper;
@@ -64,7 +67,18 @@ public class CmcAgentServiceImpl implements ICmcAgentService
64 67
         if (!transferFile.exists())
65 68
             file.transferTo(transferFile);
66 69
         String[] filenameSplit = file.getOriginalFilename().split("\\.");
67
-        return "/upload/agent/" + agentName + File.separator + file.getOriginalFilename().replace(filenameSplit[filenameSplit.length - 2], filenameSplit[filenameSplit.length - 2] + "_" + agentName);
70
+        String outputFilename = "/upload/agent/" + agentName + "/" + file.getOriginalFilename().replace(filenameSplit[filenameSplit.length - 2], filenameSplit[filenameSplit.length - 2] + "_" + agentName);
71
+        if (agentName.contains("技术")) {
72
+            XWPFDocument doc = new XWPFDocument(new FileInputStream(RuoYiConfig.getProfile() + "/upload/agent/technical/template/technical.docx"));
73
+            // 保存文档到本地文件系统
74
+            FileOutputStream out = new FileOutputStream(RuoYiConfig.getProfile() + outputFilename);
75
+            doc.write(out);
76
+            out.close();
77
+
78
+            // 关闭文档
79
+            doc.close();
80
+        }
81
+        return outputFilename;
68 82
     }
69 83
 
70 84
     /**

Loading…
Cancel
Save