Skip to content
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

feat: vertexAI package support #8236

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

feat: vertexAI package support #8236

wants to merge 101 commits into from

Conversation

russellwheatley
Copy link
Member

Description

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
  • 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 Jan 17, 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 Jan 31, 2025 0:29am

@russellwheatley russellwheatley changed the title init feat: vertexAI package support Jan 17, 2025
@russellwheatley
Copy link
Member Author

russellwheatley commented Jan 30, 2025

@mikehardy - just to give you an update. I was able to write e2e tests for fetch and fetch stream.

I was able to mock vertexAI responses here: fa07a0d (#8236)

To make this work, I edited the RequestUrl to point to our emulators here: 8e8a2c6 (#8236),
I then updated the env var in the e2e test runner: d0afb73 (#8236)

I think this is fine but just wanted to see what you thought. I thought this would be better than just a stream/fetch request.

The thing that really borked was when I updated the types to use RNFB types rather than firebase-js-sdk types which are bundled with app (and sneakily allowed it to build/compile TS): https://github.com/invertase/react-native-firebase/blob/fix-jest-tests/packages/app/package.json#L60

Here is the commit: 0c9f687 (#8236)

I've basically reproduced the types from auth and app check package but only copied the relevant API we need to get a token from either package.

This created an additional problem. I needed to add this config to vertexai tsconfig.json so it knew about the app package (it's a peer dependency ):30b2b0e (#8236). But more importantly, to the root tsconfig.json as jest test runner would fail without it.

But this broke our TS validation as it now couldn't find firebase.storage(), firebase.auth() types on the FirebaseApp type. So I extended the tsconfig.json just for Jest: d378aee (#8236)

The last bits from my perspective are merging this: #8257

and figuring out why vertexai usage docs are broken on preview.

@russellwheatley
Copy link
Member Author

russellwheatley commented Jan 31, 2025

What do you think of this, @mikehardy? I update the types in this commit to use actual auth and app check types: 3514416 (#8236)

I had a look initially at using relative paths to auth and app check, but in the dist/ directory it kept the relative paths to auth and app check which naturally won't exist when published. So I used the paths property in tsconfig.json:

    "paths": {
      "@react-native-firebase/app": ["../app/lib"],
      "@react-native-firebase/auth": ["../auth/lib"],
      "@react-native-firebase/app-check": ["../app-check/lib"],
    }

which, for example, now generates the following types in dist/commonjs/lib/service.d.ts:

import { ReactNativeFirebase } from '@react-native-firebase/app';
import { VertexAI, VertexAIOptions } from './public-types';
import { FirebaseAuthTypes } from '@react-native-firebase/auth';
import { FirebaseAppCheckTypes } from '@react-native-firebase/app-check';
export declare class VertexAIService implements VertexAI {
    app: ReactNativeFirebase.FirebaseApp;
    options?: VertexAIOptions | undefined;
    auth: FirebaseAuthTypes.Module | null;
    appCheck: FirebaseAppCheckTypes.Module | null;
    location: string;
    constructor(app: ReactNativeFirebase.FirebaseApp, auth?: FirebaseAuthTypes.Module, appCheck?: FirebaseAppCheckTypes.Module, options?: VertexAIOptions | undefined);
}
//# sourceMappingURL=service.d.ts.map

If the user does pass in auth instance, they will naturally install auth dependency, and therefore import { FirebaseAuthTypes } from '@react-native-firebase/auth'; I believe will be able to reference the correct types from that import if that makes sense.

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

Successfully merging this pull request may close these issues.

3 participants