fix(sendMessage): optimize message slicing logic
- prevents empty context when message ID isn't found in history array
This commit is contained in:
parent
4634c88f76
commit
85160c2d29
@ -334,14 +334,12 @@ export const sendMessage =
|
|||||||
// 节流
|
// 节流
|
||||||
const throttledDispatch = throttle(handleResponseMessageUpdate, 100, { trailing: true }) // 100ms的节流时间应足够平衡用户体验和性能
|
const throttledDispatch = throttle(handleResponseMessageUpdate, 100, { trailing: true }) // 100ms的节流时间应足够平衡用户体验和性能
|
||||||
|
|
||||||
|
const messageIndex = messages.findIndex((m) => m.id === assistantMessage.id)
|
||||||
await fetchChatCompletion({
|
await fetchChatCompletion({
|
||||||
message: { ...assistantMessage },
|
message: { ...assistantMessage },
|
||||||
messages: messages
|
messages: messages
|
||||||
.filter((m) => !m.status?.includes('ing'))
|
.filter((m) => !m.status?.includes('ing'))
|
||||||
.slice(
|
.slice(0, messageIndex !== -1 ? messageIndex : undefined),
|
||||||
0,
|
|
||||||
messages.findIndex((m) => m.id === assistantMessage.id)
|
|
||||||
),
|
|
||||||
assistant: assistantWithModel,
|
assistant: assistantWithModel,
|
||||||
onResponse: async (msg) => {
|
onResponse: async (msg) => {
|
||||||
// 允许在回调外维护一个最新的消息状态,每次都更新这个对象,但只通过节流函数分发到Redux
|
// 允许在回调外维护一个最新的消息状态,每次都更新这个对象,但只通过节流函数分发到Redux
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user