-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Deprecation of AutoML services: Add deprecation warnings and raise exceptions for already deprecated ones #38673
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
91 changes: 91 additions & 0 deletions
91
airflow/providers/google/cloud/hooks/vertex_ai/prediction_service.py
This file contains hidden or 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,91 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING, Sequence | ||
|
|
||
| from google.api_core.client_options import ClientOptions | ||
| from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault | ||
| from google.cloud.aiplatform_v1 import PredictionServiceClient | ||
|
|
||
| from airflow.providers.google.common.consts import CLIENT_INFO | ||
| from airflow.providers.google.common.hooks.base_google import PROVIDE_PROJECT_ID, GoogleBaseHook | ||
|
|
||
| if TYPE_CHECKING: | ||
| from google.api_core.retry import Retry | ||
| from google.cloud.aiplatform_v1.types import PredictResponse | ||
|
|
||
|
|
||
| class PredictionServiceHook(GoogleBaseHook): | ||
potiuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Hook for Google Cloud Vertex AI Prediction API.""" | ||
|
|
||
| def get_prediction_service_client(self, region: str | None = None) -> PredictionServiceClient: | ||
| """ | ||
| Return PredictionServiceClient object. | ||
|
|
||
| :param region: The ID of the Google Cloud region that the service belongs to. Default is None. | ||
|
|
||
| :return: `google.cloud.aiplatform_v1.services.prediction_service.client.PredictionServiceClient` instance. | ||
| """ | ||
| if region and region != "global": | ||
| client_options = ClientOptions(api_endpoint=f"{region}-aiplatform.googleapis.com:443") | ||
| else: | ||
| client_options = ClientOptions() | ||
|
|
||
| return PredictionServiceClient( | ||
| credentials=self.get_credentials(), client_info=CLIENT_INFO, client_options=client_options | ||
| ) | ||
|
|
||
| @GoogleBaseHook.fallback_to_default_project_id | ||
| def predict( | ||
| self, | ||
| endpoint_id: str, | ||
| instances: list[str], | ||
| location: str, | ||
| project_id: str = PROVIDE_PROJECT_ID, | ||
| parameters: dict[str, str] | None = None, | ||
| retry: Retry | _MethodDefault = DEFAULT, | ||
| timeout: float | None = None, | ||
| metadata: Sequence[tuple[str, str]] = (), | ||
| ) -> PredictResponse: | ||
| """ | ||
| Perform an online prediction and returns the prediction result in the response. | ||
|
|
||
| :param endpoint_id: Name of the endpoint_id requested to serve the prediction. | ||
| :param instances: Required. The instances that are the input to the prediction call. A DeployedModel | ||
| may have an upper limit on the number of instances it supports per request, and when it is | ||
| exceeded the prediction call errors in case of AutoML Models, or, in case of customer created | ||
| Models, the behaviour is as documented by that Model. | ||
| :param parameters: Additional domain-specific parameters, any string must be up to 25000 characters long. | ||
| :param project_id: ID of the Google Cloud project where model is located if None then | ||
| default project_id is used. | ||
| :param location: The location of the project. | ||
| :param retry: A retry object used to retry requests. If `None` is specified, requests will not be | ||
| retried. | ||
| :param timeout: The amount of time, in seconds, to wait for the request to complete. Note that if | ||
| `retry` is specified, the timeout applies to each individual attempt. | ||
| :param metadata: Additional metadata that is provided to the method. | ||
| """ | ||
| client = self.get_prediction_service_client(location) | ||
| endpoint = f"projects/{project_id}/locations/{location}/endpoints/{endpoint_id}" | ||
| return client.predict( | ||
| request={"endpoint": endpoint, "instances": instances, "parameters": parameters}, | ||
| retry=retry, | ||
| timeout=timeout, | ||
| metadata=metadata, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.