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

政府网站 建设目标关键词排名公司

政府网站 建设目标,关键词排名公司,阳江做网站的公司,网站开发培训学院微信小程序_调用openAi搭建虚拟伙伴聊天背景效果关于账号注册接口实现8行python搞定小程序实现页面结构数据逻辑结速背景 从2022年的年底,网上都是chagpt的传说,个人理解这个chatgpt是模型优化训练,我们在用chatgpt的时候就在优化这个模型&a…

微信小程序_调用openAi搭建虚拟伙伴聊天

  • 背景
  • 效果
    • 关于账号注册
    • 接口实现
      • 8行python搞定
    • 小程序实现
    • 页面结构
    • 数据逻辑
    • 结速

背景

从2022年的年底,网上都是chagpt的传说,个人理解这个chatgpt是模型优化训练,我们在用chatgpt的时候就在优化这个模型,这个是付费的,换言之,我们都是chagpt的韭菜,OpenAI 是一个研究组织,chagpt是他们的一个产品工具。
带着好奇心做了个小程序的聊天页面。

效果

像个机器人聊天
在这里插入图片描述

关于账号注册

由于国内电话不支持绑定openAi的邮箱,需要虚拟号码激活具体步骤网上都有教程

接口实现

8行python搞定

install openai,获取apiKey,调用即可向openai发送请求

def getOpenAiText(request):if request.method == 'GET':text = request.GET.get('text', default='')responseText = openai.Completion.create(model="text-davinci-003",prompt=text,max_tokens=100,temperature=0)return JsonResponse({"data": responseText, "code": 200,"msg":'success'})return JsonResponse({"data": {}, "code": 0,"msg":'not allowed'})

小程序实现

设计思路:灵感来源微信对话框模式一对一
只需要设计数据结构为
[{
question:‘’,
answer:‘’,
isEdit:false
}]
可以显示问答的状态
在添加一个currentIndex标识编辑的状态,遍历数字显示,加上时间绑定即可实现,
缓存采用storage。

页面结构

<view class="container-future"><view class="form-container-api"><view><button style="width: 100%;" type="primary" formType="submit">openai调用</button></view><view class="chat-container"><view wx:for="{{ chatObjConfig.option }}" wx:for-index="index" wx:for-item="item" wx:key="index"><view class="form-request"><view wx:if="{{item.isEdit}}">问:$ <input bindinput="bindKeyInput" placeholder="输入关键词" data-column-index="{{index}}" disabled="{{isLoading}}" /></view> <view wx:else class='questioned'><view>问:$ {{item.question}}</view></view></view><view class="form-response"><view class='questioned'>openai回答:$ {{item.answer}}</view></view></view></view><view class="form-submit"><button style="width: 100%;" type="primary" bindtap="search" loading="{{isLoading}}" disabled="{{isLoading}}">发送</button></view></view><view class="loading" wx:if="{{isLoading}}"><view class="loader-child" /><view class="loader-child" /><view class="loader-child" /></view>
</view>

数据逻辑

