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

备案的网站可以攻击吗三门峡网站建设电话

备案的网站可以攻击吗,三门峡网站建设电话,生成论坛网站,自己学习建设网站Demo介绍 本demo对接阿里云和百度的大模型API#xff0c;实现一个简单的对话应用。 DecEco Studio版本#xff1a;DevEco Studio 3.1.1 Release HarmonyOS API版本#xff1a;API9 关键点#xff1a;ArkTS、ArkUI、UIAbility、网络http请求、列表布局 官方接口文档 此…Demo介绍 本demo对接阿里云和百度的大模型API实现一个简单的对话应用。 DecEco Studio版本DevEco Studio 3.1.1 Release HarmonyOS API版本API9 关键点ArkTS、ArkUI、UIAbility、网络http请求、列表布局 官方接口文档 此链接为当前时间2024-1-26文档链接地址可能发生迁移变更以官方为准。 阿里云通义千文API接口文档地址通义千问API如何使用_模型服务灵积(DashScope)-阿里云帮助中心 百度智能云千帆大模型API接口文档地址鉴权介绍 - 千帆大模型平台 | 百度智能云文档 新建项目 API9Stage模型需要联网 资源同步下载结束后打开预览器可正常预览页面 实现API接口调用 新建http目录在其中并在此目录下新建两个ts文件分别实现调用阿里云和百度的API接口 申请网络权限 1、对接阿里云API 开通服务并获得API-KEY 请参照如何开通DashScope并创建API-KEY_模型服务灵积(DashScope)-阿里云帮助中心 开通完成后可在工作台拿到接口请求的鉴权信息API-KEY发起http时请求头header需要携带 参照文档实现请求方法 根据接口文档构造请求体发起http请求完成大模型对话 接口文档通义千问API如何使用_模型服务灵积(DashScope)-阿里云帮助中心 实现ALiYunHttpUtils 类的 request 方法。 import http from ohos.net.http; import hilog from ohos.hilog; class ALiYunHttpUtils {request(question: string) {hilog.info(0x0000, testTag, ALiYunHttpUtils request invoke. question: %{public}s, question);// 1 createHttp接口创建请求let httpRequest http.createHttp();// 2 发起请求httpRequest.request(// 请求地址https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation,// 请求options: HttpRequestOptions{// 请求方式method: http.RequestMethod.POST,// 请求头header: {Content-Type: application/json,// 这里的Authorization 就是刚才工作台查看的 API-KEYAuthorization: sk-0bxxxxxxxxxxxxxxxxc3 // 脱敏处理},// 请求体extraData: {model: qwen-plus, // 指定用于对话的通义千问模型名input: {messages: [{role: user,content: question // 请求发起方传入的问题}]}}}, (err, data: http.HttpResponse) {if (err) {hilog.error(0x0000, testTag, Failed to request ALiYun. Cause: %{public}s, JSON.stringify(err) ?? );httpRequest.destroy();} else {hilog.error(0x0000, testTag, Request ALiYun success. data: %{public}s, JSON.stringify(data.result));httpRequest.destroy();}})}} export default new ALiYunHttpUtils; 调用http请求方法 在index页面加载的时候调用ALiYunHttpUtils.request方法 刷新页面触发请求 刷新或重启Preview预览器index页面重新加载会执行aboutToAppear方法 打开Log控制台可看到请求结果 2、对接百度API 创建应用 登录平台创建应用可得到应用的API Key 和 Secret Key这两个信息在调用鉴权信息接口时会用到。 开通服务计费 添加应用后会默认预置一部分服务可在【在线服务】菜单页查看 大部分服务都需要付费开通有几个免费的本人不太会用尴尬。。有免费的策略各位也可以分享一下 嘿嘿~ 开通了一个计费的个人测试使用调用不会很频繁 鉴权认证 根据鉴权接口文档实现鉴权接口请求 文档地址获取access_token - 千帆大模型平台 | 百度智能云文档 实现BaiduHttpUtils类的 request 方法。 注意此处BaiduHttpUtils.request方法仅完成了鉴权接口调用还未进行真正的对话 import hilog from ohos.hilog; import http from ohos.net.http; class BaiduHttpUtils {request(question: string) {hilog.info(0x0000, testTag, BaiduHttpUtils request invoke. question: %{public}s, question);// 先鉴权// 1 createHttp接口创建请求let httpRequest http.createHttp();// 2 发起请求httpRequest.request(// 请求地址// 参数grant_type 固定值client_credentials// 参数client_id 应用的API Key// 参数client_secret 应用的Secret Keyhttps://aip.baidubce.com/oauth/2.0/token?grant_typeclient_credentialsclient_idasxxxxxxxxxxHoclient_secretihxxxxxxxxgG,{method: http.RequestMethod.POST,header: {Content-Type: application/json}}, (err, data: http.HttpResponse) {if (err) {hilog.error(0x0000, testTag, Failed to request BaiDu. Cause: %{public}s, JSON.stringify(err) ?? );httpRequest.destroy();} else {hilog.error(0x0000, testTag, Request BaiDu success. data: %{public}s, JSON.stringify(data.result));httpRequest.destroy();}})}} export default new BaiduHttpUtils; 在index页面加载的时候调用BaiduHttpUtils.request方法 鉴权通过后可在接口返回中获取后续对话接口所需要的鉴权信息access_token 发起对话请求 拿到access_token后可根据上述开通的服务对应的接口文档发起对话请求 实现BaiduHttpUtils类的 chatRequest方法在鉴权结束后调用 import hilog from ohos.hilog; import http from ohos.net.http; class BaiduHttpUtils {request(question: string) {hilog.info(0x0000, testTag, BaiduHttpUtils request invoke. question: %{public}s, question);// 先鉴权// 1 createHttp接口创建请求let httpRequest http.createHttp();// 2 发起请求httpRequest.request(// 请求地址// 参数grant_type 固定值client_credentials// 参数client_id 应用的API Key// 参数client_secret 应用的Secret Keyhttps://aip.baidubce.com/oauth/2.0/token?grant_typeclient_credentialsclient_idasxxxxxxxxHoclient_secretihxxxxxxxxgG,{method: http.RequestMethod.POST,header: {Content-Type: application/json}}, (err, data: http.HttpResponse) {if (err) {hilog.error(0x0000, testTag, Failed to request BaiDu. Cause: %{public}s, JSON.stringify(err) ?? );httpRequest.destroy();} else {hilog.error(0x0000, testTag, Request BaiDu success. data: %{public}s, JSON.stringify(data.result));httpRequest.destroy();// 携带认证信息 发起对话请求let respToken: BaiDuToken JSON.parse(data.result.toString())this.chatRequest(respToken.access_token, question)}})}chatRequest(token: string, question: string) {// 通常情况不建议把token打印出来 此处为了方便调试hilog.info(0x0000, testTag, BaiduHttpUtils chaRequest invoke. token: %{public}s, question: %{public}s, token, question);// 1 createHttp接口创建请求let httpRequest http.createHttp();// 2 发起请求httpRequest.request(// 请求地址https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions?access_token token,{method: http.RequestMethod.POST,header: {Content-Type: application/json},extraData: {messages: [{role: user,content: question}]}}, (err, data: http.HttpResponse) {if (err) {hilog.error(0x0000, testTag, Failed to request BaiDu. Cause: %{public}s, JSON.stringify(err) ?? );httpRequest.destroy();} else {hilog.error(0x0000, testTag, Request BaiDu success. data: %{public}s, JSON.stringify(data.result));httpRequest.destroy();}})}} export default new BaiduHttpUtils;class BaiDuToken {access_token: stringexpires_in: numbersession_key: string// ... } 刷新页面触发请求 刷新或重启Preview预览器index页面重新加载会执行aboutToAppear方法 打开Log控制台可看到请求结果 至此两个大模型的API接口对接完成下一步可以开始设计对话页面。
http://www.hkea.cn/news/14543087/

