Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vertex AI] Remove CountTokensError enum #13736

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
is now optional (`Int?`); it may be `null` in cases such as when a
`GenerateContentRequest` contains only images or other non-text content.
(#13721)
- [changed] **Breaking Change**: The `CountTokensError` enum has been removed;
errors occurring in `GenerativeModel.countTokens(...)` are now thrown directly
instead of being wrapped in a `CountTokensError.internalError`. (#13736)
- [changed] The default request timeout is now 180 seconds instead of the
platform-default value of 60 seconds for a `URLRequest`; this timeout may
still be customized in `RequestOptions`. (#13722)
Expand Down
22 changes: 6 additions & 16 deletions FirebaseVertexAI/Sources/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,12 @@ public final class GenerativeModel {
/// invalid.
public func countTokens(_ content: @autoclosure () throws -> [ModelContent]) async throws
-> CountTokensResponse {
do {
let countTokensRequest = try CountTokensRequest(
model: modelResourceName,
contents: content(),
options: requestOptions
)
return try await generativeAIService.loadRequest(request: countTokensRequest)
} catch {
throw CountTokensError.internalError(underlying: error)
}
let countTokensRequest = try CountTokensRequest(
model: modelResourceName,
contents: content(),
options: requestOptions
)
return try await generativeAIService.loadRequest(request: countTokensRequest)
}

/// Returns a `GenerateContentError` (for public consumption) from an internal error.
Expand All @@ -291,9 +287,3 @@ public final class GenerativeModel {
return GenerateContentError.internalError(underlying: error)
}
}

/// An error thrown in `GenerativeModel.countTokens(_:)`.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public enum CountTokensError: Error {
case internalError(underlying: Error)
}
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ final class GenerativeModelTests: XCTestCase {
do {
_ = try await model.countTokens("Why is the sky blue?")
XCTFail("Request should not have succeeded.")
} catch let CountTokensError.internalError(rpcError as RPCError) {
} catch let rpcError as RPCError {
XCTAssertEqual(rpcError.httpResponseCode, 404)
XCTAssertEqual(rpcError.status, .notFound)
XCTAssert(rpcError.message.hasPrefix("models/test-model-name is not found"))
Expand Down
Loading