Merge pull request #4445 from ushuz/fix-google-creds

fix: do not resolve vertex project id from creds
This commit is contained in:
Krish Dholakia 2024-06-27 21:31:59 -07:00 committed by GitHub
commit 6f030043e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -736,9 +736,6 @@ class VertexLLM(BaseLLM):
json_obj,
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
if project_id is None:
project_id = creds.project_id
else:
creds, project_id = google_auth.default(
quota_project_id=project_id,
@ -747,14 +744,6 @@ class VertexLLM(BaseLLM):
creds.refresh(Request())
if not project_id:
raise ValueError("Could not resolve project_id")
if not isinstance(project_id, str):
raise TypeError(
f"Expected project_id to be a str but got {type(project_id)}"
)
return creds, project_id
def refresh_auth(self, credentials: Any) -> None:
@ -770,28 +759,17 @@ class VertexLLM(BaseLLM):
"""
Returns auth token and project id
"""
if self.access_token is not None and self.project_id is not None:
return self.access_token, self.project_id
if not self._credentials:
self._credentials, project_id = self.load_auth(
self._credentials, _ = self.load_auth(
credentials=credentials, project_id=project_id
)
if not self.project_id:
self.project_id = project_id
else:
self.refresh_auth(self._credentials)
if not self.project_id:
self.project_id = self._credentials.project_id
if not self.project_id:
raise ValueError("Could not resolve project_id")
if not self._credentials or not self._credentials.token:
if not self._credentials.token:
raise RuntimeError("Could not resolve API token from the environment")
return self._credentials.token, self.project_id
return self._credentials.token, None
def _get_token_and_url(
self,
@ -825,7 +803,7 @@ class VertexLLM(BaseLLM):
)
)
else:
auth_header, vertex_project = self._ensure_access_token(
auth_header, _ = self._ensure_access_token(
credentials=vertex_credentials, project_id=vertex_project
)
vertex_location = self.get_vertex_region(vertex_region=vertex_location)