diff --git a/constants/API/APIBuilder.ts b/constants/API/APIBuilder.ts index 7bae548..0462579 100644 --- a/constants/API/APIBuilder.ts +++ b/constants/API/APIBuilder.ts @@ -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) => { @@ -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() }) diff --git a/constants/SSEFetch.ts b/constants/SSEFetch.ts index 08c7762..68b6247 100644 --- a/constants/SSEFetch.ts +++ b/constants/SSEFetch.ts @@ -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))