Skip to content

Commit e1db225

Browse files
committed
GCP improvements
- Pin google-auth to 2.27.0 to fix conflicts in Colab notebooks - Enable passing a user-provided access token to MistralGoogleCloud
1 parent f62530a commit e1db225

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

packages/mistralai_gcp/poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/mistralai_gcp/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ in-project = true
1818
[tool.poetry.dependencies]
1919
python = "^3.8"
2020
eval-type-backport = "^0.2.0"
21-
google-auth = "^2.31.0"
21+
google-auth = "2.27.0"
2222
httpx = "^0.27.0"
2323
jsonpath-python = "^1.0.6"
2424
pydantic = "~2.8.2"

packages/mistralai_gcp/src/mistralai_gcp/sdk.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(
3232
self,
3333
region: str = "europe-west4",
3434
project_id: Optional[str] = None,
35+
access_token: Optional[str] = None,
3536
client: Optional[HttpClient] = None,
3637
async_client: Optional[AsyncHttpClient] = None,
3738
retry_config: Optional[Nullable[RetryConfig]] = None,
@@ -45,10 +46,11 @@ def __init__(
4546
:param async_client: The Async HTTP client to use for all asynchronous methods
4647
:param retry_config: The retry configuration to use for all supported methods
4748
"""
48-
49+
4950
credentials, loaded_project_id = google.auth.default(
5051
scopes=["https://www.googleapis.com/auth/cloud-platform"],
5152
)
53+
credentials.refresh(google.auth.transport.requests.Request())
5254

5355
if not isinstance(credentials, google.auth.credentials.Credentials):
5456
raise models.SDKError(
@@ -60,12 +62,14 @@ def __init__(
6062
raise models.SDKError("project_id must be provided")
6163

6264
def auth_token() -> str:
63-
if credentials.expired:
65+
if access_token:
66+
return access_token
67+
else:
6468
credentials.refresh(google.auth.transport.requests.Request())
65-
token = credentials.token
66-
if not token:
67-
raise models.SDKError("Failed to get token from credentials")
68-
return token
69+
token = credentials.token
70+
if not token:
71+
raise models.SDKError("Failed to get token from credentials")
72+
return token
6973

7074
if client is None:
7175
client = httpx.Client()

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jsonpath-python = "^1.0.6"
2121
pydantic = "~2.8.2"
2222
python-dateutil = "^2.9.0.post0"
2323
typing-inspect = "^0.9.0"
24-
google-auth = { version = "^2.31.0", optional = true }
24+
google-auth = { version = "2.27.0", optional = true }
2525
requests = { version = "^2.32.3", optional = true }
2626

2727
[tool.poetry.group.dev.dependencies]

0 commit comments

Comments
 (0)