From 78c2c99c534d09e280ebb409fdb4e68cecaac9ee Mon Sep 17 00:00:00 2001 From: 0007 <0007@qq.com> Date: Wed, 27 Aug 2025 19:57:38 +0800 Subject: [PATCH] Add File --- .../llm/chatglm/test/WeatherFunctions.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 agents-flex-llm/agents-flex-llm-chatglm/src/test/java/com/agentsflex/llm/chatglm/test/WeatherFunctions.java diff --git a/agents-flex-llm/agents-flex-llm-chatglm/src/test/java/com/agentsflex/llm/chatglm/test/WeatherFunctions.java b/agents-flex-llm/agents-flex-llm-chatglm/src/test/java/com/agentsflex/llm/chatglm/test/WeatherFunctions.java new file mode 100644 index 0000000..e5af1fb --- /dev/null +++ b/agents-flex-llm/agents-flex-llm-chatglm/src/test/java/com/agentsflex/llm/chatglm/test/WeatherFunctions.java @@ -0,0 +1,24 @@ +package com.agentsflex.llm.chatglm.test; + +import com.agentsflex.core.llm.functions.annotation.FunctionDef; +import com.agentsflex.core.llm.functions.annotation.FunctionParam; +import com.agentsflex.core.llm.client.HttpClient; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; + +public class WeatherFunctions { + + private static String getCityCode(String cityName) { + return cityName.contains("北京") ? "101010100" : null; + } + + @FunctionDef(name = "天气查询", description = "获取天气信息的方法") + public static String getWeatherInfo( + @FunctionParam(name = "location", description = "城市的名称,比如: 北京, 上海") String name + ) { + String response = new HttpClient().get("http://t.weather.sojson.com/api/weather/city/" + getCityCode(name)); + JSONObject jsonObject = JSONObject.parseObject(response); + return JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue); + } +}