Skip to content

Commit

Permalink
[Vertex AI] Re-added location parameter to public API (#12835)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed May 13, 2024
1 parent daf2900 commit 5e9a1b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions FirebaseVertexAI/Sources/VertexAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,33 @@ public class VertexAI: NSObject {

/// The default `VertexAI` instance.
///
/// - Parameter location: The region identifier, defaulting to `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() -> VertexAI {
public static func vertexAI(location: String = "us-central1") -> VertexAI {
guard let app = FirebaseApp.app() else {
fatalError("No instance of the default Firebase app was found.")
}

return vertexAI(app: app)
return vertexAI(app: app, location: location)
}

/// Creates an instance of `VertexAI` configured with a custom `FirebaseApp`.
///
/// - Parameters:
/// - app: The custom `FirebaseApp` used for initialization.
/// - location: The region identifier, defaulting to `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) -> VertexAI {
public static func vertexAI(app: FirebaseApp, location: String = "us-central1") -> 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("us-central1")
return provider.vertexAI(location)
}

/// Initializes a generative model with the given parameters.
Expand Down
2 changes: 2 additions & 0 deletions FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ final class VertexAIAPITests: XCTestCase {

// Instantiate Vertex AI SDK - Default App
let vertexAI = VertexAI.vertexAI()
let _ = VertexAI.vertexAI(location: "my-location")

// Instantiate Vertex AI SDK - Custom App
let _ = VertexAI.vertexAI(app: app!)
let _ = VertexAI.vertexAI(app: app!, location: "my-location")

// Permutations without optional arguments.

Expand Down

0 comments on commit 5e9a1b9

Please sign in to comment.