Skip to content

Commit 9f7ee6b

Browse files
ifielkerkevinthecheunghiranya911William Sedlacekrsgowman
authored
feat(machine-learning): Adding Firebase ML management APIs (#850)
* Firebase ML Node.js SDK Structure (#778) * Firebase ML Node.js SDK Structure * added tests * Added GetModel functionality and tests (#781) * Added GetModel functionality and tests * Added DeleteModel functionality and tests (#782) * Added DeleteModel functionality and tests * Added CreateModel functionality and tests (#788) * Added CreateModel functionality and tests * Added UpdateModel, publishModel,and unpublishModel functionality + tests (#791) * Added UpdateModel, publishModel,and unpublishModel functionality plus tests * Added ListModels functionality for Firebase ML (#795) * Added ListModels functionality for Firebase ML * Firebase ML changed endpoint (#813) * Add ML APIs to docgen toc (#847) * Docstring fixes and additions (#848) * Docstring fixes and additions * A few edits * Ml merge (#851) * Custom Action for sending Tweets (#784) * Experimental custom Action for sending Tweets * Added license headers * Added README file * Updated package descriptions * Improve customClaims Typing (#768) * chore: Experimental release flow based on Actions (#780) * chore: Experimental release flow based on Actions * Added tarball verification step; Simplified CI trigger * Splitting staging and publish phases into separate jobs * Fleshed out the full workflow * Trigger RC build * chore: Migrated to ESlint (#790) * chore: Migrated to ESlint * Added licesne header * Enabling additional ESLint checks (#794) * chore: Enabling more ESLint checks and fixing errors (#797) * Fix compilation error in integration tests (#798) Introduced by #790 * Build integration tests during CI (and release) (#800) Note that this won't actually run them. Additionally, the *unit* tests are also built, impying that we're building them twice (once during this step, and possibly again when running the unit tests.) * Fix revokeRefreshTokens to round consistently with the other platforms. (#801) This also makes it consistent with the comments a few lines above, as well as the integration test. * feat(auth): Multi-factor Auth support with SMS for Google Cloud Identity Platform (#804) Defines multi-factor auth administrative APIs for Google Cloud Identity Platform. * Defines new MFA types in toc.yaml. (#807) * Removes special char from index.d.ts. (#808) This is causing errors in the reference generation process. * Defines MultiFactor{Create|Update}Settings interfaces. (#809) * Defines MultiFactor{Create|Update}Settings interfaces. * chore: Adding a .npmrc file to the root of the repo (#810) * chore: Adding a .npmrc file to the root of the repo * Removing the root-level .npmrc file * [chore] Release 8.10.0 (#811) * [chore] Release 8.10.0 (take 2) (#812) * Bump acorn from 6.1.1 to 6.4.1 (#815) Bumps [acorn](https://github.com/acornjs/acorn) from 6.1.1 to 6.4.1. - [Release notes](https://github.com/acornjs/acorn/releases) - [Commits](acornjs/acorn@6.1.1...6.4.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Fixing Android notification options descriptions (#820) * Fixing doc bug that conflated sound and tag options for Android notifications. * Removing duplicate documentation for tag. * Adding tag details in the right place this time, hopefully. * chore: Splitting the index.d.ts file into smaller files (#751) * Splitting the index.d.ts file into smaller files * Database return type fixed * chore: Cleaning up package verification scripts (#822) * chore: Cleaning up package verification scripts * Added package metadata to test package.json file * fix(auth): Fixing UserImportRecord typings declaration (#835) * fix(auth): Fixing UserImportRecord typings declaration * Fixing more integration test compilation errors * Trigger CI * Removed redundant line * Bump minimist from 1.2.0 to 1.2.3 (#839) Bumps [minimist](https://github.com/substack/minimist) from 1.2.0 to 1.2.3. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.0...1.2.3) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * remerge conflict Co-authored-by: Hiranya Jayathilaka <[email protected]> Co-authored-by: William Sedlacek <[email protected]> Co-authored-by: rsgowman <[email protected]> Co-authored-by: bojeil-google <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: egilmorez <[email protected]> * Added Firebase ML API requirements to Contributing doc (#853) Co-authored-by: Kevin Cheung <[email protected]> Co-authored-by: Hiranya Jayathilaka <[email protected]> Co-authored-by: William Sedlacek <[email protected]> Co-authored-by: rsgowman <[email protected]> Co-authored-by: bojeil-google <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: egilmorez <[email protected]>
1 parent ed6036f commit 9f7ee6b

17 files changed

+3023
-2
lines changed

CONTRIBUTING.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,17 @@ Then set up your Firebase/GCP project as follows:
155155
Firebase Console. Select the "Sign-in method" tab, and enable the
156156
"Email/Password" sign-in method, including the Email link (passwordless
157157
sign-in) option.
158-
3. Enable the IAM API: Go to the
158+
3. Enable the Firebase ML API: Go to the
159+
[Google Developers Console](
160+
https://console.developers.google.com/apis/api/firebaseml.googleapis.com/overview)
161+
and make sure your project is selected. If the API is not already enabled, click Enable.
162+
4. Enable the IAM API: Go to the
159163
[Google Cloud Platform Console](https://console.cloud.google.com) and make
160164
sure your Firebase/GCP project is selected. Select "APIs & Services >
161165
Dashboard" from the main menu, and click the "ENABLE APIS AND SERVICES"
162166
button. Search for and enable the "Identity and Access Management (IAM)
163167
API".
164-
4. Grant your service account the 'Firebase Authentication Admin' role. This is
168+
5. Grant your service account the 'Firebase Authentication Admin' role. This is
165169
required to ensure that exported user records contain the password hashes of
166170
the user accounts:
167171
1. Go to [Google Cloud Platform Console / IAM & admin](https://console.cloud.google.com/iam-admin).

docgen/content-sources/node/toc.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ toc:
132132
- title: "InstanceId"
133133
path: /docs/reference/admin/node/admin.instanceId.InstanceId
134134

135+
- title: "machinelearning"
136+
path: /docs/reference/admin/node/admin.machinelearning
137+
section:
138+
- title: "ListModelsOptions"
139+
path: /docs/reference/admin/node/admin.machinelearning.ListModelsOptions
140+
- title: "ListModelsResult"
141+
path: /docs/reference/admin/node/admin.machinelearning.ListModelsResult
142+
- title: "MachineLearning"
143+
path: /docs/reference/admin/node/admin.machinelearning.MachineLearning
144+
- title: "Model"
145+
path: /docs/reference/admin/node/admin.machinelearning.Model
146+
- title: "ModelOptions"
147+
path: /docs/reference/admin/node/admin.machinelearning.ModelOptions
148+
- title: "TFLiteModel"
149+
path: /docs/reference/admin/node/admin.machinelearning.TFLiteModel
150+
135151
- title: "admin.messaging"
136152
path: /docs/reference/admin/node/admin.messaging
137153
section:

src/firebase-app.ts

+15
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import {FirebaseNamespaceInternals} from './firebase-namespace';
2222
import {AppErrorCodes, FirebaseAppError} from './utils/error';
2323

2424
import {Auth} from './auth/auth';
25+
import {MachineLearning} from './machine-learning/machine-learning';
2526
import {Messaging} from './messaging/messaging';
2627
import {Storage} from './storage/storage';
2728
import {Database} from '@firebase/database';
2829
import {DatabaseService} from './database/database';
2930
import {Firestore} from '@google-cloud/firestore';
3031
import {FirestoreService} from './firestore/firestore';
3132
import {InstanceId} from './instance-id/instance-id';
33+
3234
import {ProjectManagement} from './project-management/project-management';
3335
import {SecurityRules} from './security-rules/security-rules';
3436

@@ -354,6 +356,19 @@ export class FirebaseApp {
354356
});
355357
}
356358

359+
/**
360+
* Returns the MachineLearning service instance associated with this app.
361+
*
362+
* @return {MachineLearning} The Machine Learning service instance of this app
363+
*/
364+
public machineLearning(): MachineLearning {
365+
return this.ensureService_('machine-learning', () => {
366+
const machineLearningService: typeof MachineLearning =
367+
require('./machine-learning/machine-learning').MachineLearning;
368+
return new machineLearningService(this);
369+
});
370+
}
371+
357372
/**
358373
* Returns the ProjectManagement service instance associated with this app.
359374
*

src/firebase-namespace.ts

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from './auth/credential';
2929

3030
import {Auth} from './auth/auth';
31+
import {MachineLearning} from './machine-learning/machine-learning';
3132
import {Messaging} from './messaging/messaging';
3233
import {Storage} from './storage/storage';
3334
import {Database} from '@firebase/database';
@@ -399,6 +400,21 @@ export class FirebaseNamespace {
399400
return fn;
400401
}
401402

403+
/**
404+
* Gets the `MachineLearning` service namespace. The returned namespace can be
405+
* used to get the `MachineLearning` service for the default app or an
406+
* explicityly specified app.
407+
*/
408+
get machineLearning(): FirebaseServiceNamespace<MachineLearning> {
409+
const fn: FirebaseServiceNamespace<MachineLearning> =
410+
(app?: FirebaseApp) => {
411+
return this.ensureApp(app).machineLearning();
412+
};
413+
const machineLearning =
414+
require('./machine-learning/machine-learning').MachineLearning;
415+
return Object.assign(fn, {MachineLearning: machineLearning});
416+
}
417+
402418
/**
403419
* Gets the `InstanceId` service namespace. The returned namespace can be used to get the
404420
* `Instance` service for the default app or an explicitly specified app.

src/index.d.ts

+238
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,37 @@ declare namespace admin {
404404
*/
405405
function securityRules(app?: admin.app.App): admin.securityRules.SecurityRules;
406406

407+
/**
408+
* Gets the {@link admin.machineLearning.MachineLearning `MachineLearning`} service for the
409+
* default app or a given app.
410+
*
411+
* `admin.machineLearning()` can be called with no arguments to access the
412+
* default app's {@link admin.machineLearning.MachineLearning
413+
* `MachineLearning`} service or as `admin.machineLearning(app)` to access
414+
* the {@link admin.machineLearning.MachineLearning `MachineLearning`}
415+
* service associated with a specific app.
416+
*
417+
* @example
418+
* ```javascript
419+
* // Get the MachineLearning service for the default app
420+
* var defaultMachineLearning = admin.machineLearning();
421+
* ```
422+
*
423+
* @example
424+
* ```javascript
425+
* // Get the MachineLearning service for a given app
426+
* var otherMachineLearning = admin.machineLearning(otherApp);
427+
* ```
428+
*
429+
* @param app Optional app whose `MachineLearning` service to
430+
* return. If not provided, the default `MachineLearning` service
431+
* will be returned.
432+
*
433+
* @return The default `MachineLearning` service if no app is provided or the
434+
* `MachineLearning` service associated with the provided app.
435+
*/
436+
function machineLearning(app?: admin.app.App): admin.machineLearning.MachineLearning;
437+
407438
function initializeApp(options?: admin.AppOptions, name?: string): admin.app.App;
408439
}
409440

@@ -462,6 +493,7 @@ declare namespace admin.app {
462493
database(url?: string): admin.database.Database;
463494
firestore(): admin.firestore.Firestore;
464495
instanceId(): admin.instanceId.InstanceId;
496+
machineLearning(): admin.machineLearning.MachineLearning;
465497
messaging(): admin.messaging.Messaging;
466498
projectManagement(): admin.projectManagement.ProjectManagement;
467499
securityRules(): admin.securityRules.SecurityRules;
@@ -788,6 +820,212 @@ declare namespace admin.securityRules {
788820
export import SecurityRules = _securityRules.admin.securityRules.SecurityRules;
789821
}
790822

823+
declare namespace admin.machineLearning {
824+
/**
825+
* Interface representing options for listing Models.
826+
*/
827+
interface ListModelsOptions {
828+
/**
829+
* An expression that specifies how to filter the results.
830+
*
831+
* Examples:
832+
*
833+
* ```
834+
* display_name = your_model
835+
* display_name : experimental_*
836+
* tags: face_detector AND tags: experimental
837+
* state.published = true
838+
* ```
839+
*
840+
* See https://firebase.google.com/docs/ml-kit/manage-hosted-models#list_your_projects_models
841+
*/
842+
filter?: string;
843+
844+
/** The number of results to return in each page. */
845+
pageSize?: number;
846+
847+
/** A token that specifies the result page to return. */
848+
pageToken?: string;
849+
}
850+
851+
/** Response object for a listModels operation. */
852+
interface ListModelsResult {
853+
/** A list of models in your project. */
854+
readonly models: Model[];
855+
856+
/**
857+
* A token you can use to retrieve the next page of results. If null, the
858+
* current page is the final page.
859+
*/
860+
readonly pageToken?: string;
861+
}
862+
863+
/**
864+
* A TensorFlow Lite Model output object
865+
*/
866+
interface TFLiteModel {
867+
/** The size of the model. */
868+
readonly sizeBytes: number;
869+
870+
/** The URI from which the model was originally provided to Firebase. */
871+
readonly gcsTfliteUri?: string;
872+
}
873+
874+
/**
875+
* A Firebase ML Model input object
876+
*/
877+
interface ModelOptions {
878+
/** A name for the model. This is the name you use from your app to load the model. */
879+
displayName?: string;
880+
881+
/** Tags for easier model management. */
882+
tags?: string[];
883+
884+
/**
885+
* An object containing the URI of the model in Cloud Storage.
886+
*
887+
* Example: `tfliteModel: { gcsTfliteUri: 'gs://your-bucket/your-model.tflite' }`
888+
*/
889+
tfliteModel?: {gcsTfliteUri: string};
890+
}
891+
892+
/**
893+
* A Firebase ML Model output object
894+
*/
895+
interface Model {
896+
/** The ID of the model. */
897+
readonly modelId: string;
898+
899+
/** The model's name. This is the name you use from your app to load the model. */
900+
readonly displayName: string;
901+
902+
/** The model's tags. */
903+
readonly tags?: string[];
904+
905+
/** The timestamp of the model's creation. */
906+
readonly createTime: string;
907+
908+
/** The timestamp of the model's most recent update. */
909+
readonly updateTime: string;
910+
911+
/** Error message when model validation fails. */
912+
readonly validationError?: string;
913+
914+
/** True if the model is published. */
915+
readonly published: boolean;
916+
917+
/**
918+
* The ETag identifier of the current version of the model. This value
919+
* changes whenever you update any of the model's properties.
920+
*/
921+
readonly etag: string;
922+
923+
/**
924+
* The hash of the model's `tflite` file. This value changes only when
925+
* you upload a new TensorFlow Lite model.
926+
*/
927+
readonly modelHash?: string;
928+
929+
/**
930+
* True if the model is locked by a server-side operation. You can't make
931+
* changes to a locked model. See {@link waitForUnlocked `waitForUnlocked()`}.
932+
*/
933+
readonly locked: boolean;
934+
935+
/**
936+
* Wait for the model to be unlocked.
937+
*
938+
* @param {number} maxTimeSeconds The maximum time in seconds to wait.
939+
*
940+
* @return {Promise<void>} A promise that resolves when the model is unlocked
941+
* or the maximum wait time has passed.
942+
*/
943+
waitForUnlocked(maxTimeSeconds?: number): Promise<void>;
944+
945+
/** Metadata about the model's TensorFlow Lite model file. */
946+
readonly tfliteModel?: TFLiteModel;
947+
}
948+
949+
/**
950+
* The Firebase `MachineLearning` service interface.
951+
*
952+
* Do not call this constructor directly. Instead, use
953+
* [`admin.machineLearning()`](admin.machineLearning#machineLearning).
954+
*/
955+
interface MachineLearning {
956+
/**
957+
* The {@link admin.app.App} associated with the current `MachineLearning`
958+
* service instance.
959+
*/
960+
app: admin.app.App;
961+
962+
/**
963+
* Creates a model in Firebase ML.
964+
*
965+
* @param {ModelOptions} model The model to create.
966+
*
967+
* @return {Promise<Model>} A Promise fulfilled with the created model.
968+
*/
969+
createModel(model: ModelOptions): Promise<Model>;
970+
971+
/**
972+
* Updates a model in Firebase ML.
973+
*
974+
* @param {string} modelId The ID of the model to update.
975+
* @param {ModelOptions} model The model fields to update.
976+
*
977+
* @return {Promise<Model>} A Promise fulfilled with the updated model.
978+
*/
979+
updateModel(modelId: string, model: ModelOptions): Promise<Model>;
980+
981+
/**
982+
* Publishes a model in Firebase ML.
983+
*
984+
* @param {string} modelId The ID of the model to publish.
985+
*
986+
* @return {Promise<Model>} A Promise fulfilled with the published model.
987+
*/
988+
publishModel(modelId: string): Promise<Model>;
989+
990+
/**
991+
* Unpublishes a model in Firebase ML.
992+
*
993+
* @param {string} modelId The ID of the model to unpublish.
994+
*
995+
* @return {Promise<Model>} A Promise fulfilled with the unpublished model.
996+
*/
997+
unpublishModel(modelId: string): Promise<Model>;
998+
999+
/**
1000+
* Gets a model from Firebase ML.
1001+
*
1002+
* @param {string} modelId The ID of the model to get.
1003+
*
1004+
* @return {Promise<Model>} A Promise fulfilled with the model object.
1005+
*/
1006+
getModel(modelId: string): Promise<Model>;
1007+
1008+
/**
1009+
* Lists models from Firebase ML.
1010+
*
1011+
* @param {ListModelsOptions} options The listing options.
1012+
*
1013+
* @return {Promise<ListModelsResult>} A promise that
1014+
* resolves with the current (filtered) list of models and the next page
1015+
* token. For the last page, an empty list of models and no page token
1016+
* are returned.
1017+
*/
1018+
listModels(options?: ListModelsOptions): Promise<ListModelsResult>;
1019+
1020+
/**
1021+
* Deletes a model from Firebase ML.
1022+
*
1023+
* @param {string} modelId The ID of the model to delete.
1024+
*/
1025+
deleteModel(modelId: string): Promise<void>;
1026+
}
1027+
}
1028+
7911029
declare module 'firebase-admin' {
7921030
}
7931031

0 commit comments

Comments
 (0)