SpringAi-mcp高德

1.创建key

进入高德官网注册,创建key

https://console.amap.com/dev/id/phone(官网)

2.编写yml文件

引入自己的key

复制代码
#高德的key
AMAP-KEY: #自己的key,复制上

3.创建工具类

3.1AmapService

java 复制代码
package com.jiazhong.mingxing.ai.siliconflow.mcp.glm.service;

import org.springframework.stereotype.Service;

@Service
public interface AmapSrvice {
    String weatherAmap(String city);
}

3.2Impl类

java 复制代码
package com.jiazhong.mingxing.ai.siliconflow.mcp.glm.service.impl;

import com.jiazhong.mingxing.ai.siliconflow.mcp.glm.service.AmapSrvice;
import jakarta.annotation.Resource;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class AmapServiceImpl implements AmapSrvice {
    @Resource
    private RestTemplate restTemplate;

    @Value("${AMAP-KEY}")
    private String key;
    @Tool(description = "根据城市获取到具体天气情况")
    public String weatherAmap(@ToolParam(description = "具体的城市名称") String city) {
        String url="https://restapi.amap.com/v3/weather/weatherInfo?key="+
                key + "&city=" + city + "&extensions=all";
        return restTemplate.getForObject(url,String.class);
    }
}

4.注册工具类

java 复制代码
@Configuration
public class ChatClientConfig {
    /*@Resource
    private OpenAiChatModel openAiChatModel;
    @Resource
    private NowDateToolService nowDateToolService;
    @Resource
    private WeatherJiaService weatherJiaService;*/
    @Resource
    private AmapSrvice amapService;
    @Bean("openAiChatClient")
    public ChatClient openAiChatClient(OpenAiChatModel openAiChatModel){
       /* FunctionToolCallback<Weather.WeatherRequest,Weather.WeatherResponse> toolCallback
                =FunctionToolCallback.builder("weatherJiaServiceImpl",weatherJiaService)
                .description("获取到执行位置的天气").inputType(Weather.WeatherRequest.class).build();*/
        return ChatClient.builder(openAiChatModel)
                /*.defaultTools(currentWeather)*/
                /*.defaultToolNames("currentWeather","currentDressing")*/
                .defaultTools(amapService)
                .build();
    }
}
相关推荐
子游i2 分钟前
HappyHorse 1.0 创作指南
人工智能·ai·happyhorse
ting94520006 分钟前
动手学深度学习(PyTorch版)深度详解(4):深度学习计算实战详解
人工智能·pytorch·深度学习
QuestLab7 分钟前
【第26期】2026年4月29日 AI日报
人工智能
南宫萧幕7 分钟前
Python与Simulink联合仿真:基于DQN的HEV能量管理策略建模与全链路排雷实战
开发语言·人工智能·python·算法·机器学习·matlab·控制
ToTensor11 分钟前
Agent 记忆管理框架基准测试排名
人工智能·agent
极智视界12 分钟前
分类数据集 - 伪造人脸和真实人脸分类数据集下载
人工智能·yolo·数据集·图像分类·算法训练·人脸伪造检测
千寻girling13 分钟前
滑动窗口刷了快一个月(26天)了 , 还没有刷完. | 含(操作系统学什么的Java 后端)
java·开发语言·javascript·c++·人工智能·后端·python
GEO索引未来21 分钟前
国内首部GEO可信传播标准立项通过/DeepSeek-V4 正式上线并开源/Open AI、Google继续推进AI广告标准化
大数据·人工智能·gpt·ai·chatgpt·开源
Chengbei1122 分钟前
面向红队的 AI 赋能全场景流量分析仪 网页 / APP / 终端 / IoT 全域 HTTPS 抓包解密利器
人工智能·物联网·网络协议·web安全·网络安全·https·系统安全
小糖学代码23 分钟前
LLM系列:2.pytorch入门:9.神经网络的学习
人工智能·python·深度学习·神经网络·学习·机器学习