Skip to content

Commit

Permalink
fix(vertex): don't error if project_id couldn't be loaded if it was a…
Browse files Browse the repository at this point in the history
…lready explicitly given (#513)
  • Loading branch information
RobertCraigie authored May 22, 2024
1 parent 6cccfa7 commit e7159d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/anthropic/lib/vertex/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
# cause synchronous blocking issues.


def load_auth() -> tuple[Credentials, str]:
def load_auth(*, project_id: str | None) -> tuple[Credentials, str]:
from google.auth.transport.requests import Request # type: ignore[import-untyped]

credentials, project_id = google_auth.default(
credentials, loaded_project_id = google_auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
credentials.refresh(Request())

if not project_id:
project_id = loaded_project_id

if not project_id:
raise ValueError("Could not resolve project_id")

Expand Down
4 changes: 2 additions & 2 deletions src/anthropic/lib/vertex/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _ensure_access_token(self) -> str:
return self.access_token

if not self._credentials:
self._credentials, project_id = load_auth()
self._credentials, project_id = load_auth(project_id=self.project_id)
if not self.project_id:
self.project_id = project_id
else:
Expand Down Expand Up @@ -267,7 +267,7 @@ async def _ensure_access_token(self) -> str:
return self.access_token

if not self._credentials:
self._credentials, project_id = await asyncify(load_auth)()
self._credentials, project_id = await asyncify(load_auth)(project_id=self.project_id)
if not self.project_id:
self.project_id = project_id
else:
Expand Down

0 comments on commit e7159d8

Please sign in to comment.