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();
    }
}
相关推荐
张张123y26 分钟前
Cordis 插件模型:契约、提供者、插件、作用域、策略包五件套讲透
网络·人工智能·开源·后端开发·ai agent
SelectDB37 分钟前
多模湖仓是什么?与湖仓一体的 5 个区别,以及 Lance、Iceberg、Doris 如何协同
人工智能
JmoVxia1 小时前
大龄程序员,还能坚持多久?
人工智能·程序员·app
always20221 小时前
AI可观测 · 06 - 开源 LLM 观测平台数据模型与埋点实战:Session/Trace/Observation/Score 与 SDK 三态
人工智能·开源
AIGC5951 小时前
「冷一下」讲个冷笑话 Rokid Glasses AIUI 应用开发手记
人工智能
秦先生在广东1 小时前
一个工具全协议下载还能隐身
人工智能
秦先生在广东1 小时前
驳回率25%?预检工具帮你拦
人工智能
byte轻骑兵1 小时前
【BAS】规范精讲[2]: 挂出 0x180F 这块招牌:BAS 从上电声明到双链路被发现的全流程
人工智能·物联网·aiot·att·嵌入式蓝牙
skywalk81631 小时前
把「假成功」赶出工具层:lightharness 两天升级复盘(4×5 模式矩阵 + 工具层 5 个缺陷)
开发语言·前端·人工智能·lightharness
秦先生在广东2 小时前
550家数据源一API搞定Agent
人工智能