package com.iwe3.langchain4j.tools;

import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import dev.langchain4j.agent.tool.ToolMemoryId;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class WeatherTools {

    @Resource
    private RestTemplate restTemplate;

    //name 是工具描述   value是工具补充信息
    @Tool(name = "查询天气",value = "根据城市编码调用高德开发平台，返回对应城市的天气情况")
    public String queryWeather(@ToolMemoryId int memoryId,
                               @P(value = "城市编码",required = true) String citycode){
        System.out.println("查询天气情况---> 开始 ---> memoryId=" + memoryId);
        //高德地图：查询天气
        //https://lbs.amap.com/api/webservice/guide/api-advanced/weatherinfo
        var key = "cf6cb4245c630692d2f13c1cd1ad1632";
        var url = "https://restapi.amap.com/v3/weather/weatherInfo?key="+key+"&city="+citycode+"&extensions=all";
        return restTemplate.getForObject(url, String.class);
    }
}
