From 6901925396a78f548ba270e43f1582702c767ccf Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Thu, 10 Oct 2024 14:24:28 -0400 Subject: [PATCH] [Vertex AI] Switch to `firebasevertexai.googleapis.com` API (#13725) --- FirebaseVertexAI/CHANGELOG.md | 4 ++ FirebaseVertexAI/Sources/Constants.swift | 5 +- FirebaseVertexAI/Sources/Errors.swift | 16 ------ .../Sources/GenerativeAIRequest.swift | 4 +- .../Sources/GenerativeAIService.swift | 11 ---- .../Tests/Unit/GenerativeModelTests.swift | 50 ------------------- 6 files changed, 6 insertions(+), 84 deletions(-) diff --git a/FirebaseVertexAI/CHANGELOG.md b/FirebaseVertexAI/CHANGELOG.md index 04ae2573ecda..ad5e1b74f954 100644 --- a/FirebaseVertexAI/CHANGELOG.md +++ b/FirebaseVertexAI/CHANGELOG.md @@ -1,4 +1,8 @@ # 11.4.0 +- [changed] **Breaking Change**: The SDK is now Generally Available (GA); both + new and existing users must perform the + [Build with Gemini](https://console.firebase.google.com/project/_/genai/) + onboarding flow in the Firebase Console to use the updated API. (#13725) - [changed] **Breaking Change**: The `HarmCategory` enum is no longer nested inside the `SafetySetting` struct and the `unspecified` case has been removed. (#13686) diff --git a/FirebaseVertexAI/Sources/Constants.swift b/FirebaseVertexAI/Sources/Constants.swift index 9ec76aabe95f..587b1ad283c8 100644 --- a/FirebaseVertexAI/Sources/Constants.swift +++ b/FirebaseVertexAI/Sources/Constants.swift @@ -17,8 +17,5 @@ import Foundation /// Constants associated with the Vertex AI for Firebase SDK. enum Constants { /// The Vertex AI backend endpoint URL. - /// - /// TODO(andrewheard): Update to "https://firebasevertexai.googleapis.com" after the Vertex AI in - /// Firebase API launch. - static let baseURL = "https://firebaseml.googleapis.com" + static let baseURL = "https://firebasevertexai.googleapis.com" } diff --git a/FirebaseVertexAI/Sources/Errors.swift b/FirebaseVertexAI/Sources/Errors.swift index 57fbe826580c..770dc3b12d37 100644 --- a/FirebaseVertexAI/Sources/Errors.swift +++ b/FirebaseVertexAI/Sources/Errors.swift @@ -31,11 +31,6 @@ struct RPCError: Error { self.details = details } - // TODO(andrewheard): Remove this method after the Vertex AI in Firebase API launch. - func isFirebaseMLServiceDisabledError() -> Bool { - return details.contains { $0.isFirebaseMLServiceDisabledErrorDetails() } - } - func isVertexAIInFirebaseServiceDisabledError() -> Bool { return details.contains { $0.isVertexAIInFirebaseServiceDisabledErrorDetails() } } @@ -95,17 +90,6 @@ struct ErrorDetails { return isErrorInfo() && reason == "SERVICE_DISABLED" && domain == "googleapis.com" } - // TODO(andrewheard): Remove this method after the Vertex AI in Firebase API launch. - func isFirebaseMLServiceDisabledErrorDetails() -> Bool { - guard isServiceDisabledError() else { - return false - } - guard let metadata, metadata["service"] == "firebaseml.googleapis.com" else { - return false - } - return true - } - func isVertexAIInFirebaseServiceDisabledErrorDetails() -> Bool { guard isServiceDisabledError() else { return false diff --git a/FirebaseVertexAI/Sources/GenerativeAIRequest.swift b/FirebaseVertexAI/Sources/GenerativeAIRequest.swift index 08ac22eaa5fa..ac9046e0de49 100644 --- a/FirebaseVertexAI/Sources/GenerativeAIRequest.swift +++ b/FirebaseVertexAI/Sources/GenerativeAIRequest.swift @@ -31,9 +31,7 @@ public struct RequestOptions { let timeout: TimeInterval /// The API version to use in requests to the backend. - /// - /// TODO(andrewheard): Update to "v1beta" after the Vertex AI in Firebase API launch. - let apiVersion = "v2beta" + let apiVersion = "v1beta" /// Initializes a request options object. /// diff --git a/FirebaseVertexAI/Sources/GenerativeAIService.swift b/FirebaseVertexAI/Sources/GenerativeAIService.swift index ac4291043526..ff49a17b07fd 100644 --- a/FirebaseVertexAI/Sources/GenerativeAIService.swift +++ b/FirebaseVertexAI/Sources/GenerativeAIService.swift @@ -263,17 +263,6 @@ struct GenerativeAIService { // Log specific RPC errors that cannot be mitigated or handled by user code. // These errors do not produce specific GenerateContentError or CountTokensError cases. private func logRPCError(_ error: RPCError) { - // TODO(andrewheard): Remove this check after the Vertex AI in Firebase API launch. - if error.isFirebaseMLServiceDisabledError() { - VertexLog.error(code: .vertexAIInFirebaseAPIDisabled, """ - The Vertex AI in Firebase SDK requires the Firebase ML API (`firebaseml.googleapis.com`) to \ - be enabled in your Firebase project. Enable this API by visiting the Firebase Console at - https://console.firebase.google.com/project/\(projectID)/genai/ and clicking "Get started". \ - If you enabled this API recently, wait a few minutes for the action to propagate to our \ - systems and then retry. - """) - } - if error.isVertexAIInFirebaseServiceDisabledError() { VertexLog.error(code: .vertexAIInFirebaseAPIDisabled, """ The Vertex AI in Firebase SDK requires the Vertex AI in Firebase API \ diff --git a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift index 5474a4675efd..de14552c251f 100644 --- a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift +++ b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift @@ -457,30 +457,6 @@ final class GenerativeModelTests: XCTestCase { } } - // TODO(andrewheard): Remove this test case after the Vertex AI in Firebase API launch. - func testGenerateContent_failure_firebaseMLAPINotEnabled() async throws { - let expectedStatusCode = 403 - MockURLProtocol - .requestHandler = try httpRequestHandler( - forResource: "unary-failure-firebaseml-api-not-enabled", - withExtension: "json", - statusCode: expectedStatusCode - ) - - do { - _ = try await model.generateContent(testPrompt) - XCTFail("Should throw GenerateContentError.internalError; no error thrown.") - } catch let GenerateContentError.internalError(error as RPCError) { - XCTAssertEqual(error.httpResponseCode, expectedStatusCode) - XCTAssertEqual(error.status, .permissionDenied) - XCTAssertTrue(error.message.starts(with: "Firebase ML API has not been used in project")) - XCTAssertTrue(error.isFirebaseMLServiceDisabledError()) - return - } catch { - XCTFail("Should throw GenerateContentError.internalError(RPCError); error thrown: \(error)") - } - } - func testGenerateContent_failure_firebaseVertexAIAPINotEnabled() async throws { let expectedStatusCode = 403 MockURLProtocol @@ -805,32 +781,6 @@ final class GenerativeModelTests: XCTestCase { XCTFail("Should have caught an error.") } - // TODO(andrewheard): Remove this test case after the Vertex AI in Firebase API launch. - func testGenerateContentStream_failure_firebaseMLAPINotEnabled() async throws { - let expectedStatusCode = 403 - MockURLProtocol - .requestHandler = try httpRequestHandler( - forResource: "unary-failure-firebaseml-api-not-enabled", - withExtension: "json", - statusCode: expectedStatusCode - ) - - do { - let stream = try model.generateContentStream(testPrompt) - for try await _ in stream { - XCTFail("No content is there, this shouldn't happen.") - } - } catch let GenerateContentError.internalError(error as RPCError) { - XCTAssertEqual(error.httpResponseCode, expectedStatusCode) - XCTAssertEqual(error.status, .permissionDenied) - XCTAssertTrue(error.message.starts(with: "Firebase ML API has not been used in project")) - XCTAssertTrue(error.isFirebaseMLServiceDisabledError()) - return - } - - XCTFail("Should have caught an error.") - } - func testGenerateContentStream_failure_vertexAIInFirebaseAPINotEnabled() async throws { let expectedStatusCode = 403 MockURLProtocol