|
@@ -0,0 +1,24 @@
|
|
|
|
|
+package space.anyi.springAiAlibabaLearn.tool;
|
|
|
|
|
+
|
|
|
|
|
+import org.springframework.ai.tool.annotation.Tool;
|
|
|
|
|
+import org.springframework.ai.tool.annotation.ToolParam;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
+import java.time.ZonedDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+
|
|
|
|
|
+public class MyTool {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 使用@Tool注解标注这是一个供LLM调用的tool
|
|
|
|
|
+ * @param zoneId 时区ID
|
|
|
|
|
+ * @return 当前时间的字符串
|
|
|
|
|
+ */
|
|
|
|
|
+ @Tool(name = "getLocalDateTimeByZoneId",description = "根据ZoneId获取当前的本地时间(格式为:yyyy-MM-dd HH:mm:ss z)")
|
|
|
|
|
+ public String getLocalDateTimeByZoneId(@ToolParam(description = "时区ID(ZoneId),例如:",required = true) String zoneId){
|
|
|
|
|
+ ZoneId zone = ZoneId.of(zoneId);
|
|
|
|
|
+ ZonedDateTime zonedDateTime = ZonedDateTime.now(zone);
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
|
|
|
|
|
+ return zonedDateTime.format(formatter);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+}
|