测试地图 MCP
This commit is contained in:
parent
1ab9c43548
commit
fadd140cbe
7
pom.xml
7
pom.xml
@ -140,6 +140,13 @@
|
||||
<version>9.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.ai/spring-ai-mcp-client-spring-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-mcp-client-spring-boot-starter</artifactId>
|
||||
<version>1.0.0-M6</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.huangge1199.aiagent.controller;
|
||||
|
||||
import com.huangge1199.aiagent.common.R;
|
||||
import com.huangge1199.aiagent.config.MyLoggerAdvisor;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.ai.tool.ToolCallbackProvider;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@ -34,6 +37,11 @@ public class ResController {
|
||||
record ActorFilms(String actor, List<String> movies) {
|
||||
}
|
||||
|
||||
// AI 调用 MCP 服务
|
||||
|
||||
@Resource
|
||||
private ToolCallbackProvider toolCallbackProvider;
|
||||
|
||||
@PostMapping("/chatRes")
|
||||
@Operation(summary = "返回 ChatResponse")
|
||||
public R<ChatResponse> chatResRes(@RequestBody String question) {
|
||||
@ -85,4 +93,19 @@ public class ResController {
|
||||
.chatResponse();
|
||||
return R.ok(output);
|
||||
}
|
||||
|
||||
@PostMapping("/doChatWithMcp")
|
||||
@Operation(summary = "使用mcp返回会话")
|
||||
public R<String> doChatWithMcp(@RequestBody String question) {
|
||||
ChatResponse chatResponse = chatClient
|
||||
.prompt()
|
||||
.user(question)
|
||||
// 开启日志,便于观察效果
|
||||
.advisors(new MyLoggerAdvisor())
|
||||
.tools(toolCallbackProvider)
|
||||
.call()
|
||||
.chatResponse();
|
||||
String content = chatResponse.getResult().getOutput().getText();
|
||||
return R.ok(content);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,10 @@ spring:
|
||||
distance-type: COSINE_DISTANCE
|
||||
dimensions: 1536
|
||||
max-document-batch-size: 10000
|
||||
mcp:
|
||||
client:
|
||||
stdio:
|
||||
servers-configuration: classpath:mcp-servers.json
|
||||
server:
|
||||
port: 8123
|
||||
servlet:
|
||||
|
Loading…
Reference in New Issue
Block a user