From a02d1e244499ab74c2e7a11f698902a802380ba2 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Wed, 25 Sep 2024 12:49:05 -0400 Subject: [PATCH 1/3] [Vertex AI] Make `CountTokensResponse.totalBillableCharacters` optional --- FirebaseVertexAI/CHANGELOG.md | 3 +++ .../Sources/CountTokensRequest.swift | 18 ++---------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/FirebaseVertexAI/CHANGELOG.md b/FirebaseVertexAI/CHANGELOG.md index 9950b1c0190..63282e03a56 100644 --- a/FirebaseVertexAI/CHANGELOG.md +++ b/FirebaseVertexAI/CHANGELOG.md @@ -18,6 +18,9 @@ accepts an array of *optional* parameters instead of a list of *required* parameters; if a parameter is not listed as optional it is assumed to be required. (#13616) +- [changed] **Breaking Change**: `CountTokensResponse.totalBillableCharacters` + is now optional (`Int?`); it may be `null` in cases such as when a + `GenerateContentRequest` contains only images or other non-text content. # 11.3.0 - [added] Added `Decodable` conformance for `FunctionResponse`. (#13606) diff --git a/FirebaseVertexAI/Sources/CountTokensRequest.swift b/FirebaseVertexAI/Sources/CountTokensRequest.swift index feddf9b2a05..6b052da19e6 100644 --- a/FirebaseVertexAI/Sources/CountTokensRequest.swift +++ b/FirebaseVertexAI/Sources/CountTokensRequest.swift @@ -40,7 +40,7 @@ public struct CountTokensResponse { /// /// > Important: This does not include billable image, video or other non-text input. See /// [Vertex AI pricing](https://cloud.google.com/vertex-ai/generative-ai/pricing) for details. - public let totalBillableCharacters: Int + public let totalBillableCharacters: Int? } // MARK: - Codable Conformances @@ -53,18 +53,4 @@ extension CountTokensRequest: Encodable { } @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) -extension CountTokensResponse: Decodable { - enum CodingKeys: CodingKey { - case totalTokens - case totalBillableCharacters - } - - public init(from decoder: any Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - totalTokens = try container.decode(Int.self, forKey: .totalTokens) - totalBillableCharacters = try container.decodeIfPresent( - Int.self, - forKey: .totalBillableCharacters - ) ?? 0 - } -} +extension CountTokensResponse: Decodable {} From de2af36a77cc38b8e39e0a864b43236be43ea87b Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Wed, 25 Sep 2024 12:59:42 -0400 Subject: [PATCH 2/3] Fixed test --- FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift index 5b30a56039c..c7cfe36df70 100644 --- a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift +++ b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift @@ -1194,7 +1194,7 @@ final class GenerativeModelTests: XCTestCase { )) XCTAssertEqual(response.totalTokens, 258) - XCTAssertEqual(response.totalBillableCharacters, 0) + XCTAssertNil(response.totalBillableCharacters) } func testCountTokens_modelNotFound() async throws { From dde45984f686607d64134733d3609d2be095a7b7 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Wed, 25 Sep 2024 14:17:55 -0400 Subject: [PATCH 3/3] Add CHANGELOG PR# --- FirebaseVertexAI/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/FirebaseVertexAI/CHANGELOG.md b/FirebaseVertexAI/CHANGELOG.md index 63282e03a56..f3d471969c3 100644 --- a/FirebaseVertexAI/CHANGELOG.md +++ b/FirebaseVertexAI/CHANGELOG.md @@ -21,6 +21,7 @@ - [changed] **Breaking Change**: `CountTokensResponse.totalBillableCharacters` is now optional (`Int?`); it may be `null` in cases such as when a `GenerateContentRequest` contains only images or other non-text content. + (#13721) # 11.3.0 - [added] Added `Decodable` conformance for `FunctionResponse`. (#13606)