소스 검색

根据招标文件要求编写技术方案到新文件

lamphua 1 일 전
부모
커밋
0b41cdd5af

+ 34
- 8
llm-back/ruoyi-agent/src/main/java/com/ruoyi/agent/service/impl/McpServiceImpl.java 파일 보기

12
 import org.springframework.stereotype.Service;
12
 import org.springframework.stereotype.Service;
13
 
13
 
14
 import java.io.FileInputStream;
14
 import java.io.FileInputStream;
15
+import java.io.FileOutputStream;
15
 import java.io.IOException;
16
 import java.io.IOException;
16
 import java.util.Arrays;
17
 import java.util.Arrays;
17
 import java.util.Collection;
18
 import java.util.Collection;
19
+import java.util.Collections;
18
 
20
 
19
 @Service
21
 @Service
20
 @McpServerEndpoint(sseEndpoint = "/llm/mcp/sse")
22
 @McpServerEndpoint(sseEndpoint = "/llm/mcp/sse")
25
         return "晴,14度";
27
         return "晴,14度";
26
     }
28
     }
27
 
29
 
28
-    @ToolMapping(description = "查看word文档")
29
-    public String openDocument() throws IOException {
30
-        String filePath = "C:\\Users\\lamphua\\Desktop\\智慧水利\\李家岩水库数字孪生招标文件.DOCX";
31
-        try (XWPFDocument doc = new XWPFDocument(new FileInputStream(filePath))) {
30
+    @ToolMapping(description = "查看招标文档")
31
+    public String openDocument(@Param(description = "文件路径") String document) throws IOException {
32
+        try (XWPFDocument doc = new XWPFDocument(new FileInputStream(document))) {
32
             StringBuilder content = new StringBuilder();
33
             StringBuilder content = new StringBuilder();
33
             for (XWPFParagraph paragraph : doc.getParagraphs()) {
34
             for (XWPFParagraph paragraph : doc.getParagraphs()) {
34
                 content.append(paragraph.getText()).append("\n");
35
                 content.append(paragraph.getText()).append("\n");
37
         }
38
         }
38
     }
39
     }
39
 
40
 
41
+    @ToolMapping(description = "补全技术方案")
42
+    public String writeTechnicalPlan(@Param(description = "文件路径") String document, @Param(description = "技术方案内容") String resultContent) throws IOException {
43
+        // 创建临时输出文件路径
44
+        String outputPath = document.replace(".docx", "_modified.docx");
45
+
46
+        try (FileInputStream fis = new FileInputStream(document);
47
+             XWPFDocument doc = new XWPFDocument(fis);
48
+             FileOutputStream fos = new FileOutputStream(outputPath)) {
49
+
50
+            // 在最后添加分页符和新内容
51
+            XWPFParagraph pageBreak = doc.createParagraph();
52
+            pageBreak.setPageBreak(true);
53
+
54
+            XWPFParagraph newContent = doc.createParagraph();
55
+            newContent.createRun().setText(resultContent);
56
+
57
+            // 保存文档
58
+            doc.write(fos);
59
+
60
+            return "技术方案添加完成,已保存到: " + outputPath;
61
+        } catch (IOException e) {
62
+            throw new IOException("处理Word文档时出错: " + e.getMessage(), e);
63
+        }
64
+    }
65
+
40
     @ResourceMapping(uri = "config://app-version", description = "获取应用版本号")
66
     @ResourceMapping(uri = "config://app-version", description = "获取应用版本号")
41
     public String getAppVersion() {
67
     public String getAppVersion() {
42
         return "v3.2.0";
68
         return "v3.2.0";
47
         return user_id + "@example.com";
73
         return user_id + "@example.com";
48
     }
74
     }
49
 
75
 
50
-    @PromptMapping(description = "生成关于某个主题的提问")
51
-    public Collection<ChatMessage> askQuestion(@Param(description = "主题") String topic) {
52
-        return Arrays.asList(
53
-                ChatMessage.ofUser("请解释一下'" + topic + "'的概念?")
76
+    @PromptMapping(description = "提出技术")
77
+    public Collection<ChatMessage> askQuestion(@Param(description = "描述招标文件服务要求") String request) {
78
+        return Collections.singletonList(
79
+                ChatMessage.ofUser("请根据以下要求:'" + request + "\n编写技术方案")
54
         );
80
         );
55
     }
81
     }
56
 }
82
 }

+ 40
- 3
llm-back/ruoyi-llm/src/main/java/com/ruoyi/web/llm/controller/McpController.java 파일 보기

