Skip to content

Commit 43e246d

Browse files
ifielkerhiranya911kevinthecheung
authored
feat(ml): Adding Firebase ML management APIs (#447)
* Introduced the exceptions module (#296) * Added the exceptions module * Cleaned up the error handling logic; Added tests * Updated docs; Fixed some typos * Migrating FCM Send APIs to the New Exceptions (#297) * Migrated FCM send APIs to the new error handling regime * Moved error parsing logic to _utils * Refactored OP error handling code * Fixing a broken test * Added utils for handling googleapiclient errors * Added tests for new error handling logic * Updated public API docs * Fixing test for python3 * Cleaning up the error code lookup code * Cleaning up the error parsing APIs * Cleaned up error parsing logic; Updated docs * Migrated remaining messaging APIs to new error types (#298) * Migrated FCM send APIs to the new error handling regime * Moved error parsing logic to _utils * Refactored OP error handling code * Fixing a broken test * Added utils for handling googleapiclient errors * Added tests for new error handling logic * Updated public API docs * Fixing test for python3 * Cleaning up the error code lookup code * Cleaning up the error parsing APIs * Cleaned up error parsing logic; Updated docs * Migrated the FCM IID APIs to the new error types * Introducing TokenSignError to represent custom token creation errors (#302) * Migrated FCM send APIs to the new error handling regime * Moved error parsing logic to _utils * Refactored OP error handling code * Fixing a broken test * Added utils for handling googleapiclient errors * Added tests for new error handling logic * Updated public API docs * Fixing test for python3 * Cleaning up the error code lookup code * Cleaning up the error parsing APIs * Cleaned up error parsing logic; Updated docs * Migrated the FCM IID APIs to the new error types * Migrated custom token API to new error types * Raising FirebaseError from create_session_cookie() API (#306) * Migrated FCM send APIs to the new error handling regime * Moved error parsing logic to _utils * Refactored OP error handling code * Fixing a broken test * Added utils for handling googleapiclient errors * Added tests for new error handling logic * Updated public API docs * Fixing test for python3 * Cleaning up the error code lookup code * Cleaning up the error parsing APIs * Cleaned up error parsing logic; Updated docs * Migrated the FCM IID APIs to the new error types * Migrated custom token API to new error types * Migrated create cookie API to new error types * Improved error message computation * Refactored the shared error handling code * Fixing lint errors * Renamed variable for clarity * Introducing UserNotFoundError type (#309) * Added UserNotFoundError type * Fixed some lint errors * Some formatting updates * Updated docs and tests * New error handling support in create/update/delete user APIs (#311) * New error handling support in create/update/delete user APIs * Fixing some lint errors * Error handling improvements in email action link APIs (#312) * New error handling support in create/update/delete user APIs * Fixing some lint errors * Error handling update in email action link APIs * Project management API migrated to new error types (#314) * Error handling updated for remaining user_mgt APIs (#315) * Error handling updated for remaining user_mgt APIs * Removed unused constants * Migrated token verification APIs to new exception types (#317) * Migrated token verification APIs to new error types * Removed old AuthError type * Added new exception types for revoked tokens * Migrated the db module to the new exception types (#318) * Migrating db module to new exception types * Error handling for transactions * Updated integration tests * Restoring the old txn abort behavior * Updated error type in snippet * Added comment * Adding a few overlooked error types (#319) * Adding some missing error types * Updated documentation * Removing the ability to delete user properties by passing None (#320) * Adding beginning of _MLKitService (#323) * Adding beginning of _MLKitService * Added License and Docstring * Firebase ML Kit Get Model API implementation (#326) * added GetModel * Added tests for get_model * Firebase ML Kit Delete Model API implementation (#327) * implement delete model * Firebase ML Kit List Models API implementation (#331) * implemented list models plus tests * Implementation of Model, ModelFormat, TFLiteModelSource and subclasses (#335) * Implementation of Model, ModelFormat, ModelSource and subclasses * Firebase ML Kit Create Model API implementation (#337) * create model plus long running operation handling * Model.wait_for_unlocked * Firebase ML Kit Update Model API implementation (#343) * Firebase ML Kit Create Model API implementation * Firebase ML Kit Publish and Unpublish Implementation (#345) * Firebase ML Kit Publish and Unpublish Implementation * Firebase ML Kit TFLiteGCSModelSource.from_tflite_model implementation and conversion helpers (#346) * Firebase ML Kit TFLiteGCSModelSource.from_tflite_model implementation * support for tensorflow lite conversion helpers (version 1.x) * Quick pass at filling in missing docstrings (#367) * Quick pass at filling in missing docstrings * More punctuation * Modify Operation Handling to not require a name for Done Operations (#371) * Firebase ML Kit Modify Operation Handling to not require a name for Done Operations * Adding support for TensorFlow 2.x * rename from mlkit to ml (#373) * Adding File naming capability to from_saved_model and from_keras_model. (#375) adding File naming capability for ModelSource * Firebase ML Modify Operation Handling Code to match rpc codes not html codes (#390) * Firebase ML Modify Operation Handling Code to match actual codes * apply database fix too * Mlkit fix date handling2 (#391) * Fix create/update date handling * Skip unrelated failing tests (until sync) * Firebase Ml Fix upload file naming (#392) * Fix File Naming * Integration tests for Firebase ML (#394) * Integration tests for Firebase ML * Fixing lint errors for Py3 (#401) * Fixing lint errors for Py3 * Removed dependency on six * Fixing a couple of merge errors * Modifying operation handling to support backend changes (#423) * modifying operation handling to support backend changes * Firebase ML Changing service endpoint (#421) * Mlkit add headers (#445) * add Headers * fixed test (#448) * Adding tensorflow and keras so we don't skip tests (#449) * Adding tensorflow and keras so we don't skip tests * Add additional instructions for integration tests for ml Co-authored-by: Hiranya Jayathilaka <[email protected]> Co-authored-by: Kevin Cheung <[email protected]>
1 parent af1b456 commit 43e246d

File tree

8 files changed

+2478
-3
lines changed

8 files changed

+2478
-3
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ jobs:
5454
python -m pip install --upgrade pip
5555
pip install -r requirements.txt
5656
pip install setuptools wheel
57+
pip install tensorflow
58+
pip install keras
5759
5860
- name: Run unit tests
5961
run: pytest

CONTRIBUTING.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,17 @@ Then set up your Firebase/GCP project as follows:
183183
Firebase Console. Select the "Sign-in method" tab, and enable the
184184
"Email/Password" sign-in method, including the Email link (passwordless
185185
sign-in) option.
186-
187-
3. Enable the IAM API: Go to the
186+
3. Enable the Firebase ML API: Go to the
187+
[Google Developers Console](
188+
https://console.developers.google.com/apis/api/firebaseml.googleapis.com/overview)
189+
and make sure your project is selected. If the API is not already enabled, click Enable.
190+
4. Enable the IAM API: Go to the
188191
[Google Cloud Platform Console](https://console.cloud.google.com) and make
189192
sure your Firebase/GCP project is selected. Select "APIs & Services >
190193
Dashboard" from the main menu, and click the "ENABLE APIS AND SERVICES"
191194
button. Search for and enable the "Identity and Access Management (IAM)
192195
API".
193-
4. Grant your service account the 'Firebase Authentication Admin' role. This is
196+
5. Grant your service account the 'Firebase Authentication Admin' role. This is
194197
required to ensure that exported user records contain the password hashes of
195198
the user accounts:
196199
1. Go to [Google Cloud Platform Console / IAM & admin](https://console.cloud.google.com/iam-admin).

firebase_admin/_utils.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@
5959
}
6060

6161

62+
# See https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
63+
_RPC_CODE_TO_ERROR_CODE = {
64+
1: exceptions.CANCELLED,
65+
2: exceptions.UNKNOWN,
66+
3: exceptions.INVALID_ARGUMENT,
67+
4: exceptions.DEADLINE_EXCEEDED,
68+
5: exceptions.NOT_FOUND,
69+
6: exceptions.ALREADY_EXISTS,
70+
7: exceptions.PERMISSION_DENIED,
71+
8: exceptions.RESOURCE_EXHAUSTED,
72+
9: exceptions.FAILED_PRECONDITION,
73+
10: exceptions.ABORTED,
74+
11: exceptions.OUT_OF_RANGE,
75+
13: exceptions.INTERNAL,
76+
14: exceptions.UNAVAILABLE,
77+
15: exceptions.DATA_LOSS,
78+
16: exceptions.UNAUTHENTICATED,
79+
}
80+
81+
6282
def _get_initialized_app(app):
6383
"""Returns a reference to an initialized App instance."""
6484
if app is None:
@@ -75,6 +95,7 @@ def _get_initialized_app(app):
7595
' firebase_admin.App, but given "{0}".'.format(type(app)))
7696

7797

98+
7899
def get_app_service(app, name, initializer):
79100
app = _get_initialized_app(app)
80101
return app._get_service(name, initializer) # pylint: disable=protected-access
@@ -108,6 +129,27 @@ def handle_platform_error_from_requests(error, handle_func=None):
108129
return exc if exc else _handle_func_requests(error, message, error_dict)
109130

110131

132+
def handle_operation_error(error):
133+
"""Constructs a ``FirebaseError`` from the given operation error.
134+
135+
Args:
136+
error: An error returned by a long running operation.
137+
138+
Returns:
139+
FirebaseError: A ``FirebaseError`` that can be raised to the user code.
140+
"""
141+
if not isinstance(error, dict):
142+
return exceptions.UnknownError(
143+
message='Unknown error while making a remote service call: {0}'.format(error),
144+
cause=error)
145+
146+
rpc_code = error.get('code')
147+
message = error.get('message')
148+
error_code = _rpc_code_to_error_code(rpc_code)
149+
err_type = _error_code_to_exception_type(error_code)
150+
return err_type(message=message)
151+
152+
111153
def _handle_func_requests(error, message, error_dict):
112154
"""Constructs a ``FirebaseError`` from the given GCP error.
113155
@@ -264,6 +306,9 @@ def _http_status_to_error_code(status):
264306
"""Maps an HTTP status to a platform error code."""
265307
return _HTTP_STATUS_TO_ERROR_CODE.get(status, exceptions.UNKNOWN)
266308

309+
def _rpc_code_to_error_code(rpc_code):
310+
"""Maps an RPC code to a platform error code."""
311+
return _RPC_CODE_TO_ERROR_CODE.get(rpc_code, exceptions.UNKNOWN)
267312

268313
def _error_code_to_exception_type(code):
269314
"""Maps a platform error code to an exception type."""

0 commit comments

Comments
 (0)