fit chat stop (#117)

This commit is contained in:
HCode authored and GitHub committed 2024-08-17 23:07:34 +08:00
1 parent d3d46b5f2f
commit 31cd8921ef
7 files changed
+65 -7

No files matched your search

+15 -3
View File
@@ -35,6 +35,7 @@
@update:question="question = $event"
@update:references="references = $event"
@submit="onSubmit"
@stop="onStop"
/>
</div>
</template>
@@ -64,6 +65,7 @@ export interface IData {
references: string[];
answering: boolean;
messages: IChatMessage[];
canceler: AbortController | undefined;
}
export default defineComponent({
@@ -82,6 +84,7 @@ export default defineComponent({
question: '',
references: [],
answering: false,
canceler: undefined,
messages:
this.$store.state.chat.conversations?.find(
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
@@ -161,6 +164,12 @@ export default defineComponent({
this.question = question;
this.onSubmit();
},
async onStop() {
if (this.canceler) {
this.canceler.abort();
this.answering = false; // 更新状态
}
},
async onRestart(targetMessage: IChatMessage) {
// 1. Clear the following message
const targetIndex = this.messages.findIndex((message) => message === targetMessage);
@@ -190,6 +199,7 @@ export default defineComponent({
return;
}
let conversationId = this.conversationId;
this.canceler = new AbortController();
chatOperator
.updateConversation(
{
@@ -198,7 +208,8 @@ export default defineComponent({
messages: update_messages
},
{
token
token,
signal: this.canceler.signal
}
)
.then(async () => {
@@ -392,6 +403,7 @@ export default defineComponent({
this.onScrollDown();
// request server to get answer
this.answering = true;
this.canceler = new AbortController();
chatOperator
.chatConversation(
{
@@ -412,7 +424,8 @@ export default defineComponent({
};
conversationId = response?.id;
this.onScrollDown();
}
},
signal: this.canceler.signal
}
)
.then(async () => {
@@ -422,7 +435,6 @@ export default defineComponent({
id: conversationId,
messages: this.messages
});
console.log('messages', JSON.stringify(this.messages));
this.answering = false;
if (!this.conversationId) {
await this.$router.push({