Skip to content

Commit 78c341f

Browse files
authored
[Vertex AI] Remove CountTokensError enum (#13736)
1 parent 4c9cc64 commit 78c341f

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

FirebaseVertexAI/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
- [changed] **Breaking Change**: The `ImageConversionError` enum is no longer
2626
public; image conversion errors are still reported as
2727
`GenerateContentError.promptImageContentError`. (#13735)
28+
- [changed] **Breaking Change**: The `CountTokensError` enum has been removed;
29+
errors occurring in `GenerativeModel.countTokens(...)` are now thrown directly
30+
instead of being wrapped in a `CountTokensError.internalError`. (#13736)
2831
- [changed] The default request timeout is now 180 seconds instead of the
2932
platform-default value of 60 seconds for a `URLRequest`; this timeout may
3033
still be customized in `RequestOptions`. (#13722)

FirebaseVertexAI/Sources/GenerativeModel.swift

+6-16
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,12 @@ public final class GenerativeModel {
269269
/// invalid.
270270
public func countTokens(_ content: @autoclosure () throws -> [ModelContent]) async throws
271271
-> CountTokensResponse {
272-
do {
273-
let countTokensRequest = try CountTokensRequest(
274-
model: modelResourceName,
275-
contents: content(),
276-
options: requestOptions
277-
)
278-
return try await generativeAIService.loadRequest(request: countTokensRequest)
279-
} catch {
280-
throw CountTokensError.internalError(underlying: error)
281-
}
272+
let countTokensRequest = try CountTokensRequest(
273+
model: modelResourceName,
274+
contents: content(),
275+
options: requestOptions
276+
)
277+
return try await generativeAIService.loadRequest(request: countTokensRequest)
282278
}
283279

284280
/// Returns a `GenerateContentError` (for public consumption) from an internal error.
@@ -291,9 +287,3 @@ public final class GenerativeModel {
291287
return GenerateContentError.internalError(underlying: error)
292288
}
293289
}
294-
295-
/// An error thrown in `GenerativeModel.countTokens(_:)`.
296-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
297-
public enum CountTokensError: Error {
298-
case internalError(underlying: Error)
299-
}

FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ final class GenerativeModelTests: XCTestCase {
12581258
do {
12591259
_ = try await model.countTokens("Why is the sky blue?")
12601260
XCTFail("Request should not have succeeded.")
1261-
} catch let CountTokensError.internalError(rpcError as RPCError) {
1261+
} catch let rpcError as RPCError {
12621262
XCTAssertEqual(rpcError.httpResponseCode, 404)
12631263
XCTAssertEqual(rpcError.status, .notFound)
12641264
XCTAssert(rpcError.message.hasPrefix("models/test-model-name is not found"))

0 commit comments

Comments
 (0)