From c56598eed81bdc64f41301958426f80c457ca073 Mon Sep 17 00:00:00 2001 From: frogcjn Date: Fri, 26 Jan 2024 19:11:53 -0500 Subject: [PATCH] Update StreamingSession.swift stringContent may contain a prefix new line ("\n") before the first "data:" separator. --- Sources/OpenAI/Private/StreamingSession.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/OpenAI/Private/StreamingSession.swift b/Sources/OpenAI/Private/StreamingSession.swift index a69e46cf..c20768a1 100644 --- a/Sources/OpenAI/Private/StreamingSession.swift +++ b/Sources/OpenAI/Private/StreamingSession.swift @@ -57,7 +57,7 @@ final class StreamingSession: NSObject, Identifiable, URLSe extension StreamingSession { private func processJSON(from stringContent: String) { - let jsonObjects = "\(previousChunkBuffer)\(stringContent)" + let jsonObjects = "\(previousChunkBuffer)\(stringContent)".trimmingCharacters(in: .whitespacesAndNewlines) .components(separatedBy: "data:") .filter { $0.isEmpty == false } .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }