-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
* @param config - The optional config for your firebase app. | ||
* @returns Promise<FirebaseApp> - The initialized Firebase app. | ||
*/ | ||
export function initializeApp( |
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.
Would you be able to point to what causes this to become potentially async?
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.
It is async: https://github.com/invertase/react-native-firebase/blob/main/packages/app/lib/internal/registry/app.js#L118
which bears out in the docs: https://rnfirebase.io/app/usage
*/ | ||
export function getAI( | ||
app: ReactNativeFirebase.FirebaseApp = getApp(), | ||
options: AIOptions = { backend: new GoogleAIBackend() }, |
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.
I wonder if we should just remove the default and force the user to provide something? How is the API in the JS SDK?
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.
this is how it is in firebase-js-sdk: https://github.com/firebase/firebase-js-sdk/blob/main/packages/ai/src/api.ts#L130
return { | ||
app, | ||
backend: options.backend, | ||
location: (options.backend as VertexAIBackend)?.location || '', |
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.
Can it fail if it's a GoogleAIBackend? Should it use a parent class?
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.
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', |
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 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', () => { |
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.
describe('Top level API', () => { | |
describe('getGenerativeModel()', () => { |
}; | ||
|
||
describe('Top level API', () => { | ||
it('getGenerativeModel throws if no model is provided', () => { |
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.
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', () => { |
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.
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', () => { |
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.
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 () { |
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.
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', () => { |
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.
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', () => { |
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.
it('AIModel is backwards compatible with VertexAIModel', () => { | |
it('should allow VertexAIModel to extend AIModel', () => { |
}); | ||
|
||
describe('backward-compatible functions', () => { | ||
it('getGenerativeModel', () => { |
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.
it('getGenerativeModel', () => { | |
it('should return a VertexAIModel assignable to AIModel from getGenerativeModel()l', () => { |
expect(model).toBeInstanceOf(VertexAIModel); | ||
}); | ||
|
||
describe('backward-compatible functions', () => { |
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.
describe('backward-compatible functions', () => { | |
describe('VertexAI functions', () => { |
Description
ai
package. Kept relevant types invertexai
package and deprecated them.firebase-js-sdk
.vertexai
andgoogleai
.dist/
so opted to makeai
package a dependency which I think is a better way of doing it.ai
example app for illustration and tested latestvertexai
andai
implementations which surfaced a couple of subtle bugs that have been resolved.Important
vertexai
for this pull request.Related issues
Release Summary
Checklist
Android
iOS
Other
(macOS, web)e2e
tests added or updated inpackages/\*\*/e2e
jest
tests added or updated inpackages/\*\*/__tests__
Test Plan
Think
react-native-firebase
is great? Please consider supporting the project with any of the below:React Native Firebase
andInvertase
on Twitter