diff --git a/Sources/OpenAI/Private/StreamingSession.swift b/Sources/OpenAI/Private/StreamingSession.swift index a69e46cf..7b883d1f 100644 --- a/Sources/OpenAI/Private/StreamingSession.swift +++ b/Sources/OpenAI/Private/StreamingSession.swift @@ -59,9 +59,9 @@ extension StreamingSession { private func processJSON(from stringContent: String) { let jsonObjects = "\(previousChunkBuffer)\(stringContent)" .components(separatedBy: "data:") - .filter { $0.isEmpty == false } .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } - + .filter { $0.isEmpty == false } + previousChunkBuffer = "" guard jsonObjects.isEmpty == false, jsonObjects.first != streamingCompletionMarker else {