当前位置: 首页 > wzjs >正文

google网站360网站推广客服电话

google网站,360网站推广客服电话,新安县住房和城乡建设局网站,免费建站网站 seo1、当我们使用大模型问 请告诉我现在北京时间几点了 回答如下 此时就需要大模型的 function call 的功能,也就是 给大模型加上工具 2、代码如下 获取时间的工具类 package com.alibaba.cloud.ai.example.chat.ollama.tools.time;import java.time.ZoneId; impo…

1、当我们使用大模型问

请告诉我现在北京时间几点了

回答如下

此时就需要大模型的 function call 的功能,也就是 给大模型加上工具

2、代码如下

获取时间的工具类

package com.alibaba.cloud.ai.example.chat.ollama.tools.time;import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;/*** @author yingzi* @date 2025/3/27:10:56*/
public class TimeUtils {public static String getTimeByZoneId(String zoneId) {// Get the time zone using ZoneIdZoneId zid = ZoneId.of(zoneId);// Get the current time in this time zoneZonedDateTime zonedDateTime = ZonedDateTime.now(zid);// Defining a formatterDateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");// Format ZonedDateTime as a stringString formattedDateTime = zonedDateTime.format(formatter);return formattedDateTime;}
}

获取时间的工具

package com.alibaba.cloud.ai.example.chat.ollama.tools.time.method;import com.alibaba.cloud.ai.example.chat.ollama.tools.time.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;public class TimeTools {private static final Logger logger = LoggerFactory.getLogger(TimeTools.class);@Tool(description = "Get the time of a specified city.")public String  getCityTimeMethod(@ToolParam(description = "Time zone id, such as Asia/Shanghai") String timeZoneId) {logger.info("The current time zone is {}", timeZoneId);return String.format("The current time zone is %s and the current time is " + "%s", timeZoneId,TimeUtils.getTimeByZoneId(timeZoneId));}
}

controller代码如下

package com.alibaba.cloud.ai.example.chat.ollama.controller;import com.alibaba.cloud.ai.example.chat.ollama.tools.time.method.TimeTools;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/time")
public class TimeController {private final ChatClient ollamaiChatClient;public TimeController(ChatClient.Builder chatClientBuilder) {this.ollamaiChatClient = chatClientBuilder.build();}/*** 无工具版*/@GetMapping("/chat")public String simpleChat(@RequestParam(value = "query", defaultValue = "请告诉我现在北京时间几点了") String query) {return ollamaiChatClient.prompt(query).call().content();}/*** 调用工具版 - function*/@GetMapping("/chat-tool-function")public String chatTranslateFunction(@RequestParam(value = "query", defaultValue = "请告诉我现在北京时间几点了") String query) {return ollamaiChatClient.prompt(query).tools("getCityTimeFunction").call().content();}/*** 调用工具版 - method*/@GetMapping("/chat-tool-method")public String chatTranslateMethod(@RequestParam(value = "query", defaultValue = "请告诉我现在北京时间几点了") String query) {return ollamaiChatClient.prompt(query).tools(new TimeTools()).call().content();}}

调用接口  http://127.0.0.1:10005/time/chat-tool-method  如下

http://www.dtcms.com/wzjs/483312.html

相关文章:

  • 可做易企秀的网站品牌营销与推广
  • wordpress页面回收站精准营销系统
  • 房地产市场信息系统网站如何在百度搜索排名靠前
  • 政府门户网站的模块seo关键词优化软件手机
  • 石家庄网站建设策划方案企业如何进行网络推广
  • 做新闻类网站需要什么资质微信推广平台
  • 中小型网站建设教程个人网站设计毕业论文
  • seo咨询顾问aso优化哪家好
  • 个人博客网站设计的目的高级seo优化招聘
  • 做化妆招生宣传在那些网站可以做短视频营销优势
  • 做网站开发要学什么语言市场营销专业就业方向
  • 深圳做网站补贴百度指数分是什么
  • 做响应式网站应该注意什么手机怎么制作网页
  • wordpress首页显示摘要 插件一键关键词优化
  • 在线视频网站a做免费下载seo搜索引擎优化课程
  • 代做网站修改维护网站关键词排名手机优化软件
  • 免费卡盟网站建设南宁网站推广哪家好
  • 天津公司网站建设广州百度
  • 关于内网站建设的请示网络营销组合策略
  • 店面设计的风格可以分成几种seo 优化 工具
  • 快手流量推广免费网站广西seo经理
  • 贵阳营销型网站建设百度广告一天多少钱
  • 最出名的网站建设公司万网域名查询注册商
  • 两学一做网站飘窗seo公司多少钱
  • 第一次开票网站建设怎么开百度权重什么意思
  • 有哪些做调查问卷的赚钱网站宁波网络推广优化方案
  • 服务器托管收费怎样优化网站排名
  • 网站兼容视图选择宁波seo优化公司
  • wordpress 显示当前时间广州seo好找工作吗
  • 福田做网站公司seo资料