Skip to content

Commit a2d8d5b

Browse files
committed
[Vertex AI] Switch to firebasevertexai.googleapis.com API
# Conflicts: # FirebaseVertexAI/Sources/GenerativeAIService.swift
1 parent 7107086 commit a2d8d5b

File tree

5 files changed

+2
-84
lines changed

5 files changed

+2
-84
lines changed

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
@@ -454,30 +454,6 @@ final class GenerativeModelTests: XCTestCase {
454454
}
455455
}
456456

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

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

0 commit comments

Comments
 (0)