Skip to content

feat(firebase-ai): create ai package, vertexai wraps around it #8555

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

Open
wants to merge 67 commits into
base: main
Choose a base branch
from

Conversation

russellwheatley
Copy link
Member

@russellwheatley russellwheatley commented Jun 3, 2025

Description

  • Moved the bulk of code to new ai package. Kept relevant types in vertexai package and deprecated them.
  • Updated implementation (where possible) to match firebase-js-sdk.
  • Updated mocks to match latest implementation on vertexai-sdk-test-data repo which now segments responses from vertexai and googleai.
  • I did attempt to symlink ai into vertexai but nested symlinks within directories were not being packaged in dist/ so opted to make ai package a dependency which I think is a better way of doing it.
  • Created an ai example app for illustration and tested latest vertexai and ai implementations which surfaced a couple of subtle bugs that have been resolved.

Important

  • We need to do the same attribution as we did for vertexai for this pull request.
  • Double check what needs to be in the CHANGELOG for this release.

Related issues

Release Summary

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
    • Other (macOS, web)
  • My change includes tests;
    • e2e tests added or updated in packages/\*\*/e2e
    • jest tests added or updated in packages/\*\*/__tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan


Think react-native-firebase is great? Please consider supporting the project with any of the below:

Copy link

vercel bot commented Jun 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-firebase ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2025 10:11am

@russellwheatley russellwheatley marked this pull request as ready for review June 6, 2025 14:35
* @param config - The optional config for your firebase app.
* @returns Promise<FirebaseApp> - The initialized Firebase app.
*/
export function initializeApp(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to point to what causes this to become potentially async?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
export function getAI(
app: ReactNativeFirebase.FirebaseApp = getApp(),
options: AIOptions = { backend: new GoogleAIBackend() },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just remove the default and force the user to provide something? How is the API in the JS SDK?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return {
app,
backend: options.backend,
location: (options.backend as VertexAIBackend)?.location || '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it fail if it's a GoogleAIBackend? Should it use a parent class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll just revert to an empty string when GoogleAIBackend. This is for backwards compatibility with VertexAI: https://github.com/invertase/react-native-firebase/blob/firebase-ai/packages/ai/lib/public-types.ts#L132-L136

firebase-js-sdk does the same thing.

@@ -37,8 +37,9 @@ export default [
'**/app.playground.js',
'**/type-test.ts',
'packages/**/modular/dist/**/*',
'packages/vertexai/__tests__/test-utils',
'packages/ai/__tests__/test-utils',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name for the package is set as ai. Is this the correct name, for example would it be firebaseai or firebase_ai. Source

location: 'us-central1',
};

describe('Top level API', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe('Top level API', () => {
describe('getGenerativeModel()', () => {

};

describe('Top level API', () => {
it('getGenerativeModel throws if no model is provided', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('getGenerativeModel throws if no model is provided', () => {
it('should throw an error if no model is provided', () => {

}
});

it('getGenerativeModel throws if no projectId is provided', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('getGenerativeModel throws if no projectId is provided', () => {
it('should throw an error if no projectId is provided', () => {

}
});

it('getGenerativeModel throws if no appId is provided', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('getGenerativeModel throws if no appId is provided', () => {
it('should throw an error if no appId is provided', () => {

assertAssignable<VertexAI, AI>();
});

it('AIError is backwards compatible with VertexAIError', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('AIError is backwards compatible with VertexAIError', function () {
it('should allow VertexAIError to extend AIError, function () {

expect(err).toBeInstanceOf(VertexAIError);
});

it('AIErrorCode is backwards compatible with VertexAIErrorCode', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('AIErrorCode is backwards compatible with VertexAIErrorCode', () => {
it('should allow VertexAIErrorCode to be assignable to AIErrorCode', () => {

expect(errCode).toBe(VertexAIErrorCode.ERROR);
});

it('AIModel is backwards compatible with VertexAIModel', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('AIModel is backwards compatible with VertexAIModel', () => {
it('should allow VertexAIModel to extend AIModel', () => {

});

describe('backward-compatible functions', () => {
it('getGenerativeModel', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('getGenerativeModel', () => {
it('should return a VertexAIModel assignable to AIModel from getGenerativeModel()l', () => {

expect(model).toBeInstanceOf(VertexAIModel);
});

describe('backward-compatible functions', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe('backward-compatible functions', () => {
describe('VertexAI functions', () => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants