-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support raw_predict for Endpoint (#1620)
* feat: support raw_predict for Endpoints * formatting * fixed broken unit test * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * remove commented out code blocks * removing debug print statements * removing extra prints * update copyright header date * removing automatically added python 3.6 support for kokoro * addressed PR comments * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding unit test * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * removed unused import * renamed raw predict constants * modified error messages * added doc strings * fixed typo in doc strings * removed extra space Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: nayaknishant <nishantnayak@google.com>
- Loading branch information
1 parent
39e3be9
commit cc7c968
Showing
7 changed files
with
229 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import json | ||
|
||
from google.cloud import aiplatform | ||
|
||
from tests.system.aiplatform import e2e_base | ||
|
||
_PERMANENT_IRIS_ENDPOINT_ID = "4966625964059525120" | ||
_PREDICTION_INSTANCE = { | ||
"petal_length": "3.0", | ||
"petal_width": "3.0", | ||
"sepal_length": "3.0", | ||
"sepal_width": "3.0", | ||
} | ||
|
||
|
||
class TestModelInteractions(e2e_base.TestEndToEnd): | ||
_temp_prefix = "" | ||
endpoint = aiplatform.Endpoint(_PERMANENT_IRIS_ENDPOINT_ID) | ||
|
||
def test_prediction(self): | ||
# test basic predict | ||
prediction_response = self.endpoint.predict(instances=[_PREDICTION_INSTANCE]) | ||
assert len(prediction_response.predictions) == 1 | ||
|
||
# test predict(use_raw_predict = True) | ||
prediction_with_raw_predict = self.endpoint.predict( | ||
instances=[_PREDICTION_INSTANCE], use_raw_predict=True | ||
) | ||
assert ( | ||
prediction_with_raw_predict.deployed_model_id | ||
== prediction_response.deployed_model_id | ||
) | ||
assert ( | ||
prediction_with_raw_predict.model_resource_name | ||
== prediction_response.model_resource_name | ||
) | ||
|
||
# test raw_predict | ||
raw_prediction_response = self.endpoint.raw_predict( | ||
json.dumps({"instances": [_PREDICTION_INSTANCE]}), | ||
{"Content-Type": "application/json"}, | ||
) | ||
assert raw_prediction_response.status_code == 200 | ||
assert len(json.loads(raw_prediction_response.text)) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.