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

自己如何开网站东坑镇网站仿做

自己如何开网站,东坑镇网站仿做,低代码无代码开发平台,做ppt哪些网站的图片质量高4.2.function call 函数调用 大模型在面对实时性问题、私域知识型问题或数学计算等问题时可能效果不佳。 您可以使用function call功能#xff0c;通过调用外部工具来提升模型的输出效果。您可以在调用大模型时#xff0c;通过tools参数传入工具的名称、描述、入参等信息。…4.2.function call 函数调用 大模型在面对实时性问题、私域知识型问题或数学计算等问题时可能效果不佳。 您可以使用function call功能通过调用外部工具来提升模型的输出效果。您可以在调用大模型时通过tools参数传入工具的名称、描述、入参等信息。 4.2.1.Function Call 流程 Function Call的工作流程示意图如下所示 4.2.2.工具类 这里的一些工具类是一些测试工具类, 只是模拟对应的功能 获取天气 public class GetWhetherTool {private String location;public GetWhetherTool(String location) {this.location location;}public String call() {return location 今天是晴天;} } 获取时间 import java.time.LocalDateTime; import java.time.format.DateTimeFormatter;public class GetTimeTool {public GetTimeTool() {}public String call() {LocalDateTime now LocalDateTime.now();DateTimeFormatter formatter DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss);String currentTime 当前时间 now.format(formatter) 。;return currentTime;} }获取好友姓名 public class GetNamesTool {public GetNamesTool() {}public String call() {return [\王小二\,\李小三\,\赵小四\];} } 4.2.3.调用处理 通过 通义大模型 进行函数调用 import com.alibaba.dashscope.aigc.generation.Generation; import com.alibaba.dashscope.aigc.generation.GenerationParam; import com.alibaba.dashscope.aigc.generation.GenerationResult; import com.alibaba.dashscope.common.Message; import com.alibaba.dashscope.common.Role; import com.alibaba.dashscope.exception.ApiException; import com.alibaba.dashscope.exception.InputRequiredException; import com.alibaba.dashscope.exception.NoApiKeyException; import com.alibaba.dashscope.tools.FunctionDefinition; import com.alibaba.dashscope.tools.ToolCallBase; import com.alibaba.dashscope.tools.ToolCallFunction; import com.alibaba.dashscope.tools.ToolFunction; import com.alibaba.dashscope.utils.Constants; import com.alibaba.dashscope.utils.JsonUtils; import com.fasterxml.jackson.databind.node.ObjectNode; import com.github.victools.jsonschema.generator.*; import com.yuan.tongyibase.tools.GetNamesTool; import com.yuan.tongyibase.tools.GetTimeTool; import com.yuan.tongyibase.tools.GetWhetherTool; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.List;import com.alibaba.dashscope.aigc.generation.GenerationOutput.Choice;RestController RequestMapping(/tongyi) public class CallFuncController {Value(${tongyi.api-key})private String apiKey;RequestMapping(/call/func)public String callFunc(RequestParam(value message, required false, defaultValue 中国的首都是哪里?) String message) throws NoApiKeyException, InputRequiredException {String selectTool selectTool(message);return selectTool;}public String selectTool(String message) throws NoApiKeyException, ApiException, InputRequiredException {// 设置API密钥Constants.apiKey apiKey;// 创建SchemaGeneratorConfigBuilder实例指定使用JSON格式的模式版本SchemaGeneratorConfigBuilder configBuilder new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12, OptionPreset.PLAIN_JSON);// 构建SchemaGeneratorConfig配置包含额外的OpenAPI格式值但不使用枚举的toString方法进行展平SchemaGeneratorConfig config configBuilder.with(Option.EXTRA_OPEN_API_FORMAT_VALUES).without(Option.FLATTENED_ENUMS_FROM_TOSTRING).build();// 根据配置创建SchemaGenerator实例用于生成模式SchemaGenerator generator new SchemaGenerator(config);// 生成GetWhetherTool类的JSON SchemaObjectNode jsonSchema_whether generator.generateSchema(GetWhetherTool.class);// 生成GetTimeTool类的JSON SchemaObjectNode jsonSchema_time generator.generateSchema(GetTimeTool.class);// 生成GetNamesTool类的JSON SchemaObjectNode jsonSchema_names generator.generateSchema(GetNamesTool.class);// 构建获取指定地区天气的函数定义FunctionDefinition fd_whether FunctionDefinition.builder().name(get_current_whether) // 设置函数名称.description(获取指定地区的天气) // 设置函数描述.parameters(JsonUtils.parseString(jsonSchema_whether.toString()).getAsJsonObject()) // 设置函数参数.build();// 构建获取当前时刻时间的函数定义FunctionDefinition fd_time FunctionDefinition.builder().name(get_current_time) // 设置函数名称.description(获取当前时刻的时间) // 设置函数描述.parameters(JsonUtils.parseString(jsonSchema_time.toString()).getAsJsonObject()) // 设置函数参数.build();// 构建获取当前names的函数定义FunctionDefinition fd_names FunctionDefinition.builder().name(get_current_names) // 设置函数名称.description(获取好友) // 设置函数描述.parameters(JsonUtils.parseString(jsonSchema_names.toString()).getAsJsonObject()) // 设置函数参数.build();// 构建系统消息用于提示助手使用工具回答问题Message systemMsg Message.builder().role(Role.SYSTEM.getValue()) // 设置消息角色为系统.content(你是一个乐于助人的AI助手。当被问到问题时尽可能使用工具。) // 设置消息内容.build();Message userMsg Message.builder().role(Role.USER.getValue()).content(message).build();ListMessage messages new ArrayList();messages.addAll(Arrays.asList(systemMsg, userMsg));// 构建生成参数对象用于配置文本生成的相关参数GenerationParam param GenerationParam.builder()// 设置所使用的模型为“qwen-max”.model(qwen-turbo) //qwen-max// 设置对话历史用于模型生成时参考.messages(messages)// 设置生成结果的格式为消息格式.resultFormat(GenerationParam.ResultFormat.MESSAGE)// 设置可用的工具函数列表包括天气查询和时间查询功能.tools(Arrays.asList(ToolFunction.builder().function(fd_whether).build(),ToolFunction.builder().function(fd_time).build(),ToolFunction.builder().function(fd_names).build())).build();// 大模型的第一轮调用Generation gen new Generation();GenerationResult result gen.call(param);System.out.println(\n大模型第一轮输出信息 JsonUtils.toJson(result));for (Choice choice : result.getOutput().getChoices()) {messages.add(choice.getMessage());// 如果需要调用工具if (result.getOutput().getChoices().get(0).getMessage().getToolCalls() ! null) {for (ToolCallBase toolCall : result.getOutput().getChoices().get(0).getMessage().getToolCalls()) {if (toolCall.getType().equals(function)) {// 获取工具函数名称和入参String functionName ((ToolCallFunction) toolCall).getFunction().getName();String functionArgument ((ToolCallFunction) toolCall).getFunction().getArguments();// 大模型判断调用天气查询工具的情况if (functionName.equals(get_current_whether)) {GetWhetherTool GetWhetherFunction JsonUtils.fromJson(functionArgument, GetWhetherTool.class);String whether GetWhetherFunction.call();Message toolResultMessage Message.builder().role(tool).content(String.valueOf(whether)).toolCallId(toolCall.getId()).build();messages.add(toolResultMessage);System.out.println(\n工具输出信息 whether);}// 大模型判断调用时间查询工具的情况else if (functionName.equals(get_current_time)) {GetTimeTool GetTimeFunction JsonUtils.fromJson(functionArgument, GetTimeTool.class);String time GetTimeFunction.call();Message toolResultMessage Message.builder().role(tool).content(String.valueOf(time)).toolCallId(toolCall.getId()).build();messages.add(toolResultMessage);System.out.println(\n工具输出信息 time);}// 大模型判断调用[ names ]的情况else if (functionName.equals(get_current_names)) {GetNamesTool GetNamesFunction JsonUtils.fromJson(functionArgument, GetNamesTool.class);String names GetNamesFunction.call();Message toolResultMessage Message.builder().role(tool).content(String.valueOf(names)).toolCallId(toolCall.getId()).build();messages.add(toolResultMessage);System.out.println(\n工具输出信息 names);}}}}// 如果无需调用工具直接输出大模型的回复else {System.out.println(\n最终答案 result.getOutput().getChoices().get(0).getMessage().getContent());return \n最终答案 result.getOutput().getChoices().get(0).getMessage().getContent();}}// 大模型的第二轮调用 包含工具输出信息param.setMessages(messages);result gen.call(param);System.out.println(\n大模型第二轮输出信息 JsonUtils.toJson(result));System.out.println((\n最终答案 result.getOutput().getChoices().get(0).getMessage().getContent()));return \n最终答案 result.getOutput().getChoices().get(0).getMessage().getContent();} } 4.2.4.测试 ### GET http://localhost:8081/tongyi/call/func?message好友的名字是什么
http://www.dnsts.com.cn/news/116467.html

