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();
    }
}
相关推荐
天翼云开发者社区14 分钟前
春节复工福利就位!天翼云息壤2500万Tokens免费送,全品类大模型一键畅玩!
人工智能·算力服务·息壤
知识浅谈23 分钟前
教你如何用 Gemini 将课本图片一键转为精美 PPT
人工智能
Ray Liang1 小时前
被低估的量化版模型,小身材也能干大事
人工智能·ai·ai助手·mindx
shengjk12 小时前
NanoClaw 深度剖析:一个"AI 原生"架构的个人助手是如何运转的?
人工智能
西门老铁4 小时前
🦞OpenClaw 让 MacMini 脱销了,而我拿出了6年陈的安卓机
人工智能
恋猫de小郭5 小时前
AI 可以让 WIFI 实现监控室内人体位置和姿态,无需摄像头?
前端·人工智能·ai编程
是一碗螺丝粉5 小时前
5分钟上手LangChain.js:用DeepSeek给你的App加上AI能力
前端·人工智能·langchain
两万五千个小时5 小时前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
用户4815930195915 小时前
揭秘GPT-4与LLaMA背后的加速黑科技:KV Cache、MQA、GQA、稀疏注意力与MoE全解析
人工智能