Skip to content

Commit e63270e

Browse files
committed
Rename the Vertex AI parameter region to location (#12656)
1 parent c9536b8 commit e63270e

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

FirebaseVertexAI/Sample/ChatSample/ViewModels/ConversationViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ConversationViewModel: ObservableObject {
3636
private var chatTask: Task<Void, Never>?
3737

3838
init() {
39-
model = VertexAI.vertexAI(region: "us-central1").generativeModel(modelName: "gemini-1.0-pro")
39+
model = VertexAI.vertexAI(location: "us-central1").generativeModel(modelName: "gemini-1.0-pro")
4040
chat = model.startChat()
4141
}
4242

FirebaseVertexAI/Sample/GenerativeAIMultimodalSample/ViewModels/PhotoReasoningViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class PhotoReasoningViewModel: ObservableObject {
4444
private var model: GenerativeModel?
4545

4646
init() {
47-
let vertexAI = VertexAI.vertexAI(region: "us-central1")
47+
let vertexAI = VertexAI.vertexAI(location: "us-central1")
4848
model = vertexAI.generativeModel(modelName: "gemini-1.0-pro-vision")
4949
}
5050

FirebaseVertexAI/Sample/GenerativeAITextSample/ViewModels/SummarizeViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SummarizeViewModel: ObservableObject {
3232
private var model: GenerativeModel?
3333

3434
init() {
35-
model = VertexAI.vertexAI(region: "us-central1").generativeModel(modelName: "gemini-1.0-pro")
35+
model = VertexAI.vertexAI(location: "us-central1").generativeModel(modelName: "gemini-1.0-pro")
3636
}
3737

3838
func summarize(inputText: String) async {

FirebaseVertexAI/Sources/VertexAI.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,35 @@ public class VertexAI: NSObject {
2525

2626
/// The default `VertexAI` instance.
2727
///
28-
/// - Parameter region: The region identifier, e.g., `us-central1`; see
28+
/// - Parameter location: The region identifier, e.g., `us-central1`; see
2929
/// [Vertex AI
3030
/// regions](https://cloud.google.com/vertex-ai/docs/general/locations#vertex-ai-regions)
3131
/// for a list of supported regions.
3232
/// - Returns: An instance of `VertexAI`, configured with the default `FirebaseApp`.
33-
public static func vertexAI(region: String) -> VertexAI {
33+
public static func vertexAI(location: String) -> VertexAI {
3434
guard let app = FirebaseApp.app() else {
3535
fatalError("No instance of the default Firebase app was found.")
3636
}
3737

38-
return vertexAI(app: app, region: region)
38+
return vertexAI(app: app, location: location)
3939
}
4040

4141
/// Creates an instance of `VertexAI` configured with a custom `FirebaseApp`.
4242
///
4343
/// - Parameters:
4444
/// - app: The custom `FirebaseApp` used for initialization.
45-
/// - region: The region identifier, e.g., `us-central1`; see
45+
/// - location: The region identifier, e.g., `us-central1`; see
4646
/// [Vertex AI
4747
/// regions](https://cloud.google.com/vertex-ai/docs/general/locations#vertex-ai-regions)
4848
/// for a list of supported regions.
4949
/// - Returns: A `VertexAI` instance, configured with the custom `FirebaseApp`.
50-
public static func vertexAI(app: FirebaseApp, region: String) -> VertexAI {
50+
public static func vertexAI(app: FirebaseApp, location: String) -> VertexAI {
5151
guard let provider = ComponentType<VertexAIProvider>.instance(for: VertexAIProvider.self,
5252
in: app.container) else {
5353
fatalError("No \(VertexAIProvider.self) instance found for Firebase app: \(app.name)")
5454
}
5555

56-
return provider.vertexAI(region)
56+
return provider.vertexAI(location)
5757
}
5858

5959
/// Initializes a generative model with the given parameters.
@@ -73,7 +73,7 @@ public class VertexAI: NSObject {
7373
tools: [Tool]? = nil,
7474
requestOptions: RequestOptions = RequestOptions())
7575
-> GenerativeModel {
76-
let modelResourceName = modelResourceName(modelName: modelName, region: region)
76+
let modelResourceName = modelResourceName(modelName: modelName, location: location)
7777

7878
guard let apiKey = app.options.apiKey else {
7979
fatalError("The Firebase app named \"\(app.name)\" has no API key in its configuration.")
@@ -97,29 +97,29 @@ public class VertexAI: NSObject {
9797

9898
private let appCheck: AppCheckInterop?
9999

100-
let region: String
100+
let location: String
101101

102-
init(app: FirebaseApp, region: String) {
102+
init(app: FirebaseApp, location: String) {
103103
self.app = app
104-
self.region = region
104+
self.location = location
105105
appCheck = ComponentType<AppCheckInterop>.instance(for: AppCheckInterop.self, in: app.container)
106106
}
107107

108-
private func modelResourceName(modelName: String, region: String) -> String {
108+
private func modelResourceName(modelName: String, location: String) -> String {
109109
if modelName.contains("/") {
110110
return modelName
111111
}
112112
guard let projectID = app.options.projectID else {
113113
fatalError("The Firebase app named \"\(app.name)\" has no project ID in its configuration.")
114114
}
115-
guard !region.isEmpty else {
115+
guard !location.isEmpty else {
116116
fatalError("""
117-
No region specified; see
117+
No location specified; see
118118
https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions for a
119119
list of available regions.
120120
""")
121121
}
122122

123-
return "projects/\(projectID)/locations/\(region)/publishers/google/models/\(modelName)"
123+
return "projects/\(projectID)/locations/\(location)/publishers/google/models/\(modelName)"
124124
}
125125
}

FirebaseVertexAI/Sources/VertexAIComponent.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Foundation
2222
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
2323
@objc(FIRVertexAIProvider)
2424
protocol VertexAIProvider {
25-
@objc func vertexAI(_ region: String) -> VertexAI
25+
@objc func vertexAI(_ location: String) -> VertexAI
2626
}
2727

2828
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@@ -64,17 +64,17 @@ class VertexAIComponent: NSObject, Library, VertexAIProvider {
6464

6565
// MARK: - VertexAIProvider conformance
6666

67-
func vertexAI(_ region: String) -> VertexAI {
67+
func vertexAI(_ location: String) -> VertexAI {
6868
os_unfair_lock_lock(&instancesLock)
6969

7070
// Unlock before the function returns.
7171
defer { os_unfair_lock_unlock(&instancesLock) }
7272

73-
if let instance = instances[region] {
73+
if let instance = instances[location] {
7474
return instance
7575
}
76-
let newInstance = VertexAI(app: app, region: region)
77-
instances[region] = newInstance
76+
let newInstance = VertexAI(app: app, location: location)
77+
instances[location] = newInstance
7878
return newInstance
7979
}
8080
}

FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ final class VertexAIAPITests: XCTestCase {
3434
let filters = [SafetySetting(harmCategory: .dangerousContent, threshold: .blockOnlyHigh)]
3535

3636
// Instantiate Vertex AI SDK - Default App
37-
let vertexAI = VertexAI.vertexAI(region: "my-region")
37+
let vertexAI = VertexAI.vertexAI(location: "my-location")
3838

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

4242
// Permutations without optional arguments.
4343

FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class VertexComponentTests: XCTestCase {
4848
func testVertexInstanceCreation() throws {
4949
let app = try XCTUnwrap(VertexComponentTests.app)
5050
let component = VertexAIComponent(app: app)
51-
let vertex = component.vertexAI("my-region")
51+
let vertex = component.vertexAI("my-location")
5252
XCTAssertNotNil(vertex)
5353
}
5454

@@ -82,14 +82,14 @@ class VertexComponentTests: XCTestCase {
8282
in: container)
8383
XCTAssertNotNil(provider)
8484

85-
let vertex1 = provider?.vertexAI("randomRegion")
86-
let vertex2 = provider?.vertexAI("randomRegion")
85+
let vertex1 = provider?.vertexAI("randomLocation")
86+
let vertex2 = provider?.vertexAI("randomLocation")
8787
XCTAssertNotNil(vertex1)
8888

8989
// Ensure they're the same instance.
9090
XCTAssert(vertex1 === vertex2)
9191

92-
let vertex3 = provider?.vertexAI("differentRegion")
92+
let vertex3 = provider?.vertexAI("differentLocation")
9393
XCTAssertNotNil(vertex3)
9494

9595
XCTAssert(vertex1 !== vertex3)
@@ -105,7 +105,7 @@ class VertexComponentTests: XCTestCase {
105105
options.projectID = "myProjectID"
106106
let app1 = FirebaseApp(instanceWithName: "transitory app", options: options)
107107
weakApp = try XCTUnwrap(app1)
108-
let vertex = VertexAI(app: app1, region: "transitory region")
108+
let vertex = VertexAI(app: app1, location: "transitory location")
109109
weakVertex = vertex
110110
XCTAssertNotNil(weakVertex)
111111
}

0 commit comments

Comments
 (0)