Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ extension KeyedDecodingContainer {
try self.decode(TimeInterval.self, forKey: key, parsingOptions: parsingOptions, defaultValue: 0)
}

func decodeInt(forKey key: KeyedDecodingContainer<K>.Key, parsingOptions: ParsingOptions) throws -> Int {
try self.decode(Int.self, forKey: key, parsingOptions: parsingOptions, defaultValue: 0)
}

func decode<T: Decodable>(_ type: T.Type, forKey key: KeyedDecodingContainer<K>.Key, parsingOptions: ParsingOptions, defaultValue: T) throws -> T {
do {
return try decode(T.self, forKey: key)
Expand Down
11 changes: 10 additions & 1 deletion Sources/OpenAI/Public/Models/ChatStreamResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct ChatStreamResult: Codable, Equatable, Sendable {

public struct ChoiceDeltaToolCall: Codable, Equatable, Sendable {

public let index: Int?
public let index: Int
/// The ID of the tool call.
public let id: String?
/// The function that the model called.
Expand All @@ -89,6 +89,15 @@ public struct ChatStreamResult: Codable, Equatable, Sendable {
self.function = function
self.type = "function"
}

public init(from decoder: any Decoder) throws {
let container: KeyedDecodingContainer<ChoiceDeltaToolCall.CodingKeys> = try decoder.container(keyedBy: ChoiceDeltaToolCall.CodingKeys.self)
let parsingOptions = decoder.userInfo[.parsingOptions] as? ParsingOptions ?? []
self.index = try container.decodeInt(forKey: ChoiceDeltaToolCall.CodingKeys.index, parsingOptions: parsingOptions)
self.id = try container.decodeIfPresent(String.self, forKey: ChoiceDeltaToolCall.CodingKeys.id)
self.function = try container.decodeIfPresent(ChoiceDeltaToolCallFunction.self, forKey: ChoiceDeltaToolCall.CodingKeys.function)
self.type = try container.decodeIfPresent(String.self, forKey: ChoiceDeltaToolCall.CodingKeys.type)
}

public struct ChoiceDeltaToolCallFunction: Codable, Equatable, Sendable {

Expand Down