最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

如何調(diào)用openai的api

2023-02-14 19:25 作者:MlKUFANS  | 我要投稿

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>


<div id="app" style="display: flex;flex-flow: column;margin: 20 ">

? ? <scroll-view scroll-with-animation scroll-y="true" style="width: 100%;">

? ? ? ? <!-- 用來(lái)獲取消息體高度 -->

? ? ? ? <view id="okk" scroll-with-animation>

? ? ? ? ? ? <!-- 消息 -->

? ? ? ? ? ? <view v-for="(x,i) in msgList" :key="i">

? ? ? ? ? ? ? ? <!-- 用戶消息 頭像可選加入-->

? ? ? ? ? ? ? ? <view v-if="x.my" style="display: flex;

? ? ? ? ? ? ? ? flex-direction: column;

? ? ? ? ? ? ? ? align-items: flex-end;">


? ? ? ? ? ? ? ? ? ? <view style="width: 400rpx;">

? ? ? ? ? ? ? ? ? ? ? ? <view style="border-radius: 35rpx;">

? ? ? ? ? ? ? ? ? ? ? ? ? ? <text style="word-break: break-all;">{{x.msg}}</text>

? ? ? ? ? ? ? ? ? ? ? ? </view>

? ? ? ? ? ? ? ? ? ? </view>


? ? ? ? ? ? ? ? </view>

? ? ? ? ? ? ? ? <!-- 機(jī)器人消息 -->

? ? ? ? ? ? ? ? <view v-if="!x.my" style="display: flex;

? ? ? ? ? ? ? ? flex-direction: row;

? ? ? ? ? ? ? ? align-items: flex-start;">


? ? ? ? ? ? ? ? ? ? <view style="width: 500rpx;">

? ? ? ? ? ? ? ? ? ? ? ? <view style="border-radius: 35rpx;background-color: #f9f9f9;">

? ? ? ? ? ? ? ? ? ? ? ? ? ? <text style="word-break: break-all;">{{x.msg}}</text>

? ? ? ? ? ? ? ? ? ? ? ? </view>

? ? ? ? ? ? ? ? ? ? </view>

? ? ? ? ? ? ? ? </view>

? ? ? ? ? ? </view>



? ? ? ? ? ? <view style="height: 130rpx;">


? ? ? ? ? ? </view>

? ? ? ? </view>


? ? </scroll-view>


? ? <!-- 底部導(dǎo)航欄 -->

? ? <view style="position: fixed;bottom:0px;width: 100%;display: flex;

? ? flex-direction: column;

? ? justify-content: center;

? ? align-items: center;">

? ? ? ? <view style="font-size: 55rpx;display: flex;

? ? ? ? flex-direction: row;

? ? ? ? justify-content: space-around;

? ? ? ? align-items: center;width: 75%;

? ? margin: 20;">


? ? ? ? ? ? <input v-model="msg" type="text" style="width: 75%;

? ? ? ? ? ? height: 45px;

? ? ? ? ? ? border-radius: 50px;

? ? ? ? ? ? padding-left: 20px;

? ? ? ? ? ? margin-left: 10px;background-color: #f0f0f0;" @confirm="sendMsg" confirm-type="search"

? ? ? ? ? ? ? ? placeholder-class="my-neirong-sm" placeholder="用一句簡(jiǎn)短的話描述您的問(wèn)題" />

? ? ? ? ? ? <button @click="sendMsg" :disabled="msgLoad" style="height: 45px;

? ? ? ? ? ? width: 20%;;

? ? color: #030303;? ? border-radius: 2500px;">{{sentext}}</button>

? ? ? ? </view>

? ? </view>

? ? </view>

</div>

<script>

? ? const { createApp } = Vue

? ? createApp({

? ? ? ? data() {

? ? ? ? ? ? return {

? ? ? ? ? ? ? ? api: '替換為在官網(wǎng)申請(qǐng)到的接口',

? ? ? ? ? ? ? ? msgLoad: false,

? ? ? ? ? ? ? ? anData: {},

? ? ? ? ? ? ? ? sentext: '發(fā)送',


? ? ? ? ? ? ? ? animationData: {},

? ? ? ? ? ? ? ? showTow: false,

? ? ? ? ? ? ? ? msgList: [{

? ? ? ? ? ? ? ? ? ? my: false,

? ? ? ? ? ? ? ? ? ? msg: "你好我是openAI機(jī)器人,請(qǐng)問(wèn)有什么問(wèn)題可以幫助您?"

? ? ? ? ? ? ? ? }],

? ? ? ? ? ? ? ? msgContent: "",

? ? ? ? ? ? ? ? msg: ""

? ? ? ? ? ? }

? ? ? ? },

? ? ? ? methods: {

? ? ? ? ? ? sendMsg() {


? ? ? ? ? ? ? ? // 消息為空不做任何操作

? ? ? ? ? ? ? ? if (this.msg == "") {

? ? ? ? ? ? ? ? ? ? return 0;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? this.sentext = '請(qǐng)求中'

? ? ? ? ? ? ? ? this.msgList.push({

? ? ? ? ? ? ? ? ? ? "msg": this.msg,

? ? ? ? ? ? ? ? ? ? "my": true

? ? ? ? ? ? ? ? })

? ? ? ? ? ? ? ? console.log(this.msg);

? ? ? ? ? ? ? ? this.msgContent += ('YOU:' + this.msg + "\n")

? ? ? ? ? ? ? ? this.msgLoad = true

? ? ? ? ? ? ? ? // 清除消息

? ? ? ? ? ? ? ? this.msg = ""

? ? ? ? ? ? ? ? axios.post('https://api.openai.com/v1/completions', {

? ? ? ? ? ? ? ? ? ? prompt: this.msgContent, max_tokens: 2048, model: "text-davinci-003"

? ? ? ? ? ? ? ? }, {

? ? ? ? ? ? ? ? ? ? headers: { 'content-type': 'application/json', 'Authorization': 'Bearer ' + this.api }

? ? ? ? ? ? ? ? }).then(res => {

? ? ? ? ? ? ? ? ? ? console.log(res);

? ? ? ? ? ? ? ? ? ? let text = res.data.choices[0].text.replace("openai:", "").replace("openai:", "").replace(/^\n|\n$/g, "")

? ? ? ? ? ? ? ? ? ? console.log(text);

? ? ? ? ? ? ? ? ? ? this.msgList.push({

? ? ? ? ? ? ? ? ? ? ? ? "msg": text,

? ? ? ? ? ? ? ? ? ? ? ? "my": false

? ? ? ? ? ? ? ? ? ? })

? ? ? ? ? ? ? ? ? ? this.msgContent += (text + "\n")

? ? ? ? ? ? ? ? ? ? this.msgLoad = false

? ? ? ? ? ? ? ? ? ? this.sentext = '發(fā)送'

? ? ? ? ? ? ? ? })


? ? ? ? ? ? },



? ? ? ? }

? ? }).mount('#app')

</script>


如何調(diào)用openai的api的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
宜宾市| 响水县| 屏东市| 望城县| 邓州市| 利辛县| 叙永县| 涪陵区| 永顺县| 邵武市| 盘山县| 新野县| 公主岭市| 泽州县| 科尔| 平武县| 屏南县| 黎城县| 峨眉山市| 武冈市| 建湖县| 方城县| 云阳县| 休宁县| 墨玉县| 蓬莱市| 卫辉市| 巩留县| 老河口市| 松桃| 苍山县| 延安市| 静安区| 苍梧县| 和静县| 武义县| 祁东县| 黎川县| 从江县| 吉木萨尔县| 平乐县|