|
@@ -5,6 +5,8 @@ import com.ruoyi.web.llm.service.ILangChainMilvusService;
|
5
|
5
|
import org.noear.solon.ai.chat.ChatModel;
|
6
|
6
|
import org.noear.solon.ai.chat.ChatResponse;
|
7
|
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
|
10
|
import org.noear.solon.ai.mcp.client.McpClientProvider;
|
9
|
11
|
import org.reactivestreams.Publisher;
|
10
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -13,6 +15,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
13
|
15
|
import org.springframework.web.bind.annotation.RestController;
|
14
|
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
|
25
|
* mcp模型上下文协议Controller
|
|
@@ -32,8 +39,7 @@ public class McpController extends BaseController
|
32
|
39
|
* @return
|
33
|
40
|
*/
|
34
|
41
|
@GetMapping("/answer")
|
35
|
|
- public Flux<AssistantMessage> answer(String question)
|
36
|
|
- {
|
|
42
|
+ public Flux<AssistantMessage> answer(String question) throws IOException {
|
37
|
43
|
McpClientProvider clientProvider = McpClientProvider.builder()
|
38
|
44
|
.apiUrl("http://localhost:8080/llm/mcp/sse")
|
39
|
45
|
.build();
|
|
@@ -42,7 +48,7 @@ public class McpController extends BaseController
|
42
|
48
|
.provider("openai")
|
43
|
49
|
.model("DeepSeek-R1-Distill-Qwen-1.5B")
|
44
|
50
|
.apiKey("1")
|
45
|
|
-// .defaultToolsAdd(clientProvider)
|
|
51
|
+ .defaultToolsAdd(clientProvider)
|
46
|
52
|
.build();
|
47
|
53
|
Publisher<ChatResponse> publisher = chatModel.prompt(question).stream();
|
48
|
54
|
|
|
@@ -52,4 +58,35 @@ public class McpController extends BaseController
|
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
|
}
|