Skip to content

Commit 2e4430e

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Release API key support for Predict
FUTURE_COPYBARA_INTEGRATE_REVIEW=#5158 from googleapis:release-please--branches--main 8d20c2c PiperOrigin-RevId: 734290755
1 parent 0cb2b93 commit 2e4430e

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

google/cloud/aiplatform/models.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def __init__(
210210
will be used.
211211
"""
212212

213+
print("project: " + project or "None" + " location: " + location or "None")
213214
super().__init__(
214215
project=project,
215216
location=location,
@@ -662,7 +663,9 @@ def __init__(
662663
endpoint_name (str):
663664
Required. A fully-qualified endpoint resource name or endpoint ID.
664665
Example: "projects/123/locations/us-central1/endpoints/456" or
665-
"456" when project and location are initialized or passed.
666+
"456" when project and location are initialized or passed. If
667+
project and location are not passed, the endpoint_name is assumed
668+
to be fully-qualified.
666669
project (str):
667670
Optional. Project to retrieve endpoint from. If not set, project
668671
set in aiplatform.init will be used.
@@ -681,14 +684,15 @@ def __init__(
681684
resource_name=endpoint_name,
682685
)
683686

684-
endpoint_name = utils.full_resource_name(
685-
resource_name=endpoint_name,
686-
resource_noun="endpoints",
687-
parse_resource_name_method=self._parse_resource_name,
688-
format_resource_name_method=self._format_resource_name,
689-
project=project,
690-
location=location,
691-
)
687+
if project or initializer.global_config.project:
688+
endpoint_name = utils.full_resource_name(
689+
resource_name=endpoint_name,
690+
resource_noun="endpoints",
691+
parse_resource_name_method=self._parse_resource_name,
692+
format_resource_name_method=self._format_resource_name,
693+
project=project,
694+
location=location,
695+
)
692696

693697
# Lazy load the Endpoint gca_resource until needed
694698
self._gca_resource = gca_endpoint_compat.Endpoint(name=endpoint_name)
@@ -699,15 +703,19 @@ def __init__(
699703

700704
@property
701705
def _prediction_client(self) -> utils.PredictionClientWithOverride:
706+
api_key = initializer.global_config.api_key
707+
if api_key and initializer.global_config.project:
708+
api_key = None
702709
# The attribute might not exist due to issues in
703710
# `VertexAiResourceNounWithFutureManager._sync_object_with_future_result`
704711
# We should switch to @functools.cached_property once its available.
705712
if not getattr(self, "_prediction_client_value", None):
706713
self._prediction_client_value = initializer.global_config.create_client(
707714
client_class=utils.PredictionClientWithOverride,
708715
credentials=self.credentials,
709-
location_override=self.location,
716+
location_override=self.location if not api_key else None,
710717
prediction_client=True,
718+
api_key=api_key,
711719
)
712720
return self._prediction_client_value
713721

samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-aiplatform",
11-
"version": "0.1.0"
11+
"version": "1.89.0"
1212
},
1313
"snippets": [
1414
{

samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-aiplatform",
11-
"version": "0.1.0"
11+
"version": "1.89.0"
1212
},
1313
"snippets": [
1414
{

0 commit comments

Comments
 (0)