-
Notifications
You must be signed in to change notification settings - Fork 912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add X-Firebase-AppId
header to VertexAI requests
#8809
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@firebase/vertexai': patch | ||
--- | ||
|
||
Throw an error when initializing models if `appId` is not defined in the given `VertexAI` instance. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,10 +68,18 @@ export abstract class VertexAIModel { | |
VertexAIErrorCode.NO_PROJECT_ID, | ||
`The "projectId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid project ID.` | ||
); | ||
} else if (!vertexAI.app?.options?.appId) { | ||
throw new VertexAIError( | ||
VertexAIErrorCode.NO_APP_ID, | ||
`The "appId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid app ID.` | ||
); | ||
} else { | ||
this._apiSettings = { | ||
apiKey: vertexAI.app.options.apiKey, | ||
project: vertexAI.app.options.projectId, | ||
appId: vertexAI.app.options.appId, | ||
automaticDataCollectionEnabled: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No action needed, just wondering out loud if at some number of properties, we just pass vertexAI.app or at least vertexAI.app.options through instead of passing them through one by one. |
||
vertexAI.app.automaticDataCollectionEnabled, | ||
location: vertexAI.location | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,9 @@ export async function getHeaders(url: RequestUrl): Promise<Headers> { | |
headers.append('Content-Type', 'application/json'); | ||
headers.append('x-goog-api-client', getClientHeaders()); | ||
headers.append('x-goog-api-key', url.apiSettings.apiKey); | ||
if (url.apiSettings.automaticDataCollectionEnabled !== false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should be safe and make this fail on any falsy value in case, say, the user sets it to undefined for some reason. Sometimes that's how people unset properties. So just |
||
headers.append('X-Firebase-AppId', url.apiSettings.appId); | ||
} | ||
if (url.apiSettings.getAppCheckToken) { | ||
const appCheckToken = await url.apiSettings.getAppCheckToken(); | ||
if (appCheckToken) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In light of Paul's comment about
automaticDataCollectionEnabled
, not sure if we throw this error if that's false, since we don't actually need appId in that case? Kind of weird edge case though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
firebaseAppConfig
obtained from Firebase Console and Terraform always contains anappId
, so unless the developer deliberately removes theappId
(not sure why since it's not sensitive), it should always be present. AppId is not just for telemetry purposes. Thus, stronger validation is better here.