|
@@ -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
|
|