From b7315e5b04c7d066e991f2c6cbf1de8c61f85b3b Mon Sep 17 00:00:00 2001 From: Harizo Rajaona Date: Tue, 27 Aug 2024 16:21:35 +0200 Subject: [PATCH] Only authenticate via gcloud if no access token is manually provided --- packages/mistralai_gcp/src/mistralai_gcp/sdk.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/mistralai_gcp/src/mistralai_gcp/sdk.py b/packages/mistralai_gcp/src/mistralai_gcp/sdk.py index 446d5285..262f60e8 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/sdk.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/sdk.py @@ -46,16 +46,17 @@ def __init__( :param async_client: The Async HTTP client to use for all asynchronous methods :param retry_config: The retry configuration to use for all supported methods """ - - credentials, loaded_project_id = google.auth.default( - scopes=["https://www.googleapis.com/auth/cloud-platform"], - ) - credentials.refresh(google.auth.transport.requests.Request()) - if not isinstance(credentials, google.auth.credentials.Credentials): - raise models.SDKError( - "credentials must be an instance of google.auth.credentials.Credentials" + if not access_token: + credentials, loaded_project_id = google.auth.default( + scopes=["https://www.googleapis.com/auth/cloud-platform"], ) + credentials.refresh(google.auth.transport.requests.Request()) + + if not isinstance(credentials, google.auth.credentials.Credentials): + raise models.SDKError( + "credentials must be an instance of google.auth.credentials.Credentials" + ) project_id = project_id or loaded_project_id if project_id is None: