Skip to content

Commit

Permalink
Remove location from Vertex AI public API
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed Apr 4, 2024
1 parent 7b85605 commit 2e71451
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ConversationViewModel: ObservableObject {
private var chatTask: Task<Void, Never>?

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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 4 additions & 12 deletions FirebaseVertexAI/Sources/VertexAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<VertexAIProvider>.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.
Expand Down
4 changes: 2 additions & 2 deletions FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 2e71451

Please sign in to comment.