From 2e71451e730eff3e5ebbc7f32bb746a509e7992c Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Thu, 4 Apr 2024 14:44:56 -0400 Subject: [PATCH] Remove `location` from Vertex AI public API --- .../ViewModels/ConversationViewModel.swift | 2 +- .../ViewModels/PhotoReasoningViewModel.swift | 3 +-- .../ViewModels/SummarizeViewModel.swift | 2 +- FirebaseVertexAI/Sources/VertexAI.swift | 16 ++++------------ .../Tests/Unit/VertexAIAPITests.swift | 4 ++-- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/FirebaseVertexAI/Sample/ChatSample/ViewModels/ConversationViewModel.swift b/FirebaseVertexAI/Sample/ChatSample/ViewModels/ConversationViewModel.swift index 883cefb359f..a7c3d21a960 100644 --- a/FirebaseVertexAI/Sample/ChatSample/ViewModels/ConversationViewModel.swift +++ b/FirebaseVertexAI/Sample/ChatSample/ViewModels/ConversationViewModel.swift @@ -36,7 +36,7 @@ class ConversationViewModel: ObservableObject { private var chatTask: Task? init() { - model = VertexAI.vertexAI(location: "us-central1").generativeModel(modelName: "gemini-1.0-pro") + model = VertexAI.vertexAI().generativeModel(modelName: "gemini-1.0-pro") chat = model.startChat() } diff --git a/FirebaseVertexAI/Sample/GenerativeAIMultimodalSample/ViewModels/PhotoReasoningViewModel.swift b/FirebaseVertexAI/Sample/GenerativeAIMultimodalSample/ViewModels/PhotoReasoningViewModel.swift index bfa1cfa9028..b27d518fe86 100644 --- a/FirebaseVertexAI/Sample/GenerativeAIMultimodalSample/ViewModels/PhotoReasoningViewModel.swift +++ b/FirebaseVertexAI/Sample/GenerativeAIMultimodalSample/ViewModels/PhotoReasoningViewModel.swift @@ -44,8 +44,7 @@ class PhotoReasoningViewModel: ObservableObject { private var model: GenerativeModel? init() { - let vertexAI = VertexAI.vertexAI(location: "us-central1") - model = vertexAI.generativeModel(modelName: "gemini-1.0-pro-vision") + model = VertexAI.vertexAI().generativeModel(modelName: "gemini-1.0-pro-vision") } func reason() async { diff --git a/FirebaseVertexAI/Sample/GenerativeAITextSample/ViewModels/SummarizeViewModel.swift b/FirebaseVertexAI/Sample/GenerativeAITextSample/ViewModels/SummarizeViewModel.swift index a90e1cf15b8..99b374efefa 100644 --- a/FirebaseVertexAI/Sample/GenerativeAITextSample/ViewModels/SummarizeViewModel.swift +++ b/FirebaseVertexAI/Sample/GenerativeAITextSample/ViewModels/SummarizeViewModel.swift @@ -32,7 +32,7 @@ class SummarizeViewModel: ObservableObject { private var model: GenerativeModel? init() { - model = VertexAI.vertexAI(location: "us-central1").generativeModel(modelName: "gemini-1.0-pro") + model = VertexAI.vertexAI().generativeModel(modelName: "gemini-1.0-pro") } func summarize(inputText: String) async { diff --git a/FirebaseVertexAI/Sources/VertexAI.swift b/FirebaseVertexAI/Sources/VertexAI.swift index 3e5f5e67050..1fcfd998b45 100644 --- a/FirebaseVertexAI/Sources/VertexAI.swift +++ b/FirebaseVertexAI/Sources/VertexAI.swift @@ -25,35 +25,27 @@ public class VertexAI: NSObject { /// The default `VertexAI` instance. /// - /// - Parameter location: The region identifier, e.g., `us-central1`; see - /// [Vertex AI - /// regions](https://cloud.google.com/vertex-ai/docs/general/locations#vertex-ai-regions) - /// for a list of supported regions. /// - Returns: An instance of `VertexAI`, configured with the default `FirebaseApp`. - public static func vertexAI(location: String) -> VertexAI { + public static func vertexAI() -> VertexAI { guard let app = FirebaseApp.app() else { fatalError("No instance of the default Firebase app was found.") } - return vertexAI(app: app, location: location) + return vertexAI(app: app) } /// Creates an instance of `VertexAI` configured with a custom `FirebaseApp`. /// /// - Parameters: /// - app: The custom `FirebaseApp` used for initialization. - /// - location: The region identifier, e.g., `us-central1`; see - /// [Vertex AI - /// regions](https://cloud.google.com/vertex-ai/docs/general/locations#vertex-ai-regions) - /// for a list of supported regions. /// - Returns: A `VertexAI` instance, configured with the custom `FirebaseApp`. - public static func vertexAI(app: FirebaseApp, location: String) -> VertexAI { + public static func vertexAI(app: FirebaseApp) -> VertexAI { guard let provider = ComponentType.instance(for: VertexAIProvider.self, in: app.container) else { fatalError("No \(VertexAIProvider.self) instance found for Firebase app: \(app.name)") } - return provider.vertexAI(location) + return provider.vertexAI("us-central1") } /// Initializes a generative model with the given parameters. diff --git a/FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift b/FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift index 80236f405de..81b81414dcb 100644 --- a/FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift +++ b/FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift @@ -34,10 +34,10 @@ final class VertexAIAPITests: XCTestCase { let filters = [SafetySetting(harmCategory: .dangerousContent, threshold: .blockOnlyHigh)] // Instantiate Vertex AI SDK - Default App - let vertexAI = VertexAI.vertexAI(location: "my-location") + let vertexAI = VertexAI.vertexAI() // Instantiate Vertex AI SDK - Custom App - let _ = VertexAI.vertexAI(app: app!, location: "my-location") + let _ = VertexAI.vertexAI(app: app!) // Permutations without optional arguments.