From f797fd05144f0de8ff0766fc12e85e853c4149b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E4=B8=96=E6=98=8A?= <40659515+202252197@users.noreply.github.com> Date: Tue, 11 Apr 2023 17:49:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/pages/chatHome/chatwindow.vue | 52 +++++++++++++++++--------- src/view/pages/chatHome/index.vue | 15 +++----- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/view/pages/chatHome/chatwindow.vue b/src/view/pages/chatHome/chatwindow.vue index f008002..e636142 100644 --- a/src/view/pages/chatHome/chatwindow.vue +++ b/src/view/pages/chatHome/chatwindow.vue @@ -229,7 +229,7 @@ export default { this.sendText() } }, - readStream(reader,_this, currentResLocation) { + readStream(reader,_this, currentResLocation,type) { return reader.read().then(({ done, value }) => { if ( done ) { return; @@ -246,12 +246,19 @@ export default { if(decoded.trim()==="[DONE]"){ return; }else{ - const response = JSON.parse(decoded).choices[0].delta.content?JSON.parse(decoded).choices[0].delta.content:""; - _this.chatList[currentResLocation].msg=_this.chatList[currentResLocation].msg+response + console.log(type) + if(type==="chat"){ + const response = JSON.parse(decoded).choices[0].delta.content ? JSON.parse(decoded).choices[0].delta.content : ""; + _this.chatList[currentResLocation].msg = _this.chatList[currentResLocation].msg + response + _this.scrollBottom(); + }else{ + const response = JSON.parse(decoded).choices[0].text; + _this.chatList[currentResLocation].msg = _this.chatList[currentResLocation].msg + response + } } } }) - return this.readStream(reader,_this, currentResLocation); + return this.readStream(reader,_this, currentResLocation,type); }); }, //导入当前内容json触发的方法 @@ -532,14 +539,14 @@ export default { } else { //如果是文字模式则进入 params.model = this.frinedInfo.id, - params.max_tokens = this.settingInfo.chat.MaxTokens, - params.temperature = this.settingInfo.chat.Temperature, - params.top_p = this.settingInfo.chat.TopP, - params.n = this.settingInfo.chat.n, - params.stream = this.settingInfo.chat.stream, - params.stop = this.settingInfo.chat.stop, - params.presence_penalty = this.settingInfo.chat.PresencePenalty, - params.frequency_penalty = this.settingInfo.chat.FrequencyPenalty + params.max_tokens = this.settingInfo.chat.MaxTokens, + params.temperature = this.settingInfo.chat.Temperature, + params.top_p = this.settingInfo.chat.TopP, + params.n = this.settingInfo.chat.n, + params.stream = this.settingInfo.chat.stream, + params.stop = this.settingInfo.chat.stop, + params.presence_penalty = this.settingInfo.chat.PresencePenalty, + params.frequency_penalty = this.settingInfo.chat.FrequencyPenalty let chatBeforResMsg = { headImg: AI_HEAD_IMG_URL, @@ -552,7 +559,19 @@ export default { if (this.frinedInfo.id === "gpt-3.5-turbo" || this.frinedInfo.id === "gpt-3.5-turbo-0301") { this.chatCompletion(params, chatBeforResMsg) } else { - this.completion(params, chatBeforResMsg) + if(this.settingInfo.cutSetting===0){ + if(this.frinedInfo.id === "text-davinci-003" ){ + this.completion(params, chatBeforResMsg) + }else{ + this.$message.error("暂时不支持gpt-3.5-turbo、gpt-3.5-turbo-0301、text-davinci-003以外的模型聊天~") + this.$nextTick(() => { + this.acqStatus = true + }) + } + }else{ + this.completion(params, chatBeforResMsg) + } + } } if (this.storeStatu == 0) { @@ -637,8 +656,7 @@ export default { const currentResLocation = this.chatList.length - 1 let _this = this - - try { + try { if ( this.settingInfo.chat.stream ){ await fetch( base.baseUrl+'/v1/chat/completions',{ @@ -654,7 +672,7 @@ export default { } ).then(response=>{ const reader = response.body.getReader(); - this.readStream(reader,_this, currentResLocation); + this.readStream(reader,_this, currentResLocation,"chat"); }); }else{ await fetch( @@ -726,7 +744,7 @@ export default { this.acqStatus = true }); // _this.chatList[currentResLocation].msg = _this.chatList[currentResLocation].msg + ":grinning:" - this.readStream(reader,_this, currentResLocation); + this.readStream(reader,_this, currentResLocation,"completion"); }) } catch (error) { diff --git a/src/view/pages/chatHome/index.vue b/src/view/pages/chatHome/index.vue index 168256b..492220c 100644 --- a/src/view/pages/chatHome/index.vue +++ b/src/view/pages/chatHome/index.vue @@ -656,6 +656,7 @@ export default { batch_sizeStr: "", //全部的设置参数 SettingInfo: { + cutSetting : 1, KeyMsg: process.env.VUE_APP_OPENAI_API_KEY, readefile: false, inputStatus: true, @@ -1019,16 +1020,6 @@ export default { this.showSetupList = true; }; }, - // // 更新当前余额 - // updateMoneyInfo() { - // getMoneyInfo(this.SettingInfo.KeyMsg).then((res) => { - // this.$nextTick(() => { - // this.moneryInfo.totalGranted = res.total_granted; - // this.moneryInfo.totalUsed = res.total_used; - // this.moneryInfo.totalAvailable = res.total_available; - // }) - // }) - // }, //创建会话 newSession() { //获取当前会话长度 @@ -1070,6 +1061,7 @@ export default { this.fineTuningInfo = {}; this.SettingStatus = 0 this.cutSetting = 0 + this.SettingInfo.cutSetting = 0 // this.showChatWindow = false; }, //会话列表被点击 @@ -1078,6 +1070,7 @@ export default { this.clearCurrent() this.SettingStatus = 5 this.cutSetting = 1 + this.SettingInfo.cutSetting = 1 this.chatWindowInfo = { img: "", name: "ChatGPT", @@ -1107,6 +1100,7 @@ export default { this.clearCurrent() this.SettingStatus = 3; this.cutSetting = 2 + this.SettingInfo.cutSetting = 2 // this.showChatWindow = false; //获取微调模型列表 this.getFineTunessList(this.SettingInfo.KeyMsg) @@ -1128,6 +1122,7 @@ export default { this.fineTuningInfo = {}; this.SettingStatus = 4; this.cutSetting = 3 + this.SettingInfo.cutSetting = 3 //获取微调模型列表 this.getFilessList(this.SettingInfo.KeyMsg) },