Skip to content

Commit c95da8e

Browse files
author
oBlank
committed
fix: fix json decode error when jsonContent is emtpy
1 parent 497266a commit c95da8e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sources/OpenAI/Private/StreamingSession.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ final class StreamingSession<ResultType: Codable>: NSObject, Identifiable, URLSe
5757
extension StreamingSession {
5858

5959
private func processJSON(from stringContent: String) {
60+
if stringContent.isEmpty {
61+
return
62+
}
6063
let jsonObjects = "\(previousChunkBuffer)\(stringContent)"
6164
.components(separatedBy: "data:")
6265
.filter { $0.isEmpty == false }
@@ -68,7 +71,7 @@ extension StreamingSession {
6871
return
6972
}
7073
jsonObjects.enumerated().forEach { (index, jsonContent) in
71-
guard jsonContent != streamingCompletionMarker else {
74+
guard jsonContent != streamingCompletionMarker && !jsonContent.isEmpty else {
7275
return
7376
}
7477
guard let jsonData = jsonContent.data(using: .utf8) else {

0 commit comments

Comments
 (0)