fit chat stop (#117)
This commit is contained in:
1 parent
d3d46b5f2f
commit
31cd8921ef
7 files changed
+65
-7
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "patch",
|
||||||
|
"comment": "add chat stop",
|
||||||
|
"packageName": "@acedatacloud/nexior",
|
||||||
|
"email": "1348977728@qq.com",
|
||||||
|
"dependentChangeType": "patch"
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
<span
|
<span
|
||||||
|
v-show="!disabled"
|
||||||
:class="{
|
:class="{
|
||||||
btn: true,
|
btn: true,
|
||||||
'btn-send': true,
|
'btn-send': true,
|
||||||
@@ -32,6 +33,17 @@
|
|||||||
>
|
>
|
||||||
<font-awesome-icon icon="fa-solid fa-location-arrow" class="icon icon-send" />
|
<font-awesome-icon icon="fa-solid fa-location-arrow" class="icon icon-send" />
|
||||||
</span>
|
</span>
|
||||||
|
<span
|
||||||
|
v-show="disabled"
|
||||||
|
:class="{
|
||||||
|
btn: true,
|
||||||
|
'btn-stop': true,
|
||||||
|
disabled: !disabled
|
||||||
|
}"
|
||||||
|
@click="onStop"
|
||||||
|
>
|
||||||
|
<font-awesome-icon icon="fa-solid fa-stop-circle" class="icon icon-stop" />
|
||||||
|
</span>
|
||||||
<!-- add this textarea -->
|
<!-- add this textarea -->
|
||||||
<textarea
|
<textarea
|
||||||
ref="textarea"
|
ref="textarea"
|
||||||
@@ -80,7 +92,7 @@ export default defineComponent({
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['update:question', 'update:references', 'submit'],
|
emits: ['update:question', 'update:references', 'submit', 'stop'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
inputHeight: '35px', //add inputHeight
|
inputHeight: '35px', //add inputHeight
|
||||||
@@ -143,6 +155,9 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
this.$emit('submit');
|
this.$emit('submit');
|
||||||
},
|
},
|
||||||
|
onStop() {
|
||||||
|
this.$emit('stop');
|
||||||
|
},
|
||||||
onExceed() {
|
onExceed() {
|
||||||
ElMessage.warning(this.$t('chat.message.uploadReferencesExceed'));
|
ElMessage.warning(this.$t('chat.message.uploadReferencesExceed'));
|
||||||
},
|
},
|
||||||
@@ -246,6 +261,19 @@ textarea.input:focus {
|
|||||||
color: var(--el-text-color-primary);
|
color: var(--el-text-color-primary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
&.btn-stop {
|
||||||
|
right: 15px; // Adjust position if needed
|
||||||
|
&.disabled {
|
||||||
|
.icon-stop {
|
||||||
|
color: var(--el-text-color-disabled);
|
||||||
|
}
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
.icon-stop {
|
||||||
|
font-size: 16px;
|
||||||
|
color: var(--el-text-color-primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,14 +56,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="operations">
|
<div class="operations">
|
||||||
<copy-to-clipboard
|
<copy-to-clipboard
|
||||||
v-if="!Array.isArray(message.content) && message.state === messageState.FINISHED"
|
v-if="
|
||||||
|
!Array.isArray(message.content) &&
|
||||||
|
(message.state === messageState.FINISHED || message.state === messageState.FAILED)
|
||||||
|
"
|
||||||
:content="message.content!"
|
:content="message.content!"
|
||||||
class="btn-copy"
|
class="btn-copy"
|
||||||
/>
|
/>
|
||||||
<restart-to-generate
|
<restart-to-generate
|
||||||
v-if="
|
v-if="
|
||||||
!Array.isArray(message.content) &&
|
!Array.isArray(message.content) &&
|
||||||
message.state === messageState.FINISHED &&
|
(message.state === messageState.FINISHED || message.state === messageState.FAILED) &&
|
||||||
message.role === 'assistant' &&
|
message.role === 'assistant' &&
|
||||||
message === messages[messages.length - 1]
|
message === messages[messages.length - 1]
|
||||||
"
|
"
|
||||||
@@ -99,6 +102,7 @@ import {
|
|||||||
ERROR_CODE_TOO_MANY_REQUESTS,
|
ERROR_CODE_TOO_MANY_REQUESTS,
|
||||||
ERROR_CODE_UNKNOWN,
|
ERROR_CODE_UNKNOWN,
|
||||||
ERROR_CODE_USED_UP,
|
ERROR_CODE_USED_UP,
|
||||||
|
ERROR_CODE_CANCELED,
|
||||||
ROLE_ASSISTANT
|
ROLE_ASSISTANT
|
||||||
} from '@/constants';
|
} from '@/constants';
|
||||||
import { ROUTE_CONSOLE_APPLICATION_EXTRA } from '@/router';
|
import { ROUTE_CONSOLE_APPLICATION_EXTRA } from '@/router';
|
||||||
@@ -168,6 +172,8 @@ export default defineComponent({
|
|||||||
return this.$t('chat.message.errorContentTooLarge');
|
return this.$t('chat.message.errorContentTooLarge');
|
||||||
case ERROR_CODE_NOT_APPLIED:
|
case ERROR_CODE_NOT_APPLIED:
|
||||||
return this.$t('chat.message.errorNotApplied');
|
return this.$t('chat.message.errorNotApplied');
|
||||||
|
case ERROR_CODE_CANCELED:
|
||||||
|
return undefined; // 不显示错误框
|
||||||
case ERROR_CODE_UNKNOWN:
|
case ERROR_CODE_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
return this.$t('chat.message.errorUnknown');
|
return this.$t('chat.message.errorUnknown');
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export interface IChatConversation {
|
|||||||
export interface IChatConversationOptions {
|
export interface IChatConversationOptions {
|
||||||
stream?: (response: IChatConversationResponse) => void;
|
stream?: (response: IChatConversationResponse) => void;
|
||||||
token: string;
|
token: string;
|
||||||
|
signal?: AbortController['signal'];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IChatConversationRequest {
|
export interface IChatConversationRequest {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class ChatOperator {
|
|||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
},
|
},
|
||||||
baseURL: BASE_URL_API,
|
baseURL: BASE_URL_API,
|
||||||
|
signal: options.signal,
|
||||||
responseType: 'stream',
|
responseType: 'stream',
|
||||||
onDownloadProgress: ({ event }: AxiosProgressEvent) => {
|
onDownloadProgress: ({ event }: AxiosProgressEvent) => {
|
||||||
const response = event.target.response;
|
const response = event.target.response;
|
||||||
@@ -134,7 +135,8 @@ class ChatOperator {
|
|||||||
authorization: `Bearer ${options.token}`,
|
authorization: `Bearer ${options.token}`,
|
||||||
'x-record-exempt': 'true'
|
'x-record-exempt': 'true'
|
||||||
},
|
},
|
||||||
baseURL: BASE_URL_API
|
baseURL: BASE_URL_API,
|
||||||
|
signal: options.signal
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
@update:question="question = $event"
|
@update:question="question = $event"
|
||||||
@update:references="references = $event"
|
@update:references="references = $event"
|
||||||
@submit="onSubmit"
|
@submit="onSubmit"
|
||||||
|
@stop="onStop"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -64,6 +65,7 @@ export interface IData {
|
|||||||
references: string[];
|
references: string[];
|
||||||
answering: boolean;
|
answering: boolean;
|
||||||
messages: IChatMessage[];
|
messages: IChatMessage[];
|
||||||
|
canceler: AbortController | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -82,6 +84,7 @@ export default defineComponent({
|
|||||||
question: '',
|
question: '',
|
||||||
references: [],
|
references: [],
|
||||||
answering: false,
|
answering: false,
|
||||||
|
canceler: undefined,
|
||||||
messages:
|
messages:
|
||||||
this.$store.state.chat.conversations?.find(
|
this.$store.state.chat.conversations?.find(
|
||||||
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
|
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
|
||||||
@@ -161,6 +164,12 @@ export default defineComponent({
|
|||||||
this.question = question;
|
this.question = question;
|
||||||
this.onSubmit();
|
this.onSubmit();
|
||||||
},
|
},
|
||||||
|
async onStop() {
|
||||||
|
if (this.canceler) {
|
||||||
|
this.canceler.abort();
|
||||||
|
this.answering = false; // 更新状态
|
||||||
|
}
|
||||||
|
},
|
||||||
async onRestart(targetMessage: IChatMessage) {
|
async onRestart(targetMessage: IChatMessage) {
|
||||||
// 1. Clear the following message
|
// 1. Clear the following message
|
||||||
const targetIndex = this.messages.findIndex((message) => message === targetMessage);
|
const targetIndex = this.messages.findIndex((message) => message === targetMessage);
|
||||||
@@ -190,6 +199,7 @@ export default defineComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let conversationId = this.conversationId;
|
let conversationId = this.conversationId;
|
||||||
|
this.canceler = new AbortController();
|
||||||
chatOperator
|
chatOperator
|
||||||
.updateConversation(
|
.updateConversation(
|
||||||
{
|
{
|
||||||
@@ -198,7 +208,8 @@ export default defineComponent({
|
|||||||
messages: update_messages
|
messages: update_messages
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
token
|
token,
|
||||||
|
signal: this.canceler.signal
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
@@ -392,6 +403,7 @@ export default defineComponent({
|
|||||||
this.onScrollDown();
|
this.onScrollDown();
|
||||||
// request server to get answer
|
// request server to get answer
|
||||||
this.answering = true;
|
this.answering = true;
|
||||||
|
this.canceler = new AbortController();
|
||||||
chatOperator
|
chatOperator
|
||||||
.chatConversation(
|
.chatConversation(
|
||||||
{
|
{
|
||||||
@@ -412,7 +424,8 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
conversationId = response?.id;
|
conversationId = response?.id;
|
||||||
this.onScrollDown();
|
this.onScrollDown();
|
||||||
}
|
},
|
||||||
|
signal: this.canceler.signal
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
@@ -422,7 +435,6 @@ export default defineComponent({
|
|||||||
id: conversationId,
|
id: conversationId,
|
||||||
messages: this.messages
|
messages: this.messages
|
||||||
});
|
});
|
||||||
console.log('messages', JSON.stringify(this.messages));
|
|
||||||
this.answering = false;
|
this.answering = false;
|
||||||
if (!this.conversationId) {
|
if (!this.conversationId) {
|
||||||
await this.$router.push({
|
await this.$router.push({
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
} from '@fortawesome/free-regular-svg-icons';
|
} from '@fortawesome/free-regular-svg-icons';
|
||||||
import { faDiscord as faBrandsDiscord, faWeixin as faBrandsWeixin } from '@fortawesome/free-brands-svg-icons';
|
import { faDiscord as faBrandsDiscord, faWeixin as faBrandsWeixin } from '@fortawesome/free-brands-svg-icons';
|
||||||
import {
|
import {
|
||||||
|
faStopCircle as faSolidStopCircle,
|
||||||
faPlayCircle as faSolidPlayCircle,
|
faPlayCircle as faSolidPlayCircle,
|
||||||
faDownload as faSolidDownload,
|
faDownload as faSolidDownload,
|
||||||
faFilm as faSolidFilm,
|
faFilm as faSolidFilm,
|
||||||
@@ -76,6 +77,7 @@ import {
|
|||||||
faAngleDown as faSolidAngleDown
|
faAngleDown as faSolidAngleDown
|
||||||
} from '@fortawesome/free-solid-svg-icons';
|
} from '@fortawesome/free-solid-svg-icons';
|
||||||
// add icons
|
// add icons
|
||||||
|
library.add(faSolidStopCircle);
|
||||||
library.add(faSolidPlayCircle);
|
library.add(faSolidPlayCircle);
|
||||||
library.add(faSolidFilm);
|
library.add(faSolidFilm);
|
||||||
library.add(faSolidMusic);
|
library.add(faSolidMusic);
|
||||||
|
|||||||
Reference in new issue
Block a user