mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
fix cancel streaming
This commit is contained in:
parent
ce7ee62abe
commit
dce0378eb2
1 changed files with 8 additions and 7 deletions
|
|
@ -548,7 +548,8 @@ export const SidebarChat = () => {
|
||||||
|
|
||||||
// stream state
|
// stream state
|
||||||
const chatThreadsStreamState = useChatThreadsStreamState(chatThreadsState.currentThreadId)
|
const chatThreadsStreamState = useChatThreadsStreamState(chatThreadsState.currentThreadId)
|
||||||
const isCurrThreadStreaming = !!chatThreadsStreamState?.streamingToken
|
const streamingToken = chatThreadsStreamState?.streamingToken
|
||||||
|
const isStreaming = !!streamingToken
|
||||||
const latestError = chatThreadsStreamState?.error
|
const latestError = chatThreadsStreamState?.error
|
||||||
const messageSoFar = chatThreadsStreamState?.messageSoFar
|
const messageSoFar = chatThreadsStreamState?.messageSoFar
|
||||||
|
|
||||||
|
|
@ -569,7 +570,7 @@ export const SidebarChat = () => {
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
|
|
||||||
if (isDisabled) return
|
if (isDisabled) return
|
||||||
if (isCurrThreadStreaming) return
|
if (isStreaming) return
|
||||||
|
|
||||||
// send message to LLM
|
// send message to LLM
|
||||||
const userMessage = textAreaRef.current?.value ?? ''
|
const userMessage = textAreaRef.current?.value ?? ''
|
||||||
|
|
@ -582,9 +583,9 @@ export const SidebarChat = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const onAbort = () => {
|
const onAbort = () => {
|
||||||
const token = chatThreadsStreamState?.streamingToken
|
// this assumes an instant cancellation doesn't happen, since streamingToken state must have updated by this time
|
||||||
if (!token) return
|
if (!streamingToken) return
|
||||||
chatThreadsService.cancelStreaming(token)
|
chatThreadsService.cancelStreaming(streamingToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
// const [_test_messages, _set_test_messages] = useState<string[]>([])
|
// const [_test_messages, _set_test_messages] = useState<string[]>([])
|
||||||
|
|
@ -626,7 +627,7 @@ export const SidebarChat = () => {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* message stream */}
|
{/* message stream */}
|
||||||
<ChatBubble chatMessage={{ role: 'assistant', content: messageSoFar ?? '', displayContent: messageSoFar || null }} isLoading={isCurrThreadStreaming} />
|
<ChatBubble chatMessage={{ role: 'assistant', content: messageSoFar ?? '', displayContent: messageSoFar || null }} isLoading={isStreaming} />
|
||||||
|
|
||||||
</ScrollToBottomContainer>
|
</ScrollToBottomContainer>
|
||||||
|
|
||||||
|
|
@ -700,7 +701,7 @@ export const SidebarChat = () => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* submit / stop button */}
|
{/* submit / stop button */}
|
||||||
{isCurrThreadStreaming ?
|
{isStreaming ?
|
||||||
// stop button
|
// stop button
|
||||||
<ButtonStop
|
<ButtonStop
|
||||||
onClick={onAbort}
|
onClick={onAbort}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue