【优化】AI 聊天卡顿问题

This commit is contained in:
cherishsince 2024-05-17 23:27:13 +08:00
parent d8dcc911b5
commit 959731609f

View File

@ -259,9 +259,6 @@ const doSend = async (content: string) => {
conversationId: activeConversationId.value,
content: content
} as ChatMessageVO
// list.value.push(userMessage)
//
// await scrollToBottom()
// stream
await doSendStream(userMessage)
}
@ -274,6 +271,21 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
//
fullText.value = ''
try {
// stream
list.value.push({
id: -1,
conversationId: activeConversationId.value,
type: 'user',
content: userMessage.content,
createTime: new Date()
} as ChatMessageVO)
list.value.push({
id: -2,
conversationId: activeConversationId.value,
type: 'system',
content: '思考中...',
createTime: new Date()
} as ChatMessageVO)
//
textRoll()
// event stream
@ -291,20 +303,20 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
conversationInProgress.value = false
// stream
conversationInAbortController.value.abort()
return
}
// message
if (isFirstMessage) {
isFirstMessage = false
// debugger
//
list.value.pop()
list.value.pop()
//
list.value.push(data.send)
list.value.push(data.receive)
} else {
}
// debugger
fullText.value = fullText.value + data.receive.content
// const lastMessage = list.value[list.value.length - 1]
// lastMessage.content = content
// list.value[list.value - 1] = lastMessage
}
//
await scrollToBottom()
},