Skip to content
Merged
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
17 changes: 16 additions & 1 deletion FirebaseVertexAI/Sources/CountTokensRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,19 @@ extension CountTokensRequest: Encodable {
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension CountTokensResponse: Decodable {}
extension CountTokensResponse: Decodable {
enum CodingKeys: CodingKey {
case totalTokens
case totalBillableCharacters
case promptTokensDetails
}

public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
totalTokens = try container.decodeIfPresent(Int.self, forKey: .totalTokens) ?? 0
totalBillableCharacters =
try container.decodeIfPresent(Int.self, forKey: .totalBillableCharacters)
promptTokensDetails =
try container.decodeIfPresent([ModalityTokenCount].self, forKey: .promptTokensDetails) ?? []
}
}
16 changes: 8 additions & 8 deletions FirebaseVertexAI/Sources/GenerateContentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ extension GenerateContentResponse.UsageMetadata: Decodable {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
promptTokenCount = try container.decodeIfPresent(Int.self, forKey: .promptTokenCount) ?? 0
candidatesTokenCount = try container
.decodeIfPresent(Int.self, forKey: .candidatesTokenCount) ?? 0
candidatesTokenCount =
try container.decodeIfPresent(Int.self, forKey: .candidatesTokenCount) ?? 0
totalTokenCount = try container.decodeIfPresent(Int.self, forKey: .totalTokenCount) ?? 0
promptTokensDetails = try container
.decodeIfPresent([ModalityTokenCount].self, forKey: .promptTokensDetails) ??
[ModalityTokenCount]()
candidatesTokensDetails = try container
.decodeIfPresent([ModalityTokenCount].self, forKey: .candidatesTokensDetails) ??
[ModalityTokenCount]()
promptTokensDetails =
try container.decodeIfPresent([ModalityTokenCount].self, forKey: .promptTokensDetails) ?? []
candidatesTokensDetails = try container.decodeIfPresent(
[ModalityTokenCount].self,
forKey: .candidatesTokensDetails
) ?? []
}
}

Expand Down
Loading