SpringBoot实现简单AI问答(百度千帆)
创始人
2025-01-15 05:37:26
0

第一步:注册并登录百度智能云,创建应用并获取自己的APIKey与SecretKey,参考网址:

点击去百度智能云
在这里插入图片描述

第二步:引入千帆的pom依赖

		             com.baidubce             qianfan             0.0.9          

第三步:创建前端需要的controller

import com.baidubce.qianfan.core.auth.Auth; import com.lx.vue.common.resp.ResultData; import com.lx.vue.common.resp.ReturnCodeEnum; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController;  import com.baidubce.qianfan.Qianfan; import com.baidubce.qianfan.core.builder.ChatBuilder; import com.baidubce.qianfan.model.chat.ChatResponse;  @RestController public class QianFanController {      private static final String APIKey = "你的APIKey";     private static final String SecretKey = "你的SecretKey";      private static Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH,APIKey, SecretKey);       @PostMapping("/ai/sendMsg")     public ResultData sendMsg(@RequestBody String problem) {         String result = null;         try {             result = chat(problem);         } catch (Exception e) {             e.printStackTrace();             return new ResultData(ReturnCodeEnum.RC500.getCode(),"服务暂不可用",null);         }         return new ResultData(ReturnCodeEnum.RC200.getCode(),ReturnCodeEnum.RC200.getMessage(),result);     }      private static String chat(String problem) {         ChatBuilder bulder = qianfan.chatCompletion()                 .model("ERNIE-Speed-8K");//你要使用的大模型款式,最好和我一样,其他的很有可能是收费的             bulder.addMessage("user",problem);//你的问题           ChatResponse response = bulder.execute();         return response.getResult();     } } 

第四步:前端进行调用,并动态将自己的问题与AI的回答填入Vue页面

在这里插入图片描述

相关内容

热门资讯

必看开挂"约局吧德州... 必看开挂"约局吧德州可以透视吗"哈糖大菠萝助手(透视)开挂辅助安装(有挂细节)约局吧德州可以透视吗a...
透视辅助!wepoker透视是... 透视辅助!wepoker透视是真的吗,wepoker辅助分析器,正品开挂辅助下载(透视有挂教程);亲...
分享个大家“来玩app 德州 ... 分享个大家“来玩app 德州 辅助”开挂(透视)辅助插件(爆料教程有挂方略);无需打开直接搜索加(薇...
实测辅助"hhpok... 实测辅助"hhpoker有没有辅助挂"wepoker破解版内购(透视)开挂辅助安装(有挂透明挂)1、...
透视辅助!hhpoker是正品... 透视辅助!hhpoker是正品吗,hhpoker软件靠谱吗,盘点开挂辅助安装(透视有挂技术)1、下载...
每日必看教程“hhpoker是... 每日必看教程“hhpoker是正品吗”开挂(透视)辅助软件(新2026教程有挂教程)ai黑科技系统规...
原来有开挂"拱趴大菠... 拱趴大菠萝怎么开挂开挂教程视频分享装挂详细步骤在当今的网络游戏中,拱趴大菠萝怎么开挂作为一种经典的娱...
透视辅助!wepoker看底牌... >>您好:竞技联盟透视插件确实是有挂的,很多玩家在这款竞技联盟透视插件游戏中打牌都会发现很多用户的牌...
推荐辅助"智星德州辅... 大家好,今天小编来为大家解答智星德州辅助译码插件靠谱吗这个问题咨询软件客服可以免费测试直接加微信(1...
透视ai代打“wepoker有... 透视ai代打“wepoker有没有透视方法”开挂(透视)辅助下载(辅助教程了解有挂);打开点击测试直...