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();
    }
}
相关推荐
jingli91 分钟前
恶意退款怎么办、仅退款怎么申诉:六类恶意退款识别特征+取证证据链+反制全流程(商家实操版)
人工智能·自动化·用户运营
浅安的邂逅7 分钟前
260919-报道称:美军曾因一份 AI 幻觉情报,险些误判并准备拦截一艘中国船只
人工智能·大模型·ai编程·行业动态·ai日报
Anastasiozzzz9 分钟前
重新定义 Agent 基建:Redis 在现代 AI 与智能体系统中的工程实践
java·人工智能·redis·ai
染指111014 分钟前
120.Agent-LangChain核心组件-中间件-摘要中间件(SummarizationMiddleware)
人工智能·langchain·agent·agents
Nolla15 分钟前
Tool Calling Agent:ToolNode、消息状态与常见踩坑
人工智能
hrrrrxeeeee19 分钟前
文件读取→比对→风险标记,拆解采购 AI 完整工作链路
大数据·人工智能·机器学习·prompt
AI闲人26 分钟前
Agent 平台的两种哲学:从 WeKnora 和 Molio 聊起
人工智能·知识库·企业ai落地
林伽一36 分钟前
从开源基础设施到垂直封装,AI 产业的技术主轴正在位移
人工智能·科技·ai·语言模型
lie..40 分钟前
30天从零开始学AI应用开发(Day 3):30 分钟搭好开发环境,Python + VSCode 一次配齐
人工智能·python·大模型
β添砖java40 分钟前
机器学习2 KNN算法、距离度量、特征预处理、超参数选择、手写数字、鸢尾花
人工智能·算法·机器学习