@@ -47,7 +47,6 @@ public final class FirebaseAI: Sendable {
47
47
useLimitedUseAppCheckTokens: Bool = false ) -> FirebaseAI {
48
48
let instance = createInstance (
49
49
app: app,
50
- location: backend. location,
51
50
apiConfig: backend. apiConfig,
52
51
useLimitedUseAppCheckTokens: useLimitedUseAppCheckTokens
53
52
)
@@ -188,21 +187,19 @@ public final class FirebaseAI: Sendable {
188
187
189
188
let apiConfig : APIConfig
190
189
191
- /// A map of active `FirebaseAI` instances keyed by the `FirebaseApp` name and the `location`,
192
- /// in the format `appName:location`.
190
+ /// A map of active `FirebaseAI` instances keyed by the `FirebaseApp`, the `APIConfig`, and `useLimitedUseAppCheckTokens`.
193
191
private nonisolated ( unsafe) static var instances : [ InstanceKey : FirebaseAI ] = [ : ]
194
192
195
193
/// Lock to manage access to the `instances` array to avoid race conditions.
196
194
private nonisolated ( unsafe) static var instancesLock : os_unfair_lock = . init( )
197
195
198
- let location : String ?
199
-
200
196
static let defaultVertexAIAPIConfig = APIConfig (
201
197
service: . vertexAI( endpoint: . firebaseProxyProd) ,
202
- version: . v1beta
198
+ version: . v1beta,
199
+ location: " us-central1 "
203
200
)
204
201
205
- static func createInstance( app: FirebaseApp ? , location : String ? ,
202
+ static func createInstance( app: FirebaseApp ? ,
206
203
apiConfig: APIConfig ,
207
204
useLimitedUseAppCheckTokens: Bool ) -> FirebaseAI {
208
205
guard let app = app ?? FirebaseApp . app ( ) else {
@@ -216,7 +213,6 @@ public final class FirebaseAI: Sendable {
216
213
217
214
let instanceKey = InstanceKey (
218
215
appName: app. name,
219
- location: location,
220
216
apiConfig: apiConfig,
221
217
useLimitedUseAppCheckTokens: useLimitedUseAppCheckTokens
222
218
)
@@ -225,15 +221,14 @@ public final class FirebaseAI: Sendable {
225
221
}
226
222
let newInstance = FirebaseAI (
227
223
app: app,
228
- location: location,
229
224
apiConfig: apiConfig,
230
225
useLimitedUseAppCheckTokens: useLimitedUseAppCheckTokens
231
226
)
232
227
instances [ instanceKey] = newInstance
233
228
return newInstance
234
229
}
235
230
236
- init ( app: FirebaseApp , location : String ? , apiConfig: APIConfig ,
231
+ init ( app: FirebaseApp , apiConfig: APIConfig ,
237
232
useLimitedUseAppCheckTokens: Bool ) {
238
233
guard let projectID = app. options. projectID else {
239
234
fatalError ( " The Firebase app named \" \( app. name) \" has no project ID in its configuration. " )
@@ -254,7 +249,6 @@ public final class FirebaseAI: Sendable {
254
249
useLimitedUseAppCheckTokens: useLimitedUseAppCheckTokens
255
250
)
256
251
self . apiConfig = apiConfig
257
- self . location = location
258
252
}
259
253
260
254
func modelResourceName( modelName: String ) -> String {
@@ -276,7 +270,7 @@ public final class FirebaseAI: Sendable {
276
270
}
277
271
278
272
private func vertexAIModelResourceName( modelName: String ) -> String {
279
- guard let location else {
273
+ guard let location = apiConfig . location else {
280
274
fatalError ( " Location must be specified for the Firebase AI service. " )
281
275
}
282
276
guard !location. isEmpty && location
@@ -307,7 +301,6 @@ public final class FirebaseAI: Sendable {
307
301
/// This type is `Hashable` so that it can be used as a key in the `instances` dictionary.
308
302
private struct InstanceKey : Sendable , Hashable {
309
303
let appName : String
310
- let location : String ?
311
304
let apiConfig : APIConfig
312
305
let useLimitedUseAppCheckTokens : Bool
313
306
}
0 commit comments