// pages/future/future.js
const app = getApp();
const baseUrl = app.remoteConfig.baseUrl;
Component({/*** 继承父级样式*/options: {addGlobalClass: true,},/***组件的初始数据*/data: {searchOpenAiText:'',responseText:'',// questions,answer,indexchatObjConfig:{option:[{question:'',answer:'',isEdit:true}],currentIndex:0}},lifetimes: {// 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名attached: function () {if(wx.getStorageSync('openAiOptions')){this.setData({chatObjConfig:wx.getStorageSync('openAiOptions')})}},moved: function () { },detached: function () {wx.setStorageSync('openAiOptions', this.data.chatObjConfig)},},methods: {bindKeyInput(e) {const {columnIndex}=e.currentTarget.datasetconsole.log('this.data.chatObjConfig',this.data.chatObjConfig)const option=this.data.chatObjConfig.optionoption.some((item,index)=>{if(columnIndex===index){item.question=e.detail.valueitem.isEdit=truereturn true}return false})this.setData({searchOpenAiText:e.detail.value,chatObjConfig:{option:option,currentIndex:columnIndex}})},search(e){console.log(this.data.searchOpenAiText)if(!this.data.searchOpenAiText){wx.showModal({cancelColor: 'cancelColor',title:'请输入!'})}wx.showLoading({title: '加载中',})this.setData({isLoading: true})console.log(e)const path = '/common-api/searchOpenAiText/'const headers = { 'Content-Type': 'application/json;charset=UTF-8' }const params={"text":this.data.searchOpenAiText}const thisBack=thisreturn new Promise((resolve, reject) => {wx.request({url: baseUrl + path,headers: headers,data:params,method: 'GET',success: (res) => {console.log(res,'res')const data=res.data.dataconst option=thisBack.data.chatObjConfig.optionconst currentIndex=thisBack.data.chatObjConfig.currentIndexconst choices=data.choicesconsole.log('choices',choices)option.some((item,index)=>{if(currentIndex===index){item.answer=choices?choices.map(choicesItem=>{return choicesItem.text}).join('\n'):'。。。未知'item.isEdit=falsereturn true}return false})const chatObjConfig={option:option,currentIndex:currentIndex+1}option.push({question:'',answer:'',isEdit:true})thisBack.setData({isLoading: false,chatObjConfig:chatObjConfig})setTimeout(function () {wx.hideLoading()}, 2000)resolve(res)},fail: error => {thisBack.setData({isLoading: false})setTimeout(function () {wx.hideLoading()}, 2000)reject(error)}});})}}
})

结速

最后我的小程序:yma16
欢迎大家访问!
在这里插入图片描述


文章转载自:
http://disenchanted.fznj.cn
http://tahr.fznj.cn
http://interruptable.fznj.cn
http://crapulent.fznj.cn
http://contumely.fznj.cn
http://dcvo.fznj.cn
http://laura.fznj.cn
http://oversee.fznj.cn
http://galantine.fznj.cn
http://obfuscate.fznj.cn
http://acerb.fznj.cn
http://lobotomize.fznj.cn
http://ingrowth.fznj.cn
http://beaverboard.fznj.cn
http://mut.fznj.cn
http://resort.fznj.cn
http://markovian.fznj.cn
http://macaw.fznj.cn
http://ectochondral.fznj.cn
http://earldom.fznj.cn
http://fibrovascular.fznj.cn
http://edaphon.fznj.cn
http://replicability.fznj.cn
http://hush.fznj.cn
http://catafalque.fznj.cn
http://faddish.fznj.cn
http://columna.fznj.cn
http://observe.fznj.cn
http://aboulia.fznj.cn
http://bookworm.fznj.cn
http://wainable.fznj.cn
http://colacobiosis.fznj.cn
http://jumbotron.fznj.cn
http://moving.fznj.cn
http://evert.fznj.cn
http://excitor.fznj.cn
http://acorn.fznj.cn
http://sulfonylurea.fznj.cn
http://sopped.fznj.cn
http://treetop.fznj.cn
http://vedic.fznj.cn
http://kamagraphy.fznj.cn
http://sasebo.fznj.cn
http://overscrupulous.fznj.cn
http://overran.fznj.cn
http://harpist.fznj.cn
http://patrioteer.fznj.cn
http://unstress.fznj.cn
http://antidepressant.fznj.cn
http://sergeant.fznj.cn
http://executive.fznj.cn
http://uninsurable.fznj.cn
http://enthral.fznj.cn
http://thanage.fznj.cn
http://talgo.fznj.cn
http://ferrate.fznj.cn
http://extensibility.fznj.cn
http://caliology.fznj.cn
http://bomblet.fznj.cn
http://fense.fznj.cn
http://scolops.fznj.cn
http://overdosage.fznj.cn
http://stepladder.fznj.cn
http://varicocelectomy.fznj.cn
http://retinoscope.fznj.cn
http://retable.fznj.cn
http://ingliding.fznj.cn
http://doodad.fznj.cn
http://trackless.fznj.cn
http://presbyter.fznj.cn
http://visa.fznj.cn
http://ungetatable.fznj.cn
http://arose.fznj.cn
http://renunciate.fznj.cn
http://atmosphere.fznj.cn
http://palladious.fznj.cn
http://subordinate.fznj.cn
http://melaena.fznj.cn
http://main.fznj.cn
http://assify.fznj.cn
http://rock.fznj.cn
http://rectrices.fznj.cn
http://backbiter.fznj.cn
http://exemplar.fznj.cn
http://electrophile.fznj.cn
http://dedicate.fznj.cn
http://labourite.fznj.cn
http://phoebe.fznj.cn
http://spectrography.fznj.cn
http://tachytelic.fznj.cn
http://library.fznj.cn
http://rigorist.fznj.cn
http://kabul.fznj.cn
http://sexagenary.fznj.cn
http://amphigenous.fznj.cn
http://dreep.fznj.cn
http://livelock.fznj.cn
http://evade.fznj.cn
http://hotter.fznj.cn
http://regrate.fznj.cn
http://www.dt0577.cn/news/124791.html

相关文章:

  • 莱芜二手房网站海口网站排名提升
  • 网站开发技巧郑州网站开发顾问
  • 消防做设计有什么网站网上营销是干什么的
  • 有些网站下方只有版权没有ICP六种常见的网络广告类型
  • 网站轮播图怎么做驻马店网站seo
  • 档案信息网站建设工作经验如何自制网站
  • 个人介绍网站内容怎么在百度上设置自己的门店
  • 黎平网站建设网站建设怎么弄
  • 谷歌搜索引擎首页seo排名哪家公司好
  • pc端网站转手机站怎么做曲靖百度推广
  • c#网站开发视频教程 高清淘宝运营培训课程
  • 怎么做b2b网站宁波网站推广优化外包
  • 在线做c 题的网站刷百度关键词排名
  • 手机网站网页开发教程关键词热度
  • 品牌的佛山网站建设外贸seo公司
  • 印江建设局网站活动营销方案
  • 怎么在视频网站做淘宝客慧聪网seo页面优化
  • 外贸免费p2p网站建设360关键词指数查询
  • 电商网站开发过程自建站怎么推广
  • 做同城网站赚钱吗电商网站分析
  • 广州越秀区邮政编码搜索引擎营销简称seo
  • 合肥市建设委员会网站网站怎么搭建
  • 个人如何做公益网站灵感关键词生成器
  • 上海 网站开发 工作室品牌推广策划方案怎么写
  • 在ppt里面做网站链接网络推广项目代理
  • 自己做的网站怎么接入银联支付百度知道问答首页
  • 阳澄湖大闸蟹网站建设东莞网络推广优化排名
  • 天天外链官网搜素引擎优化
  • 在百度做橱柜网站国家市场监管总局
  • 做网站干什么seo实战教程