Skip to content

Commit b189b5c

Browse files
committed
Check latest isDataCollectionDefaultEnabled value during request
1 parent c9edcb4 commit b189b5c

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

FirebaseVertexAI/Sources/FirebaseInfo.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ struct FirebaseInfo {
2525
let auth: AuthInterop?
2626
let projectID: String
2727
let apiKey: String
28-
let googleAppID: String?
28+
let googleAppID: String
29+
let app: FirebaseApp
2930

3031
init(appCheck: AppCheckInterop? = nil,
3132
auth: AuthInterop? = nil,
3233
projectID: String,
3334
apiKey: String,
34-
googleAppID: String?) {
35+
googleAppID: String,
36+
firebaseApp: FirebaseApp) {
3537
self.appCheck = appCheck
3638
self.auth = auth
3739
self.projectID = projectID
3840
self.apiKey = apiKey
3941
self.googleAppID = googleAppID
42+
app = firebaseApp
4043
}
4144
}

FirebaseVertexAI/Sources/GenerativeAIService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ struct GenerativeAIService {
193193
urlRequest.setValue("Firebase \(authToken)", forHTTPHeaderField: "Authorization")
194194
}
195195

196-
if let googleAppID = firebaseInfo.googleAppID {
197-
urlRequest.setValue(googleAppID, forHTTPHeaderField: "X-Firebase-AppId")
196+
if firebaseInfo.app.isDataCollectionDefaultEnabled {
197+
urlRequest.setValue(firebaseInfo.googleAppID, forHTTPHeaderField: "X-Firebase-AppId")
198198
}
199199

200200
let encoder = JSONEncoder()

FirebaseVertexAI/Sources/VertexAI.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ public class VertexAI {
172172
auth: ComponentType<AuthInterop>.instance(for: AuthInterop.self, in: app.container),
173173
projectID: projectID,
174174
apiKey: apiKey,
175-
googleAppID: app.isDataCollectionDefaultEnabled ? app.options.googleAppID : nil
175+
googleAppID: app.options.googleAppID,
176+
firebaseApp: app
176177
)
177178
self.location = location
178179
}

FirebaseVertexAI/Tests/Unit/ChatTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import Foundation
1616
import XCTest
1717

18+
import FirebaseCore
1819
@testable import FirebaseVertexAI
1920

2021
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
@@ -53,12 +54,16 @@ final class ChatTests: XCTestCase {
5354
return (response, fileURL.lines)
5455
}
5556

57+
let app = FirebaseApp(instanceWithName: "testApp",
58+
options: FirebaseOptions(googleAppID: "ignore",
59+
gcmSenderID: "ignore"))
5660
let model = GenerativeModel(
5761
name: "my-model",
5862
firebaseInfo: FirebaseInfo(
5963
projectID: "my-project-id",
6064
apiKey: "API_KEY",
61-
googleAppID: "My app ID"
65+
googleAppID: "My app ID",
66+
firebaseApp: app
6267
),
6368
tools: nil,
6469
requestOptions: RequestOptions(),

FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,12 +1454,17 @@ final class GenerativeModelTests: XCTestCase {
14541454
private func testFirebaseInfo(appCheck: AppCheckInterop? = nil,
14551455
auth: AuthInterop? = nil,
14561456
privateAppID: Bool = false) -> FirebaseInfo {
1457-
FirebaseInfo(
1457+
let app = FirebaseApp(instanceWithName: "testApp",
1458+
options: FirebaseOptions(googleAppID: "ignore",
1459+
gcmSenderID: "ignore"))
1460+
app.isDataCollectionDefaultEnabled = !privateAppID
1461+
return FirebaseInfo(
14581462
appCheck: appCheck,
14591463
auth: auth,
14601464
projectID: "my-project-id",
14611465
apiKey: "API_KEY",
1462-
googleAppID: privateAppID ? nil : "My app ID"
1466+
googleAppID: "My app ID",
1467+
firebaseApp: app
14631468
)
14641469
}
14651470

0 commit comments

Comments
 (0)