From c208a2ff733a89fce6eea3ad4c283d7daa182e63 Mon Sep 17 00:00:00 2001 From: AndzejsP Date: Mon, 8 May 2023 17:04:44 +0300 Subject: [PATCH 1/2] some work in progress --- app.py | 3 +- pyGpt4All/api.py | 2 +- web/src/components/Message.vue | 7 +++- web/src/views/DiscussionsView.vue | 66 +++++++++++++++++++++++-------- 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/app.py b/app.py index 411d9c77..357d1ef3 100644 --- a/app.py +++ b/app.py @@ -495,7 +495,8 @@ class Gpt4AllWebUI(GPT4AllAPI): print() # Send final message - self.socketio.emit('final', {'data': self.bot_says}) + self.socketio.emit('final', {'data': self.bot_says, 'response_id':response_id, 'parent':self.current_message_id, 'discussion_id':self.current_discussion.discussion_id}) + self.current_discussion.update_message(response_id, self.bot_says) self.full_message_list.append(self.bot_says) diff --git a/pyGpt4All/api.py b/pyGpt4All/api.py index 0c848e6c..01b75d89 100644 --- a/pyGpt4All/api.py +++ b/pyGpt4All/api.py @@ -180,7 +180,7 @@ class GPT4AllAPI(): self.bot_says += text if not self.personality.detect_antiprompt(self.bot_says): - self.socketio.emit('message', {'data': self.bot_says}) + self.socketio.emit('message', {'data': self.bot_says, 'parent':self.current_message_id, 'discussion_id':self.current_discussion.discussion_id}) if self.cancel_gen: print("Generation canceled") self.cancel_gen = False diff --git a/web/src/components/Message.vue b/web/src/components/Message.vue index ef923224..6119e979 100644 --- a/web/src/components/Message.vue +++ b/web/src/components/Message.vue @@ -40,7 +40,7 @@ @click.stop="copyContentToClipboard()"> -
+
@@ -83,7 +83,7 @@ import feather from 'feather-icons' import MarkdownRenderer from './MarkdownRenderer.vue'; export default { name: 'Message', - emits: ['copy', 'delete', 'rankUp', 'rankDown','updateMessage'], + emits: ['copy', 'delete', 'rankUp', 'rankDown','updateMessage','resendMessage'], components: { MarkdownRenderer }, @@ -128,6 +128,9 @@ export default { this.$emit('updateMessage', this.message.id, this.new_message_content) this.editMsgMode = false }, + resendMessage(){ + this.$emit('resendMessage', this.message.id, this.new_message_content) + }, getImgUrl() { if (this.message.sender == "user") { diff --git a/web/src/views/DiscussionsView.vue b/web/src/views/DiscussionsView.vue index 0ccc8e23..99b1126b 100644 --- a/web/src/views/DiscussionsView.vue +++ b/web/src/views/DiscussionsView.vue @@ -109,10 +109,10 @@
- - + + @@ -308,7 +308,7 @@ export default { }, async update_message(id, message) { try { - const res = await axios.get('/update_message', { params: { id: id, message:message } }) + const res = await axios.get('/update_message', { params: { id: id, message: message } }) if (res) { return res.data @@ -409,7 +409,7 @@ export default { let responseMessage = { content: '..typing', id: msgObj.response_id, - //parent: 10, + parent: msgObj.id, rank: 0, sender: msgObj.bot //type: 0 @@ -458,9 +458,22 @@ export default { }, steamMessageContent(content) { // Streams response message content from backend - //console.log(content) - const lastMsg = this.discussionArr[this.discussionArr.length - 1] - lastMsg.content = content.data + //console.log("stream", JSON.stringify(content)) + const parent = content.parent + const discussion_id = content.discussion_id + if (this.currentDiscussion.id = discussion_id) { + const index = this.discussionArr.findIndex((x) => x.parent == parent) + const messageItem = this.discussionArr[index] + if (messageItem) { + messageItem.content = content.data + //console.log(parent, index, discussion_id, content.data) + } + + } + + + //const lastMsg = this.discussionArr[this.discussionArr.length - 1] + //lastMsg.content = content.data }, async changeTitleUsingUserMSG(id, msg) { // If discussion is untitled or title is null then it sets the title to first user message. @@ -622,9 +635,9 @@ export default { }, async rankUpMessage(msgId) { await this.message_rank_up(msgId).then((res) => { - + const message = this.discussionArr[this.discussionArr.findIndex(item => item.id == msgId)] - message.rank= res.new_rank + message.rank = res.new_rank }).catch(() => { console.log("Error: Could not rank up message") @@ -633,9 +646,9 @@ export default { }, async rankDownMessage(msgId) { await this.message_rank_down(msgId).then((res) => { - + const message = this.discussionArr[this.discussionArr.findIndex(item => item.id == msgId)] - message.rank= res.new_rank + message.rank = res.new_rank }).catch(() => { console.log("Error: Could not rank down message") @@ -644,16 +657,36 @@ export default { }, async updateMessage(msgId, msg) { await this.update_message(msgId, msg).then(() => { - + const message = this.discussionArr[this.discussionArr.findIndex(item => item.id == msgId)] - message.content= msg - + message.content = msg + }).catch(() => { console.log("Error: Could not update message") }) }, + resendMessage(msgId, msg) { + // Resend message + this.isGenerating = true; + this.setDiscussionLoading(this.currentDiscussion.id, this.isGenerating); + axios.get('/get_generation_status', {}).then((res) => { + if (res) { + //console.log(res.data.status); + if (!res.data.status) { + socket.emit('generate_msg_from', { prompt: msg, id: msgId }); + + + } + else { + console.log("Already generating"); + } + } + }).catch((error) => { + console.log("Error: Could not get generation status", error); + }); + }, stopGenerating() { this.stop_gen() this.isGenerating = false @@ -696,6 +729,7 @@ export default { socket.on('infos', this.createBotMsg) socket.on('message', this.steamMessageContent) socket.on("final", this.finalMsgEvent) + }, activated() { // This lifecycle hook runs every time you switch from other page back to this page (vue-router) From cd31ec26ef83762651a267abbf8e235ed2a78ad3 Mon Sep 17 00:00:00 2001 From: AndzejsP Date: Mon, 8 May 2023 17:15:01 +0300 Subject: [PATCH 2/2] more debugging --- web/src/views/DiscussionsView.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/views/DiscussionsView.vue b/web/src/views/DiscussionsView.vue index 99b1126b..d9a9e645 100644 --- a/web/src/views/DiscussionsView.vue +++ b/web/src/views/DiscussionsView.vue @@ -425,7 +425,7 @@ export default { if (this.currentDiscussion.title === '' || this.currentDiscussion.title === null) { this.changeTitleUsingUserMSG(this.currentDiscussion.id, msgObj.content) } - + console.log("infos",msgObj) }, sendMsg(msg) { // Sends message to backend