Skip to content

Commit e8b141a

Browse files
committed
[Firebase AI] Rename module to FirebaseAILogic
1 parent a623ed1 commit e8b141a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+195
-136
lines changed

FirebaseAI/Sources/Constants.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ enum Constants {
1919
/// The base reverse-DNS name for `NSError` or `CustomNSError` error domains.
2020
///
2121
/// - Important: A suffix must be appended to produce an error domain (e.g.,
22-
/// "com.google.firebase.firebaseai.ExampleError").
23-
static let baseErrorDomain = "com.google.firebase.firebaseai"
22+
/// "com.google.firebase.ai-logic.ExampleError").
23+
static let baseErrorDomain = "com.google.firebase.ai-logic"
2424
}

FirebaseAI/Sources/FirebaseAI.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ internal import FirebaseCoreExtension
2222

2323
/// The Firebase AI SDK provides access to Gemini models directly from your app.
2424
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
25-
public final class FirebaseAI: Sendable {
25+
public final class AILogic: Sendable {
2626
// MARK: - Public APIs
2727

28-
/// Creates an instance of `FirebaseAI`.
28+
/// Creates an instance of `AILogic`.
2929
///
3030
/// - Parameters:
3131
/// - app: A custom `FirebaseApp` used for initialization; if not specified, uses the default
@@ -41,17 +41,16 @@ public final class FirebaseAI: Sendable {
4141
/// _This flag is set to `false` by default._
4242
/// > Migrating to limited-use tokens sooner minimizes disruption when support for replay
4343
/// > protection is added.
44-
/// - Returns: A `FirebaseAI` instance, configured with the custom `FirebaseApp`.
45-
public static func firebaseAI(app: FirebaseApp? = nil,
46-
backend: Backend = .googleAI(),
47-
useLimitedUseAppCheckTokens: Bool = false) -> FirebaseAI {
44+
/// - Returns: An `AILogic` instance, configured with the custom `FirebaseApp`.
45+
public static func aiLogic(app: FirebaseApp? = nil, backend: Backend = .googleAI(),
46+
useLimitedUseAppCheckTokens: Bool = false) -> AILogic {
4847
let instance = createInstance(
4948
app: app,
5049
location: backend.location,
5150
apiConfig: backend.apiConfig,
5251
useLimitedUseAppCheckTokens: useLimitedUseAppCheckTokens
5352
)
54-
// Verify that the `FirebaseAI` instance is always configured with the production endpoint since
53+
// Verify that the `AILogic` instance is always configured with the production endpoint since
5554
// this is the public API surface for creating an instance.
5655
assert(instance.apiConfig.service.endpoint == .firebaseProxyProd)
5756
assert(instance.apiConfig.version == .v1beta)
@@ -152,9 +151,9 @@ public final class FirebaseAI: Sendable {
152151

153152
let apiConfig: APIConfig
154153

155-
/// A map of active `FirebaseAI` instances keyed by the `FirebaseApp` name and the `location`,
154+
/// A map of active `AILogic` instances keyed by the `FirebaseApp` name and the `location`,
156155
/// in the format `appName:location`.
157-
private nonisolated(unsafe) static var instances: [InstanceKey: FirebaseAI] = [:]
156+
private nonisolated(unsafe) static var instances: [InstanceKey: AILogic] = [:]
158157

159158
/// Lock to manage access to the `instances` array to avoid race conditions.
160159
private nonisolated(unsafe) static var instancesLock: os_unfair_lock = .init()
@@ -168,7 +167,7 @@ public final class FirebaseAI: Sendable {
168167

169168
static func createInstance(app: FirebaseApp?, location: String?,
170169
apiConfig: APIConfig,
171-
useLimitedUseAppCheckTokens: Bool) -> FirebaseAI {
170+
useLimitedUseAppCheckTokens: Bool) -> AILogic {
172171
guard let app = app ?? FirebaseApp.app() else {
173172
fatalError("No instance of the default Firebase app was found.")
174173
}
@@ -187,7 +186,7 @@ public final class FirebaseAI: Sendable {
187186
if let instance = instances[instanceKey] {
188187
return instance
189188
}
190-
let newInstance = FirebaseAI(
189+
let newInstance = AILogic(
191190
app: app,
192191
location: location,
193192
apiConfig: apiConfig,
@@ -266,7 +265,7 @@ public final class FirebaseAI: Sendable {
266265
}
267266
}
268267

269-
/// Identifier for a unique instance of ``FirebaseAI``.
268+
/// Identifier for a unique instance of ``AILogic``.
270269
///
271270
/// This type is `Hashable` so that it can be used as a key in the `instances` dictionary.
272271
private struct InstanceKey: Sendable, Hashable {

FirebaseAI/Tests/TestApp/Tests/Integration/CountTokensIntegrationTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import FirebaseAI
15+
import FirebaseAILogic
1616
import FirebaseAITestApp
1717
import FirebaseAuth
1818
import FirebaseCore
1919
import FirebaseStorage
2020
import Testing
2121

22-
@testable import struct FirebaseAI.APIConfig
22+
@testable import struct FirebaseAILogic.APIConfig
2323

2424
@Suite(.serialized)
2525
struct CountTokensIntegrationTests {
@@ -48,7 +48,7 @@ struct CountTokensIntegrationTests {
4848
@Test(arguments: InstanceConfig.allConfigs)
4949
func countTokens_text(_ config: InstanceConfig) async throws {
5050
let prompt = "Why is the sky blue?"
51-
let model = FirebaseAI.componentInstance(config).generativeModel(
51+
let model = AILogic.componentInstance(config).generativeModel(
5252
modelName: ModelNames.gemini2Flash,
5353
generationConfig: generationConfig,
5454
safetySettings: safetySettings
@@ -65,7 +65,7 @@ struct CountTokensIntegrationTests {
6565

6666
@Test(arguments: InstanceConfig.allConfigs)
6767
func countTokens_text_systemInstruction(_ config: InstanceConfig) async throws {
68-
let model = FirebaseAI.componentInstance(config).generativeModel(
68+
let model = AILogic.componentInstance(config).generativeModel(
6969
modelName: ModelNames.gemini2Flash,
7070
generationConfig: generationConfig,
7171
safetySettings: safetySettings,
@@ -83,7 +83,7 @@ struct CountTokensIntegrationTests {
8383

8484
@Test(arguments: InstanceConfig.allConfigs)
8585
func countTokens_jsonSchema(_ config: InstanceConfig) async throws {
86-
let model = FirebaseAI.componentInstance(config).generativeModel(
86+
let model = AILogic.componentInstance(config).generativeModel(
8787
modelName: ModelNames.gemini2Flash,
8888
generationConfig: GenerationConfig(
8989
responseMIMEType: "application/json",

FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import FirebaseAI
15+
import FirebaseAILogic
1616
import FirebaseAITestApp
1717
import FirebaseAuth
1818
import FirebaseCore
@@ -23,7 +23,7 @@ import Testing
2323
import UIKit
2424
#endif // canImport(UIKit)
2525

26-
@testable import struct FirebaseAI.BackendError
26+
@testable import struct FirebaseAILogic.BackendError
2727

2828
@Suite(.serialized)
2929
struct GenerateContentIntegrationTests {
@@ -64,7 +64,7 @@ struct GenerateContentIntegrationTests {
6464
// (InstanceConfig.googleAI_v1beta_freeTier_bypassProxy, ModelNames.gemma3_4B),
6565
])
6666
func generateContent(_ config: InstanceConfig, modelName: String) async throws {
67-
let model = FirebaseAI.componentInstance(config).generativeModel(
67+
let model = AILogic.componentInstance(config).generativeModel(
6868
modelName: modelName,
6969
generationConfig: generationConfig,
7070
safetySettings: safetySettings,
@@ -105,7 +105,7 @@ struct GenerateContentIntegrationTests {
105105
arguments: InstanceConfig.allConfigs
106106
)
107107
func generateContentEnum(_ config: InstanceConfig) async throws {
108-
let model = FirebaseAI.componentInstance(config).generativeModel(
108+
let model = AILogic.componentInstance(config).generativeModel(
109109
modelName: ModelNames.gemini2FlashLite,
110110
generationConfig: GenerationConfig(
111111
responseMIMEType: "text/x.enum",
@@ -184,7 +184,7 @@ struct GenerateContentIntegrationTests {
184184
)
185185
func generateContentThinking(_ config: InstanceConfig, modelName: String,
186186
thinkingConfig: ThinkingConfig) async throws {
187-
let model = FirebaseAI.componentInstance(config).generativeModel(
187+
let model = AILogic.componentInstance(config).generativeModel(
188188
modelName: modelName,
189189
generationConfig: GenerationConfig(
190190
temperature: 0.0,
@@ -268,7 +268,7 @@ struct GenerateContentIntegrationTests {
268268
"country": .string(),
269269
]
270270
)
271-
let model = FirebaseAI.componentInstance(config).generativeModel(
271+
let model = AILogic.componentInstance(config).generativeModel(
272272
modelName: modelName,
273273
generationConfig: GenerationConfig(
274274
temperature: 0.0,
@@ -341,7 +341,7 @@ struct GenerateContentIntegrationTests {
341341
// 'gemini-2.0-flash-preview-image-generation' model.
342342
$0.harmCategory != .civicIntegrity
343343
}
344-
let model = FirebaseAI.componentInstance(config).generativeModel(
344+
let model = AILogic.componentInstance(config).generativeModel(
345345
modelName: ModelNames.gemini2FlashPreviewImageGeneration,
346346
generationConfig: generationConfig,
347347
safetySettings: safetySettings
@@ -384,7 +384,7 @@ struct GenerateContentIntegrationTests {
384384
arguments: InstanceConfig.allConfigs
385385
)
386386
func generateContent_withGoogleSearch_succeeds(_ config: InstanceConfig) async throws {
387-
let model = FirebaseAI.componentInstance(config).generativeModel(
387+
let model = AILogic.componentInstance(config).generativeModel(
388388
modelName: ModelNames.gemini2Flash,
389389
tools: [.googleSearch()]
390390
)
@@ -450,7 +450,7 @@ struct GenerateContentIntegrationTests {
450450
- Do NOT wrap the JSON in Markdown code blocks (e.g., ```json ... ``` or ``` ... ```).
451451
- The response must start with '[' and end with ']'.
452452
"""
453-
let model = FirebaseAI.componentInstance(config).generativeModel(
453+
let model = AILogic.componentInstance(config).generativeModel(
454454
modelName: modelName,
455455
generationConfig: generationConfig,
456456
safetySettings: safetySettings
@@ -487,7 +487,7 @@ struct GenerateContentIntegrationTests {
487487

488488
@Test(arguments: InstanceConfig.appCheckNotConfiguredConfigs)
489489
func generateContent_appCheckNotConfigured_shouldFail(_ config: InstanceConfig) async throws {
490-
let model = FirebaseAI.componentInstance(config).generativeModel(
490+
let model = AILogic.componentInstance(config).generativeModel(
491491
modelName: ModelNames.gemini2Flash
492492
)
493493
let prompt = "Where is Google headquarters located? Answer with the city name only."

FirebaseAI/Tests/TestApp/Tests/Integration/ImagenIntegrationTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import FirebaseAI
15+
import FirebaseAILogic
1616
import FirebaseAITestApp
1717
import FirebaseAuth
1818
import FirebaseCore
@@ -24,7 +24,7 @@ import Testing
2424
#endif // canImport(UIKit)
2525

2626
// TODO(#14452): Remove `@testable import` when `generateImages(prompt:gcsURI:)` is public.
27-
@testable import class FirebaseAI.ImagenModel
27+
@testable import class FirebaseAILogic.ImagenModel
2828

2929
@Suite(
3030
.enabled(
@@ -34,13 +34,13 @@ import Testing
3434
.serialized
3535
)
3636
struct ImagenIntegrationTests {
37-
var vertex: FirebaseAI
37+
var vertex: AILogic
3838
var storage: Storage
3939
var userID1: String
4040

4141
init() async throws {
4242
userID1 = try await TestHelpers.getUserID()
43-
vertex = FirebaseAI.firebaseAI(backend: .vertexAI())
43+
vertex = AILogic.aiLogic(backend: .vertexAI())
4444
storage = Storage.storage()
4545
}
4646

FirebaseAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import FirebaseAI
15+
import FirebaseAILogic
1616
import FirebaseAITestApp
1717
import FirebaseAuth
1818
import FirebaseCore
1919
import FirebaseStorage
2020
import XCTest
2121

22-
@testable import struct FirebaseAI.CountTokensRequest
22+
@testable import struct FirebaseAILogic.CountTokensRequest
2323

2424
// TODO(#14405): Migrate to Swift Testing and parameterize tests.
2525
final class IntegrationTests: XCTestCase {
@@ -44,14 +44,14 @@ final class IntegrationTests: XCTestCase {
4444
// Candidates and total token counts may differ slightly between runs due to whitespace tokens.
4545
let tokenCountAccuracy = 1
4646

47-
var vertex: FirebaseAI!
47+
var vertex: AILogic!
4848
var model: GenerativeModel!
4949
var storage: Storage!
5050
var userID1 = ""
5151

5252
override func setUp() async throws {
5353
userID1 = try await TestHelpers.getUserID()
54-
vertex = FirebaseAI.firebaseAI(backend: .vertexAI())
54+
vertex = AILogic.aiLogic(backend: .vertexAI())
5555
model = vertex.generativeModel(
5656
modelName: "gemini-2.0-flash",
5757
generationConfig: generationConfig,
@@ -196,7 +196,7 @@ final class IntegrationTests: XCTestCase {
196196

197197
func testCountTokens_appCheckNotConfigured_shouldFail() async throws {
198198
let app = try XCTUnwrap(FirebaseApp.app(name: FirebaseAppNames.appCheckNotConfigured))
199-
let vertex = FirebaseAI.firebaseAI(app: app, backend: .vertexAI())
199+
let vertex = AILogic.aiLogic(app: app, backend: .vertexAI())
200200
let model = vertex.generativeModel(modelName: "gemini-2.0-flash")
201201
let prompt = "Why is the sky blue?"
202202

FirebaseAI/Tests/TestApp/Tests/Integration/SchemaTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import FirebaseAI
15+
import FirebaseAILogic
1616
import FirebaseAITestApp
1717
import FirebaseAuth
1818
import FirebaseCore
@@ -23,7 +23,7 @@ import Testing
2323
import UIKit
2424
#endif // canImport(UIKit)
2525

26-
@testable import struct FirebaseAI.BackendError
26+
@testable import struct FirebaseAILogic.BackendError
2727

2828
/// Test the schema fields.
2929
@Suite(.serialized)
@@ -50,7 +50,7 @@ struct SchemaTests {
5050

5151
@Test(arguments: InstanceConfig.allConfigs)
5252
func generateContentSchemaItems(_ config: InstanceConfig) async throws {
53-
let model = FirebaseAI.componentInstance(config).generativeModel(
53+
let model = AILogic.componentInstance(config).generativeModel(
5454
modelName: ModelNames.gemini2FlashLite,
5555
generationConfig: GenerationConfig(
5656
responseMIMEType: "application/json",
@@ -75,7 +75,7 @@ struct SchemaTests {
7575

7676
@Test(arguments: InstanceConfig.allConfigs)
7777
func generateContentSchemaNumberRange(_ config: InstanceConfig) async throws {
78-
let model = FirebaseAI.componentInstance(config).generativeModel(
78+
let model = AILogic.componentInstance(config).generativeModel(
7979
modelName: ModelNames.gemini2FlashLite,
8080
generationConfig: GenerationConfig(
8181
responseMIMEType: "application/json",
@@ -104,7 +104,7 @@ struct SchemaTests {
104104
let price: Double // Will correspond to .double in schema
105105
let salePrice: Float // Will correspond to .float in schema
106106
}
107-
let model = FirebaseAI.componentInstance(config).generativeModel(
107+
let model = AILogic.componentInstance(config).generativeModel(
108108
modelName: ModelNames.gemini2FlashLite,
109109
generationConfig: GenerationConfig(
110110
responseMIMEType: "application/json",
@@ -195,7 +195,7 @@ struct SchemaTests {
195195
],
196196
description: "A U.S. mailing address"
197197
)
198-
let model = FirebaseAI.componentInstance(config).generativeModel(
198+
let model = AILogic.componentInstance(config).generativeModel(
199199
modelName: ModelNames.gemini2Flash,
200200
generationConfig: GenerationConfig(
201201
temperature: 0.0,

FirebaseAI/Tests/TestApp/Tests/Utilities/InstanceConfig.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import FirebaseAI
15+
import FirebaseAILogic
1616
import FirebaseAITestApp
1717
import FirebaseCore
1818
import Testing
1919

20-
@testable import struct FirebaseAI.APIConfig
20+
@testable import struct FirebaseAILogic.APIConfig
2121

2222
struct InstanceConfig: Equatable, Encodable {
2323
static let vertexAI_v1beta = InstanceConfig(
@@ -146,12 +146,12 @@ extension InstanceConfig: CustomTestStringConvertible {
146146
}
147147
}
148148

149-
extension FirebaseAI {
150-
static func componentInstance(_ instanceConfig: InstanceConfig) -> FirebaseAI {
149+
extension AILogic {
150+
static func componentInstance(_ instanceConfig: InstanceConfig) -> AILogic {
151151
switch instanceConfig.apiConfig.service {
152152
case .vertexAI:
153153
let location = instanceConfig.location ?? "us-central1"
154-
return FirebaseAI.createInstance(
154+
return AILogic.createInstance(
155155
app: instanceConfig.app,
156156
location: location,
157157
apiConfig: instanceConfig.apiConfig,
@@ -162,7 +162,7 @@ extension FirebaseAI {
162162
instanceConfig.location == nil,
163163
"The Developer API is global and does not support `location`."
164164
)
165-
return FirebaseAI.createInstance(
165+
return AILogic.createInstance(
166166
app: instanceConfig.app,
167167
location: nil,
168168
apiConfig: instanceConfig.apiConfig,

0 commit comments

Comments
 (0)