Bugfix
This commit is contained in:
+13
-12
@@ -89,22 +89,23 @@ export const OpenAIStream = async (
|
||||
const onParse = (event: ParsedEvent | ReconnectInterval) => {
|
||||
if (event.type === 'event') {
|
||||
const data = event.data;
|
||||
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
if (json.choices[0].finish_reason != null) {
|
||||
controller.close();
|
||||
return;
|
||||
if (data !== '[DONE]') {
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
if (json.choices[0].finish_reason != null || json.choices[0].finish_details != null) {
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
const text = json.choices[0].delta.content;
|
||||
const queue = encoder.encode(text);
|
||||
controller.enqueue(queue);
|
||||
} catch (e) {
|
||||
controller.error(e);
|
||||
}
|
||||
const text = json.choices[0].delta.content;
|
||||
const queue = encoder.encode(text);
|
||||
controller.enqueue(queue);
|
||||
} catch (e) {
|
||||
controller.error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const parser = createParser(onParse);
|
||||
|
||||
for await (const chunk of res.body as any) {
|
||||
|
||||
Reference in New Issue
Block a user