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();
    }
}
相关推荐
美酒没故事°15 小时前
Open WebUI安装指南。搭建自己的自托管 AI 平台
人工智能·windows·ai
云烟成雨TD15 小时前
Spring AI Alibaba 1.x 系列【6】ReactAgent 同步执行 & 流式执行
java·人工智能·spring
AI攻城狮15 小时前
用 Obsidian CLI + LLM 构建本地 RAG:让你的笔记真正「活」起来
人工智能·云原生·aigc
鸿乃江边鸟15 小时前
Nanobot 从onboard启动命令来看个人助理Agent的实现
人工智能·ai
lpfasd12315 小时前
基于Cloudflare生态的应用部署与开发全解
人工智能·agent·cloudflare
俞凡15 小时前
DevOps 2.0:智能体如何接管故障修复和基础设施维护
人工智能
comedate15 小时前
[OpenClaw] GLM 5 关于电影 - 人工智能 - 的思考
人工智能·电影评价
财迅通Ai15 小时前
6000万吨产能承压 卫星化学迎来战略窗口期
大数据·人工智能·物联网·卫星化学
liliangcsdn15 小时前
Agent Memory智能体记忆系统的示例分析
数据库·人工智能·全文检索
GISer_Jing15 小时前
Page-agent MCP结构
前端·人工智能