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