Merge pull request #1795 from cheahjs/fix/openai-handle-carriage-returns

fix: handle carriage returns in OpenAI streams
This commit is contained in:
Timothy Jaeryang Baek 2024-04-27 12:43:33 -07:00 committed by GitHub
commit db5c4be674
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -26,7 +26,11 @@ async function* openAIStreamToIterator(
break; break;
} }
const lines = value.split('\n'); const lines = value.split('\n');
for (const line of lines) { for (let line of lines) {
if (line.endsWith('\r')) {
// Remove trailing \r
line = line.slice(0, -1);
}
if (line !== '') { if (line !== '') {
console.log(line); console.log(line);
if (line === 'data: [DONE]') { if (line === 'data: [DONE]') {