Skip to content

Commit 1923fe6

Browse files
authored
Fix Speakeasy targets in GitHub actions (#312)
This commit fixes the CI for GCP and Azure SDKs: * The GitHub actions now reference the correct Speakeasy targets * Fixes issues in packages/mistralai_gcp/src/mistralai_private_gcp/sdk.py (not tracked by Speakeasy since we added gcloud authentication) * Dropped the use of SDKError for non-HTTP errors (it now expects a raw_response in its constructor and internally makes accesses to its attributes). They have been replaced with ValueError when relevant (aligned with elsewhere in the SDK for invalid inputs) or basic Exceptions. * Changed the return type GoogleCloudBeforeRequestHook#before_request to a union like in the base class.
1 parent f3ad2f1 commit 1923fe6

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

.github/workflows/sdk_generation_mistralai_azure_sdk.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
mode: pr
2323
set_version: ${{ github.event.inputs.set_version }}
2424
speakeasy_version: latest
25-
target: mistral-python-sdk-azure
25+
target: mistralai-azure-sdk
2626
secrets:
2727
github_access_token: ${{ secrets.GITHUB_TOKEN }}
2828
pypi_token: ${{ secrets.PYPI_TOKEN }}

.github/workflows/sdk_generation_mistralai_gcp_sdk.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
mode: pr
2323
set_version: ${{ github.event.inputs.set_version }}
2424
speakeasy_version: latest
25-
target: mistral-python-sdk-google-cloud
25+
target: mistralai-gcp-sdk
2626
secrets:
2727
github_access_token: ${{ secrets.GITHUB_TOKEN }}
2828
pypi_token: ${{ secrets.PYPI_TOKEN }}

packages/mistralai_gcp/src/mistralai_gcp/sdk.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import json
44
import weakref
5-
from typing import Any, Optional, cast
5+
from typing import Any, Optional, Union, cast
66

77
import google.auth
88
import google.auth.credentials
@@ -67,30 +67,32 @@ def __init__(
6767
:param timeout_ms: Optional request timeout applied to each operation in milliseconds
6868
"""
6969

70+
credentials = None
7071
if not access_token:
7172
credentials, loaded_project_id = google.auth.default(
7273
scopes=["https://www.googleapis.com/auth/cloud-platform"],
7374
)
74-
credentials.refresh(google.auth.transport.requests.Request())
7575

76-
if not isinstance(credentials, google.auth.credentials.Credentials):
77-
raise models.SDKError(
78-
"credentials must be an instance of google.auth.credentials.Credentials"
79-
)
76+
# default will already raise a google.auth.exceptions.DefaultCredentialsError if no credentials are found
77+
assert isinstance(
78+
credentials, google.auth.credentials.Credentials
79+
), "credentials must be an instance of google.auth.credentials.Credentials"
8080

81+
credentials.refresh(google.auth.transport.requests.Request())
8182
project_id = project_id or loaded_project_id
8283

8384
if project_id is None:
84-
raise models.SDKError("project_id must be provided")
85+
raise ValueError("project_id must be provided")
8586

8687
def auth_token() -> str:
8788
if access_token:
8889
return access_token
8990

91+
assert credentials is not None, "credentials must be initialized"
9092
credentials.refresh(google.auth.transport.requests.Request())
9193
token = credentials.token
9294
if not token:
93-
raise models.SDKError("Failed to get token from credentials")
95+
raise Exception("Failed to get token from credentials")
9496
return token
9597

9698
client_supplied = True
@@ -197,7 +199,7 @@ def __init__(self, region: str, project_id: str):
197199

198200
def before_request(
199201
self, hook_ctx, request: httpx.Request
200-
) -> httpx.Request | Exception:
202+
) -> Union[httpx.Request, Exception]:
201203
# The goal of this function is to template in the region, project and model into the URL path
202204
# We do this here so that the API remains more user-friendly
203205
model_id = None
@@ -210,7 +212,7 @@ def before_request(
210212
new_content = json.dumps(parsed).encode("utf-8")
211213

212214
if model_id == "":
213-
raise models.SDKError("model must be provided")
215+
raise ValueError("model must be provided")
214216

215217
stream = "streamRawPredict" in request.url.path
216218
specifier = "streamRawPredict" if stream else "rawPredict"

0 commit comments

Comments
 (0)