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();
    }
}
相关推荐
Tangyuewei8 小时前
给 AI 套上缰绳:Harness Engineering 是什么
人工智能
AI棒棒牛8 小时前
第11讲 | 目标检测任务:边界框、IoU、类别与置信度
人工智能·yolo·目标检测·yolo26
allione9 小时前
AI时代测试方向AI for Testing和Testing for AI
人工智能·ai测试
武子康9 小时前
GPT-Red:自动化红队如何形成 Agent 安全数据飞轮(4 个闭环 + 6 类评测指标 + 5 类风险误读)
人工智能·openai·agent
阿里云大数据AI技术9 小时前
DataWorks Data Agent 实战课堂(二):一句话搞定数据集成+处理,实现端到端数据流水线
人工智能·agent
Days20509 小时前
AI漫剧vs传统动漫vs真人短剧
人工智能
武子康9 小时前
从恶意 Dataset 到横向移动:一套可落地的 Dataset Processing Threat Model(资产边界 + 威胁枚举 + 5 层控制)
人工智能·安全
redreamSo9 小时前
一天涨 1800 星的 GitHub 榜首:AI 编程瓶颈变成了 token
人工智能·开源·github
wp123_19 小时前
实测数据对飙:COILCRAFT XFL4020-222MEC vs TONEVEE MVL4020-2R2M,2.2µH功率电感参数全解读
人工智能
本末倒置1839 小时前
从 PDF 到向量检索:一个最简单的本地 RAG 入库案例
人工智能