Skip to content

Commit

Permalink
Fix: prevent json decoding error when streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
neelvirdy committed Jan 31, 2024
1 parent 497266a commit 26cdd97
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/OpenAI/Private/StreamingSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 26cdd97

Please sign in to comment.