Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
95973160
authored
May 17, 2024
by
cherishsince
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【优化】AI 聊天卡顿问题
parent
d8dcc911
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
9 deletions
+21
-9
src/views/ai/chat/index.vue
+21
-9
No files found.
src/views/ai/chat/index.vue
View file @
95973160
...
@@ -259,9 +259,6 @@ const doSend = async (content: string) => {
...
@@ -259,9 +259,6 @@ const doSend = async (content: string) => {
conversationId
:
activeConversationId
.
value
,
conversationId
:
activeConversationId
.
value
,
content
:
content
content
:
content
}
as
ChatMessageVO
}
as
ChatMessageVO
// list.value.push(userMessage)
// 滚动到住下面
// await scrollToBottom()
// stream
// stream
await
doSendStream
(
userMessage
)
await
doSendStream
(
userMessage
)
}
}
...
@@ -274,6 +271,21 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
...
@@ -274,6 +271,21 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
// 设置为空
// 设置为空
fullText
.
value
=
''
fullText
.
value
=
''
try
{
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
()
textRoll
()
// 发送 event stream
// 发送 event stream
...
@@ -291,20 +303,20 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
...
@@ -291,20 +303,20 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
conversationInProgress
.
value
=
false
conversationInProgress
.
value
=
false
// 结束 stream 对话
// 结束 stream 对话
conversationInAbortController
.
value
.
abort
()
conversationInAbortController
.
value
.
abort
()
return
}
}
// 首次返回需要添加一个 message 到页面,后面的都是更新
// 首次返回需要添加一个 message 到页面,后面的都是更新
if
(
isFirstMessage
)
{
if
(
isFirstMessage
)
{
isFirstMessage
=
false
isFirstMessage
=
false
// debugger
// 弹出两个 假数据
list
.
value
.
pop
()
list
.
value
.
pop
()
// 更新返回的数据
list
.
value
.
push
(
data
.
send
)
list
.
value
.
push
(
data
.
send
)
list
.
value
.
push
(
data
.
receive
)
list
.
value
.
push
(
data
.
receive
)
}
else
{
}
// debugger
// debugger
fullText
.
value
=
fullText
.
value
+
data
.
receive
.
content
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
()
await
scrollToBottom
()
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment