Skip to content

Commit

Permalink
Merge pull request #151 from oblank/main
Browse files Browse the repository at this point in the history
fix: fix json decode error when jsonContent is emtpy
  • Loading branch information
ingvarus-bc authored Feb 2, 2024
2 parents 497266a + c95da8e commit 38cda2a
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 38cda2a

Please sign in to comment.