Skip to content

Commit

Permalink
fix: fix json decode error when jsonContent is emtpy
Browse files Browse the repository at this point in the history
  • Loading branch information
oBlank committed Jan 28, 2024
1 parent 497266a commit c95da8e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/OpenAI/Private/StreamingSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ final class StreamingSession<ResultType: Codable>: NSObject, Identifiable, URLSe
extension StreamingSession {

private func processJSON(from stringContent: String) {
if stringContent.isEmpty {
return
}
let jsonObjects = "\(previousChunkBuffer)\(stringContent)"
.components(separatedBy: "data:")
.filter { $0.isEmpty == false }
Expand All @@ -68,7 +71,7 @@ extension StreamingSession {
return
}
jsonObjects.enumerated().forEach { (index, jsonContent) in
guard jsonContent != streamingCompletionMarker else {
guard jsonContent != streamingCompletionMarker && !jsonContent.isEmpty else {
return
}
guard let jsonData = jsonContent.data(using: .utf8) else {
Expand Down

0 comments on commit c95da8e

Please sign in to comment.