| | |
| | | mixins: [mixin], |
| | | data() { |
| | | return { |
| | | client_id: "", |
| | | hot_question: [], |
| | | answer: defaultAnswer, |
| | | answerStatus: 0, // 0 是默认状态,1是生成中,2是已生成 |
| | |
| | | }); |
| | | uni.onSocketMessage(function(res) { |
| | | // console.log('收到服务器内容:' + res.data); |
| | | let json = JSON.parse(res.data) |
| | | let json = JSON.parse(res.data); |
| | | // console.log(json) |
| | | if (json.hasOwnProperty('id')) { |
| | | if (that.answerStatus != 1) { |
| | | that.answer = "" |
| | | that.answerStatus = 1; |
| | | if (json.hasOwnProperty('type') && json.type == 'content') { |
| | | that.answer = json.content; |
| | | } |
| | | if (json.hasOwnProperty('client_id') && json.client_id != '') { |
| | | console.log('更新id') |
| | | that.client_id = json.client_id |
| | | } |
| | | |
| | | if (json.status == 200) { |
| | | if (json.msg == '连接成功') { |
| | | uni.sendSocketMessage({ |
| | | data: JSON.stringify({ |
| | | type: 'login', |
| | | uid: userInfo.member_id |
| | | // uid: 3 |
| | | }) |
| | | }) |
| | | } |
| | | that.typeingId = json.id |
| | | if (!json.choices[0].delta.finish_reason) { |
| | | if (json.choices[0].delta.hasOwnProperty('content')) { |
| | | that.answer += json.choices[0].delta.content |
| | | // 此处自行斟酌是否替换 |
| | | // that.typeingText = that.typeingText.replace(/[cogptn]+/ig, "ChatGLM-6B") |
| | | if (json.type == 'content') { |
| | | that.answerStatus = 2; |
| | | that.answer = json.content.content |
| | | if (json.content.finish_reason == 'length') { |
| | | that.goon = true; |
| | | } |
| | | that.$store.commit('useNum', 1); |
| | | that.$nextTick(() => { |
| | | uni.pageScrollTo({ |
| | | scrollTop: 20000, |
| | | duration: 100 |
| | | }); |
| | | }); |
| | | } |
| | | } |
| | | |
| | |
| | | this.$failToast("请输入内容"); |
| | | return; |
| | | } |
| | | if (!this.client_id) { |
| | | let userInfo = uni.getStorageSync('userInfo') |
| | | uni.sendSocketMessage({ |
| | | data: JSON.stringify({ |
| | | type: 'login', |
| | | uid: userInfo.member_id, |
| | | // uid: 3 |
| | | }), |
| | | success: (r) => { |
| | | setTimeout(() => { |
| | | this.submit() |
| | | }, 300) |
| | | } |
| | | }) |
| | | return |
| | | } |
| | | |
| | | this.answer = answerIng; |
| | | this.sub() |
| | |
| | | sub(message) { |
| | | // 条件编译处理,h5端uni.request与socket会互相阻塞 |
| | | // #ifndef H5 |
| | | this.$request("/api/Message/completions", "POST", { |
| | | this.$request("/api/Message/sendV2", "POST", { |
| | | message: this.prompt, |
| | | client_id: this.client_id, |
| | | type: 'question' |
| | | }).then((res) => { |
| | | console.log(res); |
| | | if (res.status == 200) { |
| | |
| | | uni.showModal({ |
| | | content: res.msg |
| | | }) |
| | | } else if(res.status == 600) { |
| | | |
| | | } else { |
| | | this.loading = false; |
| | | this.$failToast(res.msg); |
| | |
| | | // #ifdef H5 |
| | | axios({ |
| | | method: 'post', |
| | | url: setting.base_url + "/api/Message/completions", |
| | | url: setting.base_url + "/api/Message/sendV2", |
| | | data: { |
| | | message: this.prompt, |
| | | client_id: this.client_id, |
| | | type: 'question' |
| | | }, |
| | | headers: { |
| | | 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', |
| | |
| | | }).then(response => { |
| | | console.log(response) |
| | | let res = response.data |
| | | if (res.status == 101 || res.status == 102 || (res.status == 411 && res.msg == '请登录')) { |
| | | console.log(1) |
| | | this.$store.commit('logout') |
| | | uni.removeStorageSync('userInfo') |
| | | uni.removeStorageSync('token') |
| | | uni.showModal({ |
| | | title: "提示", |
| | | content: res.msg, |
| | | success() { |
| | | uni.reLaunch({ |
| | | url: "/pages/login/newlogin" |
| | | }) |
| | | } |
| | | }) |
| | | uni.hideLoading() |
| | | return |
| | | } |
| | | if (res.status == 200) { |
| | | this.answerStatus = 2; |
| | | setTimeout(() => { |
| | | this.answer = res.data |
| | | this.answer = res.data.content |
| | | }, 500); |
| | | this.$store.commit('useNum', 1); |
| | | this.$nextTick(() => { |
| | |
| | | uni.showModal({ |
| | | content: res.msg |
| | | }) |
| | | } else if(res.status == 600) { |
| | | |
| | | } else { |
| | | this.loading = false; |
| | | this.$failToast(res.msg); |