【增加】增加发送 stream 中可以进行取消

This commit is contained in:
cherishsince 2024-05-13 17:49:18 +08:00
parent c1b9baf8b6
commit b0de27a721

View File

@ -151,7 +151,12 @@
<textarea class="prompt-input" v-model="prompt" @keyup.enter="onSend" placeholder="问我任何问题...Shift+Enter 换行,按下 Enter 发送)"></textarea>
<div class="prompt-btns">
<el-switch/>
<el-button type="primary" size="default" @click="onSend()">发送</el-button>
<el-button type="primary" size="default" @click="onSend()" :loading="conversationInProgress" v-if="conversationInProgress == false">
{{ conversationInProgress ? '进行中' : '发送'}}
</el-button>
<el-button type="danger" size="default" @click="stopStream()" v-if="conversationInProgress == true">
停止
</el-button>
</div>
</form>
</el-footer>
@ -170,6 +175,8 @@ const { copy } = useClipboard();
const searchName = ref('') //
const conversationId = ref('1781604279872581648') // id
const conversationInProgress = ref<Boolean>() //
conversationInProgress.value = false
const conversationInAbortController = ref<any>() // abort ( stream )
const prompt = ref<string>() // prompt
@ -204,6 +211,10 @@ const searchConversation = () => {
/** send */
const onSend = async () => {
//
if (conversationInProgress.value) {
return
}
const content = prompt.value;
//
prompt.value = ''
@ -322,12 +333,19 @@ const onDelete = async (id) => {
message: '删除成功!',
type: 'success',
})
// tip stream message controller
stopStream()
// message
await messageList();
}
const stopStream = async () => {
// tip stream message controller
if (conversationInAbortController.value) {
conversationInAbortController.value.abort()
}
// message
await messageList();
// false
conversationInProgress.value = false
}
/** 初始化 **/