相关文章:

  • 网站接广告平台徐州网站建设公司哪家好
  • 南宁网站seo公司哪家好网易企业邮箱怎么申请
  • 有区域名和主机怎么做网站有哪些网站做外贸的
  • 昆明网站seo技术厂家富阳市建设局网站
  • 医院网站管理办法回收那个网站做推广好
  • 虚拟商品购物网站源码免费手机网站制作app
  • 返利网 网站建设费用佛山网红书店
  • 网站发布 图片看不到做设计有必要买素材网站会员
  • 在公司平台做网站竞拍wordpress怎样添加版权名
  • 建筑工程网上申请质量安全监督随州网站seo
  • xd软件可做网站吗微信公众平台导航 wordpress模版
  • 评估企业网站建设wordpress转换为html5
  • 重庆技术网站建设欧洲卡一卡2卡3卡4卡
  • 制作一个网站需要什么上海游戏公司排名
  • 建设牌官方网站现在最火的推广平台
  • 做简单网站用什么软件有哪些长沙企业建
  • 表白网站在线生成免费app推广运营是做什么的
  • 360免费建站怎么做安卓市场app下载
  • 提供邯郸wap网站建设故乡网站开发的意义
  • 网站建设费用 开办费软件开发是什么职业
  • 爱情动做网站推荐郑州网站建设喝彩科技
  • 网站开发调查问卷怎么做微信网站
  • 贵阳酒店网站建设前端seo优化
  • 珠海网站建设的公司哪家好页面简洁的导航网站
  • 购物网站建设的目的上海科技网络公司
  • 电商网页设计网站二维码链接生成器在线
  • 美橙互联建站网站被截止网络运营商
  • 有没有专门做设计的网站cn域名做犯法网站
  • 安庆网站建设推荐安徽秒搜科技平台推广精准客源
  • 我做的网站有时打开很慢什么原因呢珍爱网建设网站的目的