相关文章:

  • 网站设计的硬件文创产品推广方案
  • 公司网站主页设计高要网站制作
  • 福州网站建设流程做网站用php还是html
  • 北京信管局 网站备案东莞企业网站设计
  • 织梦网站模板如何安装如何拷贝服务器里面网站做备份
  • 郑州公司网站设计南平购物网站开发设计
  • 网站内容建设怎么写wordpress 黑糖
  • 网站内如何做内部链接wordpress dux推送代码
  • 成都科技网站建设咨询电话改版网站会影响百度
  • 最大的做网站公司呼和浩特公司网页设计
  • 免费h5网站模版网络推广怎么收费
  • 浦口网站建设前端开发工程师招聘
  • 大连企业网站模板wordpress英文企业网站模板
  • 免费网站2021年能用的网址wordpress主题 二次元
  • 网站建设维护管理软件论坛网站用的虚拟主机
  • 网站服务器无法访问北京物流网站建设
  • 网站都要交域名费么包头球形网架公司
  • 网站seo收录工具wordpress数据库发布文章
  • 做网站服务销售装修公司logo设计图片
  • 做网站可以用思源字体吗网站开发好学吗
  • 网站默认首页设置获取客户信息的渠道有哪些
  • md5加密网站app分发平台
  • 如何做一个属于自己的网站东莞有哪些大公司
  • 创意活动策划网站网站建设管理工作经验介绍
  • 南昌做网站要多少钱建设网站方式有哪些
  • 湛江专业建站推广机构wordpress 客户端
  • 深圳做分销商城网站网站设计包含哪些技术
  • 系部网站建设方案自己做公司的网站
  • 如何做自己的网站商城七牛云app
  • 开发网站多少钱小公司做网站多少钱