Skip to content

Commit 46fd2ac

Browse files
committed
Make OpenAI response/stream format less strict
1 parent 7e91a10 commit 46fd2ac

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Tool/Sources/OpenAIService/APIs/OpenAIChatCompletionsService.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ actor OpenAIChatCompletionsService: ChatCompletionsStreamAPI, ChatCompletionsAPI
134134

135135
struct Choice: Codable, Equatable {
136136
var message: Message
137-
var index: Int
138-
var finish_reason: String
137+
var index: Int?
138+
var finish_reason: String?
139139
}
140140

141141
struct Usage: Codable, Equatable {
142-
var prompt_tokens: Int
143-
var completion_tokens: Int
144-
var total_tokens: Int
142+
var prompt_tokens: Int?
143+
var completion_tokens: Int?
144+
var total_tokens: Int?
145145
}
146146

147147
var id: String?
@@ -287,7 +287,7 @@ actor OpenAIChatCompletionsService: ChatCompletionsStreamAPI, ChatCompletionsAPI
287287
return .init(chunk: chunk, done: false)
288288
} catch {
289289
Logger.service.error("Error decoding stream data: \(error)")
290-
throw error
290+
return .init(chunk: nil, done: false)
291291
}
292292
}
293293

0 commit comments

Comments
 (0)