Fix regenete state (#130)

Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
GermeyandAceDataCloud authored and GitHub committed 2024-08-25 12:20:17 +08:00
1 parent cfe3ad3f7b
commit 6ee99e8c23
4 files changed
+21 -11

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix chat responding state",
"packageName": "@acedatacloud/nexior",
"email": "office@acedata.cloud",
"dependentChangeType": "patch"
}
+2 -2
View File
@@ -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;
}
}
+10 -7
View File
@@ -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
+2 -2
View File
@@ -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,