Skip to content

Commit b9c9265

Browse files
committed
Pass location through service
1 parent 147aa33 commit b9c9265

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

FirebaseAI/Sources/FirebaseAI.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ public final class FirebaseAI: Sendable {
195195
private nonisolated(unsafe) static var instancesLock: os_unfair_lock = .init()
196196

197197
static let defaultVertexAIAPIConfig = APIConfig(
198-
service: .vertexAI(endpoint: .firebaseProxyProd),
198+
service: .vertexAI(endpoint: .firebaseProxyProd, location: "us-central1"),
199199
version: .v1beta,
200-
location: "us-central1"
201200
)
202201

203202
static func createInstance(app: FirebaseApp?,
@@ -263,17 +262,14 @@ public final class FirebaseAI: Sendable {
263262
}
264263

265264
switch apiConfig.service {
266-
case .vertexAI:
267-
return vertexAIModelResourceName(modelName: modelName)
265+
case let .vertexAI(endpoint: _, location: location):
266+
return vertexAIModelResourceName(modelName: modelName, location: location)
268267
case .googleAI:
269268
return developerModelResourceName(modelName: modelName)
270269
}
271270
}
272271

273-
private func vertexAIModelResourceName(modelName: String) -> String {
274-
guard let location = apiConfig.location else {
275-
fatalError("Location must be specified for the Firebase AI service.")
276-
}
272+
private func vertexAIModelResourceName(modelName: String, location: String) -> String {
277273
guard !location.isEmpty && location
278274
.allSatisfy({ !$0.isWhitespace && !$0.isNewline && $0 != "/" }) else {
279275
fatalError("""

FirebaseAI/Sources/Types/Internal/APIConfig.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,15 @@ struct APIConfig: Sendable, Hashable, Encodable {
2222
/// The version of the selected API to use, e.g., "v1".
2323
let version: Version
2424

25-
/// The server location to use, e.g., "us-central1"
26-
let location: String?
27-
2825
/// Initializes an API configuration.
2926
///
3027
/// - Parameters:
3128
/// - service: The API service to use for generative AI.
3229
/// - version: The version of the API to use.
3330
/// - location: The server location to use.
34-
init(service: Service, version: Version, location: String?) {
31+
init(service: Service, version: Version) {
3532
self.service = service
3633
self.version = version
37-
self.location = location
3834
}
3935
}
4036

@@ -50,7 +46,7 @@ extension APIConfig {
5046
/// See the [Cloud
5147
/// docs](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference) for
5248
/// more details.
53-
case vertexAI(endpoint: Endpoint)
49+
case vertexAI(endpoint: Endpoint, location: String)
5450

5551
/// The Gemini Developer API provided by Google AI.
5652
///
@@ -62,7 +58,7 @@ extension APIConfig {
6258
/// This must correspond with the API set in `service`.
6359
var endpoint: Endpoint {
6460
switch self {
65-
case let .vertexAI(endpoint: endpoint):
61+
case let .vertexAI(endpoint: endpoint, location: _):
6662
return endpoint
6763
case let .googleAI(endpoint: endpoint):
6864
return endpoint

FirebaseAI/Sources/Types/Internal/Live/LiveSessionService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ actor LiveSessionService {
310310
private nonisolated func createWebsocket() async throws -> AsyncWebSocket {
311311
let host = apiConfig.service.endpoint.rawValue.withoutPrefix("https://")
312312
let urlString = switch apiConfig.service {
313-
case .vertexAI:
314-
"wss://\(host)/ws/google.firebase.vertexai.v1beta.LlmBidiService/BidiGenerateContent/locations/\(apiConfig.location ?? "us-central1")"
313+
case let .vertexAI(endpoint: _, location: location):
314+
"wss://\(host)/ws/google.firebase.vertexai.v1beta.LlmBidiService/BidiGenerateContent/locations/\(location)"
315315
case .googleAI:
316316
"wss://\(host)/ws/google.firebase.vertexai.v1beta.GenerativeService/BidiGenerateContent"
317317
}

FirebaseAI/Sources/Types/Public/Backend.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ public struct Backend {
2626
public static func vertexAI(location: String = "us-central1") -> Backend {
2727
return Backend(
2828
apiConfig: APIConfig(
29-
service: .vertexAI(endpoint: .firebaseProxyProd),
29+
service: .vertexAI(endpoint: .firebaseProxyProd, location: location),
3030
version: .v1beta,
31-
location: location
3231
)
3332
)
3433
}
@@ -39,7 +38,6 @@ public struct Backend {
3938
apiConfig: APIConfig(
4039
service: .googleAI(endpoint: .firebaseProxyProd),
4140
version: .v1beta,
42-
location: nil
4341
)
4442
)
4543
}

0 commit comments

Comments
 (0)