Don't stream events if the API returned a 4xx code

This commit is contained in:
valadaptive
2023-12-07 11:02:39 -05:00
parent 5540c165cf
commit cdcd913805
4 changed files with 55 additions and 4 deletions

View File

@ -476,6 +476,12 @@ async function generateTextGenWithStreaming(generate_data, signal) {
method: 'POST',
signal: signal,
});
if (!response.ok) {
tryParseStreamingError(response, await response.body.text());
throw new Error(`Got response status ${response.status}`);
}
const eventStream = new EventSourceStream();
response.body.pipeThrough(eventStream);
const reader = eventStream.readable.getReader();