This commit is contained in:
Timothy Jaeryang Baek
2024-12-12 23:31:08 -08:00
parent 9a081c8593
commit f9a05dd1e1
6 changed files with 190 additions and 144 deletions
+21 -1
View File
@@ -77,10 +77,14 @@ async function* openAIStreamToIterator(
continue;
}
if (parsedData.usage) {
yield { done: false, value: '', usage: parsedData.usage };
continue;
}
yield {
done: false,
value: parsedData.choices?.[0]?.delta?.content ?? '',
usage: parsedData.usage
};
} catch (e) {
console.error('Error extracting delta from SSE event:', e);
@@ -98,10 +102,26 @@ async function* streamLargeDeltasAsRandomChunks(
yield textStreamUpdate;
return;
}
if (textStreamUpdate.error) {
yield textStreamUpdate;
continue;
}
if (textStreamUpdate.sources) {
yield textStreamUpdate;
continue;
}
if (textStreamUpdate.selectedModelId) {
yield textStreamUpdate;
continue;
}
if (textStreamUpdate.usage) {
yield textStreamUpdate;
continue;
}
let content = textStreamUpdate.value;
if (content.length < 5) {
yield { done: false, value: content };