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/chat.vue | 124 +++++++++++++++++++++++++++++++++++++----
1 files changed, 111 insertions(+), 13 deletions(-)
diff --git a/pages/index/chat.vue b/pages/index/chat.vue
index fd7290c..023e3ff 100755
--- a/pages/index/chat.vue
+++ b/pages/index/chat.vue
@@ -122,6 +122,7 @@
mixins: [mixin],
data() {
return {
+ client_id: "",
prompt: '',
arr: [],
timer: null,
@@ -183,19 +184,58 @@
});
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
+ that.chatList[0].chat_id = json.content.chat_id
+ that.chatList[0].title = 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
+ });
+ });
}
}
-
+
});
// socket鏂紑鏃堕�氱煡鍚庣鏀瑰彉鐧诲綍鐘舵��
uni.onSocketClose(function(res) {
@@ -334,14 +374,32 @@
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,
message_id: this.arr.length + 1
});
let message = this.prompt;
+
this.prompt = ""
this.$nextTick(() => {
uni.pageScrollTo({
@@ -354,12 +412,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);
@@ -378,6 +438,9 @@
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(() => {
uni.pageScrollTo({
@@ -393,6 +456,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);
@@ -410,7 +480,8 @@
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',
@@ -419,6 +490,23 @@
}).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.loading = false;
this.typeingText = "";
@@ -431,6 +519,9 @@
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(() => {
@@ -447,6 +538,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);
@@ -455,7 +553,7 @@
// reject(error);
});
// #endif
-
+
},
copy(item) {
uni.setClipboardData({
--
Gitblit v1.9.1