Skip to content

Commit

Permalink
Fix regenete state (#130)
Browse files Browse the repository at this point in the history
Co-authored-by: AceDataCloud <office@acedata.cloud>
  • Loading branch information
Germey and AceDataCloud committed Aug 25, 2024
1 parent cfe3ad3 commit 6ee99e8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix chat responding state",
"packageName": "@acedatacloud/nexior",
"email": "office@acedata.cloud",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions src/components/chat/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export default defineComponent({
padding: 8px;
width: 100%;
max-width: 800px;
margin-bottom: 10px;
.image {
max-width: 100%;
max-height: 300px;
Expand All @@ -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;
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/pages/chat/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -205,7 +205,7 @@ export default defineComponent({
{
id: this.conversationId,
// @ts-ignore
messages: update_messages
messages: updatedMessages
},
{
token,
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/store/chat/state.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 6ee99e8

Please sign in to comment.