Преглед изворни кода

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

fix: handle carriage returns in OpenAI streams
Timothy Jaeryang Baek пре 1 година
родитељ
комит
db5c4be674
1 измењених фајлова са 5 додато и 1 уклоњено
  1. 5 1
      src/lib/apis/streaming/index.ts

+ 5 - 1
src/lib/apis/streaming/index.ts

@@ -26,7 +26,11 @@ async function* openAIStreamToIterator(
 			break;
 		}
 		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 !== '') {
 				console.log(line);
 				if (line === 'data: [DONE]') {