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();
    }
}
相关推荐
丝瓜蛋汤2 小时前
Proof of the contraction mapping theorem
人工智能·算法
renhongxia12 小时前
数字孪生国内外发展现状,数字孪生技术在工程项目上的应用情况及效益分析
人工智能·深度学习·机器学习·语言模型·制造
夏河始溢2 小时前
一八零、AG-UI:构建AI前端交互的统一协议
前端·人工智能·ui
deep_drink2 小时前
【经典论文精读(一)】Isomap:非线性降维的全局几何框架(Science 2000)
人工智能·算法·机器学习
羑悻的小杀马特2 小时前
零成本神器组合:用Docker+Uptime Kuma+cpolar打造永不掉线的远程监控系统!
运维·人工智能·docker·容器
龙山云仓2 小时前
No132:AI中国故事-对话老子——道法自然与AI设计:无为而治、柔弱胜刚强与复杂系统智慧
大数据·人工智能·机器学习
Data-Miner3 小时前
类似Pandas AI的几个数据分析处理智能体介绍
人工智能·数据分析·pandas
TonyLee0173 小时前
新型学习范式(机器学习)
人工智能·学习·机器学习
Deepoch3 小时前
Deepoc具身大模型居家机器人:重新定义家庭智能服务新标准
人工智能·机器人·具身模型·deepoc·居家机器人·居家好物·智能居家