Skip to content

feat: Release API key support for Predict #5031

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions google/cloud/aiplatform/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ def __init__(
will be used.
"""

if project:
print("project: " + project)

if location:
print("location: " + location)

super().__init__(
project=project,
location=location,
Expand Down Expand Up @@ -662,7 +668,9 @@ def __init__(
endpoint_name (str):
Required. A fully-qualified endpoint resource name or endpoint ID.
Example: "projects/123/locations/us-central1/endpoints/456" or
"456" when project and location are initialized or passed.
"456" when project and location are initialized or passed. If
project and location are not passed, the endpoint_name is assumed
to be fully-qualified.
project (str):
Optional. Project to retrieve endpoint from. If not set, project
set in aiplatform.init will be used.
Expand All @@ -681,14 +689,15 @@ def __init__(
resource_name=endpoint_name,
)

endpoint_name = utils.full_resource_name(
resource_name=endpoint_name,
resource_noun="endpoints",
parse_resource_name_method=self._parse_resource_name,
format_resource_name_method=self._format_resource_name,
project=project,
location=location,
)
if project or initializer.global_config.project:
endpoint_name = utils.full_resource_name(
resource_name=endpoint_name,
resource_noun="endpoints",
parse_resource_name_method=self._parse_resource_name,
format_resource_name_method=self._format_resource_name,
project=project,
location=location,
)

# Lazy load the Endpoint gca_resource until needed
self._gca_resource = gca_endpoint_compat.Endpoint(name=endpoint_name)
Expand All @@ -699,15 +708,19 @@ def __init__(

@property
def _prediction_client(self) -> utils.PredictionClientWithOverride:
api_key = initializer.global_config.api_key
if api_key and initializer.global_config.project:
api_key = None
# The attribute might not exist due to issues in
# `VertexAiResourceNounWithFutureManager._sync_object_with_future_result`
# We should switch to @functools.cached_property once its available.
if not getattr(self, "_prediction_client_value", None):
self._prediction_client_value = initializer.global_config.create_client(
client_class=utils.PredictionClientWithOverride,
credentials=self.credentials,
location_override=self.location,
location_override=self.location if not api_key else None,
prediction_client=True,
api_key=api_key,
)
return self._prediction_client_value

Expand Down