diff --git a/change/@acedatacloud-nexior-5c49200e-bbf8-47cd-bf15-0dae2df64510.json b/change/@acedatacloud-nexior-5c49200e-bbf8-47cd-bf15-0dae2df64510.json new file mode 100644 index 00000000..127ec614 --- /dev/null +++ b/change/@acedatacloud-nexior-5c49200e-bbf8-47cd-bf15-0dae2df64510.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "add chat stop", + "packageName": "@acedatacloud/nexior", + "email": "1348977728@qq.com", + "dependentChangeType": "patch" +} diff --git a/src/components/chat/InputBox.vue b/src/components/chat/InputBox.vue index c44ee842..395b3d0d 100644 --- a/src/components/chat/InputBox.vue +++ b/src/components/chat/InputBox.vue @@ -23,6 +23,7 @@ + + + void; token: string; + signal?: AbortController['signal']; } export interface IChatConversationRequest { diff --git a/src/operators/chat.ts b/src/operators/chat.ts index 38eef563..9819932f 100644 --- a/src/operators/chat.ts +++ b/src/operators/chat.ts @@ -21,6 +21,7 @@ class ChatOperator { 'content-type': 'application/json' }, baseURL: BASE_URL_API, + signal: options.signal, responseType: 'stream', onDownloadProgress: ({ event }: AxiosProgressEvent) => { const response = event.target.response; @@ -134,7 +135,8 @@ class ChatOperator { authorization: `Bearer ${options.token}`, 'x-record-exempt': 'true' }, - baseURL: BASE_URL_API + baseURL: BASE_URL_API, + signal: options.signal } ); } diff --git a/src/pages/chat/Conversation.vue b/src/pages/chat/Conversation.vue index 7da2766b..7ccca102 100644 --- a/src/pages/chat/Conversation.vue +++ b/src/pages/chat/Conversation.vue @@ -35,6 +35,7 @@ @update:question="question = $event" @update:references="references = $event" @submit="onSubmit" + @stop="onStop" /> @@ -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({ diff --git a/src/plugins/font-awesome.ts b/src/plugins/font-awesome.ts index f2b9b288..5cd45374 100644 --- a/src/plugins/font-awesome.ts +++ b/src/plugins/font-awesome.ts @@ -10,6 +10,7 @@ import { } from '@fortawesome/free-regular-svg-icons'; import { faDiscord as faBrandsDiscord, faWeixin as faBrandsWeixin } from '@fortawesome/free-brands-svg-icons'; import { + faStopCircle as faSolidStopCircle, faPlayCircle as faSolidPlayCircle, faDownload as faSolidDownload, faFilm as faSolidFilm, @@ -76,6 +77,7 @@ import { faAngleDown as faSolidAngleDown } from '@fortawesome/free-solid-svg-icons'; // add icons +library.add(faSolidStopCircle); library.add(faSolidPlayCircle); library.add(faSolidFilm); library.add(faSolidMusic);