Skip to content

Commit 6059bbb

Browse files
authored
[Vertex AI] Switch to firebasevertexai.googleapis.com API (#13725)
1 parent 02025ce commit 6059bbb

File tree

6 files changed

+6
-84
lines changed

6 files changed

+6
-84
lines changed

FirebaseVertexAI/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# 11.4.0
2+
- [changed] **Breaking Change**: The SDK is now Generally Available (GA); both
3+
new and existing users must perform the
4+
[Build with Gemini](https://console.firebase.google.com/project/_/genai/)
5+
onboarding flow in the Firebase Console to use the updated API. (#13725)
26
- [changed] **Breaking Change**: The `HarmCategory` enum is no longer nested
37
inside the `SafetySetting` struct and the `unspecified` case has been
48
removed. (#13686)

FirebaseVertexAI/Sources/Constants.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,5 @@ import Foundation
1717
/// Constants associated with the Vertex AI for Firebase SDK.
1818
enum Constants {
1919
/// The Vertex AI backend endpoint URL.
20-
///
21-
/// TODO(andrewheard): Update to "https://firebasevertexai.googleapis.com" after the Vertex AI in
22-
/// Firebase API launch.
23-
static let baseURL = "https://firebaseml.googleapis.com"
20+
static let baseURL = "https://firebasevertexai.googleapis.com"
2421
}

FirebaseVertexAI/Sources/Errors.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ struct RPCError: Error {
3131
self.details = details
3232
}
3333

34-
// TODO(andrewheard): Remove this method after the Vertex AI in Firebase API launch.
35-
func isFirebaseMLServiceDisabledError() -> Bool {
36-
return details.contains { $0.isFirebaseMLServiceDisabledErrorDetails() }
37-
}
38-
3934
func isVertexAIInFirebaseServiceDisabledError() -> Bool {
4035
return details.contains { $0.isVertexAIInFirebaseServiceDisabledErrorDetails() }
4136
}
@@ -95,17 +90,6 @@ struct ErrorDetails {
9590
return isErrorInfo() && reason == "SERVICE_DISABLED" && domain == "googleapis.com"
9691
}
9792

98-
// TODO(andrewheard): Remove this method after the Vertex AI in Firebase API launch.
99-
func isFirebaseMLServiceDisabledErrorDetails() -> Bool {
100-
guard isServiceDisabledError() else {
101-
return false
102-
}
103-
guard let metadata, metadata["service"] == "firebaseml.googleapis.com" else {
104-
return false
105-
}
106-
return true
107-
}
108-
10993
func isVertexAIInFirebaseServiceDisabledErrorDetails() -> Bool {
11094
guard isServiceDisabledError() else {
11195
return false

FirebaseVertexAI/Sources/GenerativeAIRequest.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public struct RequestOptions {
3131
let timeout: TimeInterval
3232

3333
/// The API version to use in requests to the backend.
34-
///
35-
/// TODO(andrewheard): Update to "v1beta" after the Vertex AI in Firebase API launch.
36-
let apiVersion = "v2beta"
34+
let apiVersion = "v1beta"
3735

3836
/// Initializes a request options object.
3937
///

FirebaseVertexAI/Sources/GenerativeAIService.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,6 @@ struct GenerativeAIService {
263263
// Log specific RPC errors that cannot be mitigated or handled by user code.
264264
// These errors do not produce specific GenerateContentError or CountTokensError cases.
265265
private func logRPCError(_ error: RPCError) {
266-
// TODO(andrewheard): Remove this check after the Vertex AI in Firebase API launch.
267-
if error.isFirebaseMLServiceDisabledError() {
268-
VertexLog.error(code: .vertexAIInFirebaseAPIDisabled, """
269-
The Vertex AI in Firebase SDK requires the Firebase ML API (`firebaseml.googleapis.com`) to \
270-
be enabled in your Firebase project. Enable this API by visiting the Firebase Console at
271-
https://console.firebase.google.com/project/\(projectID)/genai/ and clicking "Get started". \
272-
If you enabled this API recently, wait a few minutes for the action to propagate to our \
273-
systems and then retry.
274-
""")
275-
}
276-
277266
if error.isVertexAIInFirebaseServiceDisabledError() {
278267
VertexLog.error(code: .vertexAIInFirebaseAPIDisabled, """
279268
The Vertex AI in Firebase SDK requires the Vertex AI in Firebase API \

FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -457,30 +457,6 @@ final class GenerativeModelTests: XCTestCase {
457457
}
458458
}
459459

460-
// TODO(andrewheard): Remove this test case after the Vertex AI in Firebase API launch.
461-
func testGenerateContent_failure_firebaseMLAPINotEnabled() async throws {
462-
let expectedStatusCode = 403
463-
MockURLProtocol
464-
.requestHandler = try httpRequestHandler(
465-
forResource: "unary-failure-firebaseml-api-not-enabled",
466-
withExtension: "json",
467-
statusCode: expectedStatusCode
468-
)
469-
470-
do {
471-
_ = try await model.generateContent(testPrompt)
472-
XCTFail("Should throw GenerateContentError.internalError; no error thrown.")
473-
} catch let GenerateContentError.internalError(error as RPCError) {
474-
XCTAssertEqual(error.httpResponseCode, expectedStatusCode)
475-
XCTAssertEqual(error.status, .permissionDenied)
476-
XCTAssertTrue(error.message.starts(with: "Firebase ML API has not been used in project"))
477-
XCTAssertTrue(error.isFirebaseMLServiceDisabledError())
478-
return
479-
} catch {
480-
XCTFail("Should throw GenerateContentError.internalError(RPCError); error thrown: \(error)")
481-
}
482-
}
483-
484460
func testGenerateContent_failure_firebaseVertexAIAPINotEnabled() async throws {
485461
let expectedStatusCode = 403
486462
MockURLProtocol
@@ -805,32 +781,6 @@ final class GenerativeModelTests: XCTestCase {
805781
XCTFail("Should have caught an error.")
806782
}
807783

808-
// TODO(andrewheard): Remove this test case after the Vertex AI in Firebase API launch.
809-
func testGenerateContentStream_failure_firebaseMLAPINotEnabled() async throws {
810-
let expectedStatusCode = 403
811-
MockURLProtocol
812-
.requestHandler = try httpRequestHandler(
813-
forResource: "unary-failure-firebaseml-api-not-enabled",
814-
withExtension: "json",
815-
statusCode: expectedStatusCode
816-
)
817-
818-
do {
819-
let stream = try model.generateContentStream(testPrompt)
820-
for try await _ in stream {
821-
XCTFail("No content is there, this shouldn't happen.")
822-
}
823-
} catch let GenerateContentError.internalError(error as RPCError) {
824-
XCTAssertEqual(error.httpResponseCode, expectedStatusCode)
825-
XCTAssertEqual(error.status, .permissionDenied)
826-
XCTAssertTrue(error.message.starts(with: "Firebase ML API has not been used in project"))
827-
XCTAssertTrue(error.isFirebaseMLServiceDisabledError())
828-
return
829-
}
830-
831-
XCTFail("Should have caught an error.")
832-
}
833-
834784
func testGenerateContentStream_failure_vertexAIInFirebaseAPINotEnabled() async throws {
835785
let expectedStatusCode = 403
836786
MockURLProtocol

0 commit comments

Comments
 (0)