5
 import org.noear.solon.ai.chat.ChatModel;
5
 import org.noear.solon.ai.chat.ChatModel;
6
 import org.noear.solon.ai.chat.ChatResponse;
6
 import org.noear.solon.ai.chat.ChatResponse;
7
 import org.noear.solon.ai.chat.message.AssistantMessage;
7
 import org.noear.solon.ai.chat.message.AssistantMessage;
8
+import org.noear.solon.ai.chat.message.ChatMessage;
9
+import org.noear.solon.ai.chat.tool.FunctionToolDesc;
8
 import org.noear.solon.ai.mcp.client.McpClientProvider;
10
 import org.noear.solon.ai.mcp.client.McpClientProvider;
9
 import org.reactivestreams.Publisher;
11
 import org.reactivestreams.Publisher;
10
 import org.springframework.beans.factory.annotation.Autowired;
12
 import org.springframework.beans.factory.annotation.Autowired;
13
 import org.springframework.web.bind.annotation.RestController;
15
 import org.springframework.web.bind.annotation.RestController;
14
 import reactor.core.publisher.Flux;
16
 import reactor.core.publisher.Flux;
15
 
17
 
18
+import java.io.IOException;
19
+import java.util.HashMap;
20
+import java.util.List;
21
+import java.util.Map;
22
+
16
 
23
 
17
 /**
24
 /**
18
  * mcp模型上下文协议Controller
25
  * mcp模型上下文协议Controller
32
      * @return
39
      * @return
33
      */
40
      */
34
     @GetMapping("/answer")
41
     @GetMapping("/answer")
35
-    public Flux<AssistantMessage> answer(String question)
36
-    {
42
+    public Flux<AssistantMessage> answer(String question) throws IOException {
37
         McpClientProvider clientProvider = McpClientProvider.builder()
43
         McpClientProvider clientProvider = McpClientProvider.builder()
38
                     .apiUrl("http://localhost:8080/llm/mcp/sse")
44
                     .apiUrl("http://localhost:8080/llm/mcp/sse")
39
                     .build();
45
                     .build();
42
                 .provider("openai")
48
                 .provider("openai")
43
                 .model("DeepSeek-R1-Distill-Qwen-1.5B")
49
                 .model("DeepSeek-R1-Distill-Qwen-1.5B")
44
                 .apiKey("1")
50
                 .apiKey("1")
45
-//                .defaultToolsAdd(clientProvider)
51
+                .defaultToolsAdd(clientProvider)
46
                 .build();
52
                 .build();
47
         Publisher<ChatResponse> publisher = chatModel.prompt(question).stream();
53
         Publisher<ChatResponse> publisher = chatModel.prompt(question).stream();
48
 
54
 
52
                 });
58
                 });
53
     }
59
     }
54
 
60
 
61
+    /**
62
+     * 根据招标文件要求编写投标文件技术方案
63
+     * @return
64
+     */
65
+    @GetMapping("/tech")
66
+    public AssistantMessage tech(String file) throws IOException {
67
+        McpClientProvider clientProvider = McpClientProvider.builder()
68
+                    .apiUrl("http://localhost:8080/llm/mcp/sse")
69
+                    .build();
70
+        ChatModel chatModel = ChatModel.of("http://192.168.28.188:8000/v1/chat/completions")
71
+                .provider("openai")
72
+                .model("DeepSeek-R1-Distill-Qwen-1.5B")
73
+                .apiKey("1")
74
+                .defaultToolsAdd(clientProvider)
75
+                .build();
76
+
77
+        Map<String,Object> path = new HashMap<>();
78
+        path.put("document", file);
79
+        String content = clientProvider.callToolAsText("openDocument", path).getContent();
80
+        Map<String,Object> request = new HashMap<>();
81
+        request.put("request", content);
82
+        List<ChatMessage> messages = clientProvider.getPromptAsMessages("askQuestion", request);
83
+        ChatResponse response = chatModel.prompt(messages).call();
84
+        System.out.println(response.getChoices().get(0).getMessage());
85
+        Map<String,Object> write = new HashMap<>();
86
+        write.put("document", file);
87
+        write.put("resultContent", response.getChoices().get(0).getMessage().getResultContent());
88
+        clientProvider.callToolAsText("writeTechnicalPlan", write);
89
+        return response.getChoices().get(0).getMessage();
90
+    }
91
+
55
 }
92
 }

Loading…
취소
저장