Skip to content

Commit a8b24ad

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
fix: when user is not logged in, throw more intuitive message
PiperOrigin-RevId: 589211410
1 parent 7dc8771 commit a8b24ad

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

vertexai/_model_garden/_model_garden_models.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import dataclasses
1919
from typing import Dict, Optional, Type, TypeVar
20+
from google.auth import exceptions as auth_exceptions
2021

2122
from google.cloud import aiplatform
2223
from google.cloud.aiplatform import base
@@ -320,4 +321,17 @@ def from_pretrained(cls: Type[T], model_name: str) -> T:
320321
ValueError: If model does not support this class.
321322
"""
322323

323-
return _from_pretrained(interface_class=cls, model_name=model_name)
324+
credential_exception_str = (
325+
"\nUnable to authenticate your request."
326+
"\nDepending on your runtime environment, you can complete authentication by:"
327+
"\n- if in local JupyterLab instance: `!gcloud auth login` "
328+
"\n- if in Colab:"
329+
"\n -`from google.colab import auth`"
330+
"\n -`auth.authenticate_user()`"
331+
"\n- if in service account or other: please follow guidance in https://cloud.google.com/docs/authentication"
332+
)
333+
334+
try:
335+
return _from_pretrained(interface_class=cls, model_name=model_name)
336+
except auth_exceptions.GoogleAuthError as e:
337+
raise auth_exceptions.GoogleAuthError(credential_exception_str) from e

0 commit comments

Comments
 (0)