Skip to content

Commit

Permalink
fix: abort not being sent
Browse files Browse the repository at this point in the history
  • Loading branch information
Vali-98 committed Dec 4, 2024
1 parent 9de9c76 commit 657947d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 1 addition & 4 deletions constants/API/APIBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ const readableStreamResponse = async (
const closeStream = () => {
Logger.debug('Running close stream')
Chats.useChat.getState().stopGenerating()
sse.abort()
}

useInference.getState().setAbort(async () => {
Logger.debug('Running abort')
closeStream()
sse.abort()
})

sse.setOnEvent((data) => {
Expand All @@ -107,10 +107,7 @@ const readableStreamResponse = async (
})

sse.setOnError(() => {
// if ('message' in event) {
Logger.log('Generation Failed', true)
// Logger.log(`An error occured : ${event?.message ?? ''}`)

closeStream()
})

Expand Down
1 change: 1 addition & 0 deletions constants/SSEFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class SSEFetch {
}).then(async (res) => {
if (res.status !== 200 || !res.body) return this.onError()
for await (const chunk of res.body) {
if (this.abortController.signal.aborted) break
const data = this.decoder.decode(chunk)
const output = parseSSE(data)
output.forEach((item) => this.onEvent(item))
Expand Down

0 comments on commit 657947d

Please sign in to comment.