Skip to content

Commit 154ad6a

Browse files
committed
Stop using SDKError for non-HTTP errors during initialization
The generated SDKError now requires a raw_response, which we don't have in the init or hook.
1 parent fbc2661 commit 154ad6a

File tree

1 file changed

+10
-8
lines changed
  • packages/mistralai_gcp/src/mistralai_gcp

1 file changed

+10
-8
lines changed

packages/mistralai_gcp/src/mistralai_gcp/sdk.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -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)