From 6ee99e8c23ff4d61409e6f70d308ff977a322df1 Mon Sep 17 00:00:00 2001 From: Germey Date: Sun, 25 Aug 2024 12:20:17 +0800 Subject: [PATCH] Fix regenete state (#130) Co-authored-by: AceDataCloud --- ...or-fd12543f-35b9-4d06-996e-99e2fb96b669.json | 7 +++++++ src/components/chat/Message.vue | 4 ++-- src/pages/chat/Conversation.vue | 17 ++++++++++------- src/store/chat/state.ts | 4 ++-- 4 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 change/@acedatacloud-nexior-fd12543f-35b9-4d06-996e-99e2fb96b669.json diff --git a/change/@acedatacloud-nexior-fd12543f-35b9-4d06-996e-99e2fb96b669.json b/change/@acedatacloud-nexior-fd12543f-35b9-4d06-996e-99e2fb96b669.json new file mode 100644 index 00000000..5c3987c3 --- /dev/null +++ b/change/@acedatacloud-nexior-fd12543f-35b9-4d06-996e-99e2fb96b669.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix chat responding state", + "packageName": "@acedatacloud/nexior", + "email": "office@acedata.cloud", + "dependentChangeType": "patch" +} diff --git a/src/components/chat/Message.vue b/src/components/chat/Message.vue index 198a75a2..28b40c58 100644 --- a/src/components/chat/Message.vue +++ b/src/components/chat/Message.vue @@ -323,6 +323,7 @@ export default defineComponent({ padding: 8px; width: 100%; max-width: 800px; + margin-bottom: 10px; .image { max-width: 100%; max-height: 300px; @@ -347,12 +348,11 @@ export default defineComponent({ display: flex; // Use flexbox for better alignment gap: 10px; // Adjust the gap value as needed margin-left: 5px; // Adjust the value as needed + color: var(--el-text-color-regular); .btn-restart { - color: var(--el-text-color-regular); font-size: 14px; } .btn-copy { - color: var(--el-text-color-regular); font-size: 14px; } } diff --git a/src/pages/chat/Conversation.vue b/src/pages/chat/Conversation.vue index 7ccca102..3bbc81f4 100644 --- a/src/pages/chat/Conversation.vue +++ b/src/pages/chat/Conversation.vue @@ -167,21 +167,21 @@ export default defineComponent({ async onStop() { if (this.canceler) { this.canceler.abort(); - this.answering = false; // 更新状态 + this.answering = false; } }, async onRestart(targetMessage: IChatMessage) { // 1. Clear the following message const targetIndex = this.messages.findIndex((message) => message === targetMessage); - const problem_message = this.messages[targetIndex - 1]; + const problemMessage = this.messages[targetIndex - 1]; // @ts-ignore - let update_messages = []; + let updatedMessages = []; if (targetIndex !== -1) { // @ts-ignore - update_messages = this.messages.slice(0, targetIndex - 1); + updatedMessages = this.messages.slice(0, targetIndex - 1); this.messages = this.messages.slice(0, targetIndex); // @ts-ignore - this.question = problem_message.content; + this.question = problemMessage.content; } // 2. Update the messages const token = this.credential?.token; @@ -205,7 +205,7 @@ export default defineComponent({ { id: this.conversationId, // @ts-ignore - messages: update_messages + messages: updatedMessages }, { token, @@ -417,10 +417,12 @@ export default defineComponent({ token, stream: (response: IChatConversationResponse) => { console.debug('stream response', response); + const lastMessage = this.messages[this.messages.length - 1]; this.messages[this.messages.length - 1] = { role: ROLE_ASSISTANT, content: response.answer, - state: IChatMessageState.ANSWERING + state: + lastMessage?.state !== IChatMessageState.FINISHED ? IChatMessageState.ANSWERING : lastMessage?.state }; conversationId = response?.id; this.onScrollDown(); @@ -431,6 +433,7 @@ export default defineComponent({ .then(async () => { console.debug('finished fetch answer', this.messages); this.messages[this.messages.length - 1].state = IChatMessageState.FINISHED; + console.debug('finished fetch answer', JSON.stringify(this.messages)); await this.$store.dispatch('chat/setConversation', { id: conversationId, messages: this.messages diff --git a/src/store/chat/state.ts b/src/store/chat/state.ts index f03b28ac..fd2a66e2 100644 --- a/src/store/chat/state.ts +++ b/src/store/chat/state.ts @@ -1,10 +1,10 @@ -import { CHAT_MODEL_GPT_3_5 } from '@/constants'; +import { CHAT_MODEL_GPT_4 } from '@/constants'; import { IChatState } from './models'; import { Status } from '@/models'; export default (): IChatState => { return { - model: CHAT_MODEL_GPT_3_5, + model: CHAT_MODEL_GPT_4, applications: undefined, application: undefined, conversations: undefined,