From 82be1991acab9b8d15c78fb6e2d6e9d9069074fa Mon Sep 17 00:00:00 2001
From: cshenfu <men883234@gmail.com>
Date: 星期五, 02 六月 2023 14:09:58 +0800
Subject: [PATCH] add cliend_id
---
pages/index/index.vue | 128 +++++++++++++++++++++++++++++++++++++-----
1 files changed, 113 insertions(+), 15 deletions(-)
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 4d60ef5..5244757 100755
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -78,6 +78,7 @@
export default {
data() {
return {
+ client_id: "",
prompt: '',
arr: [],
timer: null,
@@ -138,19 +139,56 @@
});
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')) {
- that.typeingId = json.id
- if (!json.choices[0].delta.finish_reason) {
- if (json.choices[0].delta.hasOwnProperty('content')) {
- that.typeingText += json.choices[0].delta.content
- // 姝ゅ鑷鏂熼厡鏄惁鏇挎崲
- // that.typeingText = that.typeingText.replace(/[cogptn]+/ig, "ChatGLM-6B")
+ if (json.hasOwnProperty('type') && json.type == 'content') {
+ that.typeingText = json.content;
+ that.$nextTick(() => {
+ uni.pageScrollTo({
+ scrollTop: 20000,
+ duration: 100
+ });
+ });
+ }
+ 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: that.userInfo.member_id
+ // uid: 3
+ })
+ })
+ }
+ if (json.type == 'content') {
+ that.loading = false;
+ that.typeingText = "";
+ that.typeingId = "";
+ that.arr.push({
+ role: json.content.role,
+ content: json.content.content,
+ });
+ if (!that.chat_id) {
+ that.chat_id = json.content.chat_id
}
+ if (json.content.finish_reason == 'length') {
+ that.goon = true;
+ }
+ that.$store.commit('useNum', 1);
+ that.$nextTick(() => {
+ uni.pageScrollTo({
+ scrollTop: 20000,
+ duration: 100
+ });
+ });
}
}
-
+
});
// socket鏂紑鏃堕�氱煡鍚庣鏀瑰彉鐧诲綍鐘舵��
uni.onSocketClose(function(res) {
@@ -219,8 +257,24 @@
this.$failToast("璇疯緭鍏ュ唴瀹�");
return;
}
-
+
this.loading = true;
+ 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.sendout()
+ }, 300)
+ }
+ })
+ return
+ }
this.arr.push({
role: 'user',
content: this.prompt,
@@ -239,12 +293,14 @@
}, 200);
},
sub(message) {
+ this.goon = false;
// 鏉′欢缂栬瘧澶勭悊锛宧5绔痷ni.request涓巗ocket浼氫簰鐩搁樆濉�
// #ifndef H5
this.$request("/api/Message/sendV2", "POST", {
message: message,
chat_id: this.chat_id,
- model_id: this.now_model.assistant_id
+ model_id: this.now_model.assistant_id,
+ client_id: this.client_id
// member_id: 3 // 璋冭瘯涔嬬敤锛岀嚎涓婄幆澧冧负token瑙g爜
}).then((res) => {
console.log(res);
@@ -254,12 +310,15 @@
this.typeingId = "";
this.arr.push({
role: res.data.role,
- // 姝ゅ鑷鏂熼厡鏄惁鏇挎崲
content: res.data.content,
- // content: res.data.content.replace(/[cogptn]+/ig, "ChatGLM-6B")
});
if (!this.chat_id) {
+ this.chatList[0].chat_id = res.data.chat_id
+ this.chatList[0].title = message
this.chat_id = res.data.chat_id
+ }
+ if (res.data.finish_reason == 'length') {
+ this.goon = true;
}
this.$store.commit('useNum', 1);
this.$nextTick(() => {
@@ -276,6 +335,13 @@
uni.showModal({
content: res.msg
})
+ } else if (res.status == 403) {
+ this.loading = false;
+ this.$failToast(res.msg);
+ this.arr.pop()
+ this.prompt = res.data
+ } else if (res.status == 600) {
+
} else {
this.loading = false;
this.$failToast(res.msg);
@@ -293,15 +359,35 @@
data: {
message: message,
chat_id: this.chat_id,
- model_id: this.now_model.assistant_id
+ model_id: this.now_model.assistant_id,
+ client_id: this.client_id
},
headers: {
'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
'Authorization': this.$store.state.token
}
}).then(response => {
+
console.log(response)
let res = response.data
+ console.log(res)
+ 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.loading = false;
this.typeingText = "";
@@ -311,7 +397,12 @@
content: res.data.content
});
if (!this.chat_id) {
+ this.chatList[0].chat_id = res.data.chat_id
+ this.chatList[0].title = message
this.chat_id = res.data.chat_id
+ }
+ if (res.data.finish_reason == 'length') {
+ this.goon = true;
}
this.$store.commit('useNum', 1);
this.$nextTick(() => {
@@ -328,6 +419,13 @@
uni.showModal({
content: res.msg
})
+ } else if (res.status == 403) {
+ this.loading = false;
+ this.$failToast(res.msg);
+ this.arr.pop()
+ this.prompt = res.data
+ } else if (res.status == 600) {
+
} else {
this.loading = false;
this.$failToast(res.msg);
@@ -336,7 +434,7 @@
// reject(error);
});
// #endif
-
+
},
copy(item) {
uni.setClipboardData({
--
Gitblit v1.9.1