craft-ai-sdk 0.68.1rc1__py3-none-any.whl → 0.68.2rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of craft-ai-sdk might be problematic. Click here for more details.
- craft_ai_sdk/__init__.py +1 -1
- craft_ai_sdk/sdk.py +14 -3
- craft_ai_sdk/shared/authentication.py +2 -4
- {craft_ai_sdk-0.68.1rc1.dist-info → craft_ai_sdk-0.68.2rc1.dist-info}/METADATA +1 -1
- {craft_ai_sdk-0.68.1rc1.dist-info → craft_ai_sdk-0.68.2rc1.dist-info}/RECORD +8 -8
- {craft_ai_sdk-0.68.1rc1.dist-info → craft_ai_sdk-0.68.2rc1.dist-info}/LICENSE +0 -0
- {craft_ai_sdk-0.68.1rc1.dist-info → craft_ai_sdk-0.68.2rc1.dist-info}/WHEEL +0 -0
- {craft_ai_sdk-0.68.1rc1.dist-info → craft_ai_sdk-0.68.2rc1.dist-info}/entry_points.txt +0 -0
craft_ai_sdk/__init__.py
CHANGED
craft_ai_sdk/sdk.py
CHANGED
|
@@ -3,7 +3,7 @@ import sys
|
|
|
3
3
|
import time
|
|
4
4
|
import warnings
|
|
5
5
|
from abc import ABC, abstractmethod
|
|
6
|
-
from datetime import timedelta
|
|
6
|
+
from datetime import datetime, timedelta
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
9
|
import jwt
|
|
@@ -140,8 +140,9 @@ class CraftAiSdk(BaseCraftAiSdk):
|
|
|
140
140
|
_MULTIPART_PART_SIZE = int(
|
|
141
141
|
os.environ.get("CRAFT_AI__MULTIPART_PART_SIZE__B", str(38 * 256 * 1024))
|
|
142
142
|
)
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
# Default timeout of proxy network components
|
|
144
|
+
_access_token_margin = timedelta(seconds=120)
|
|
145
|
+
_version = "0.68.2rc1" # Would be better to share it somewhere
|
|
145
146
|
|
|
146
147
|
def __init__(
|
|
147
148
|
self,
|
|
@@ -285,11 +286,21 @@ class CraftAiSdk(BaseCraftAiSdk):
|
|
|
285
286
|
return self._session.post(url, json=data)
|
|
286
287
|
|
|
287
288
|
def _refresh_access_token(self):
|
|
289
|
+
# While a bit weird, those time calculations support any time configuration
|
|
290
|
+
# on the client & control. Incorrect local datetime should be supported.
|
|
291
|
+
token_refreshed_at = datetime.now()
|
|
288
292
|
response = self._query_refresh_access_token()
|
|
289
293
|
self._access_token = response["access_token"]
|
|
290
294
|
self._access_token_data = jwt.decode(
|
|
291
295
|
self._access_token, options={"verify_signature": False}
|
|
292
296
|
)
|
|
297
|
+
# `exp` & `iat` are both relative to control datetime.
|
|
298
|
+
# Diff between them is an absolute duration
|
|
299
|
+
token_validity_duration = timedelta(
|
|
300
|
+
seconds=self._access_token_data["exp"] - self._access_token_data["iat"]
|
|
301
|
+
)
|
|
302
|
+
# Adding that duration to local time gives a local expiration time.
|
|
303
|
+
self._access_token_valid_until = token_refreshed_at + token_validity_duration
|
|
293
304
|
|
|
294
305
|
def _clear_access_token(self):
|
|
295
306
|
self._access_token = None
|
|
@@ -19,10 +19,8 @@ def use_authentication(
|
|
|
19
19
|
@functools.wraps(action_func)
|
|
20
20
|
def wrapper(sdk, *args, headers=None, **kwargs):
|
|
21
21
|
actual_headers = None
|
|
22
|
-
if (
|
|
23
|
-
sdk.
|
|
24
|
-
or sdk._access_token_data["exp"]
|
|
25
|
-
< (datetime.now() + sdk._access_token_margin).timestamp()
|
|
22
|
+
if sdk._access_token_data is None or (
|
|
23
|
+
datetime.now() > sdk._access_token_valid_until - sdk._access_token_margin
|
|
26
24
|
):
|
|
27
25
|
sdk._refresh_access_token()
|
|
28
26
|
actual_headers = {"Authorization": f"Bearer {sdk._access_token}"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
craft_ai_sdk/__init__.py,sha256=
|
|
1
|
+
craft_ai_sdk/__init__.py,sha256=eFFCciMenzXHcefjgWH5c0zm394Bnnv3KxLYwpt0VwQ,366
|
|
2
2
|
craft_ai_sdk/constants.py,sha256=rH4JrGlTpbjjjNRrKhk5oScbj5G5INrcVza6Bb6kIzY,980
|
|
3
3
|
craft_ai_sdk/core/data_store.py,sha256=BPQalGcm6bujgkgu-MtNWWhKiJEg4MiVuCtByNbTbK8,9956
|
|
4
4
|
craft_ai_sdk/core/deployments.py,sha256=Hig0Z6tZXbaLxms9ENtKI4OG3ki7G4Iz3wGk2V2Gmfg,37731
|
|
@@ -14,8 +14,8 @@ craft_ai_sdk/core/users.py,sha256=q5et87q0SOMpRTBOiLX026oaEOTaY1aGqKdbUC51zbA,61
|
|
|
14
14
|
craft_ai_sdk/core/vector_database.py,sha256=cidA9R-KL9nYR7d7VqBx8o8pIu1Rdp3XYLZn6pnwmok,2397
|
|
15
15
|
craft_ai_sdk/exceptions.py,sha256=IC-JfZmmmaTsbMCgirOEByRmWnatQLjKe8BErRkuwM0,1075
|
|
16
16
|
craft_ai_sdk/io.py,sha256=x1G7ga10W_SeTDLHe-FrhU26_WNwWW32-yprMmCZ5Ck,11836
|
|
17
|
-
craft_ai_sdk/sdk.py,sha256
|
|
18
|
-
craft_ai_sdk/shared/authentication.py,sha256=
|
|
17
|
+
craft_ai_sdk/sdk.py,sha256=-BuLBOOlzg7CFHimo26cMnz5Ax_eZbfZOaxKWdjOT_0,11717
|
|
18
|
+
craft_ai_sdk/shared/authentication.py,sha256=mnsEhG0mWwG9ZY-GToHDNnYERoou_cjt4k8l_87QW6s,1024
|
|
19
19
|
craft_ai_sdk/shared/environments.py,sha256=JOV3s0KIFVl_zskJb--bybzIXEGQJjrf_T4dL-szSlQ,500
|
|
20
20
|
craft_ai_sdk/shared/execution_context.py,sha256=B2Ghq-wiUvq81q5mhsm79Oc59c8c00uQxMIpApFD03o,585
|
|
21
21
|
craft_ai_sdk/shared/helpers.py,sha256=5ZBiHlS-k1OgKejZgMlDJiYwIPYk7yg-lzeJI67poCc,1070
|
|
@@ -27,8 +27,8 @@ craft_ai_sdk/utils/__init__.py,sha256=A0sLCXSPD1Z3q2GP1uLDjvif4ivOr__Hzg9RQysEuq
|
|
|
27
27
|
craft_ai_sdk/utils/datetime_utils.py,sha256=yYP5HVdI879WXxQCajPTnas1pWrwInOxMux-mxqQNQM,734
|
|
28
28
|
craft_ai_sdk/utils/dict_utils.py,sha256=1HQ3A14SN48XPFDmQleujGAgksmkjIs3hyPLpwhwh24,748
|
|
29
29
|
craft_ai_sdk/utils/file_utils.py,sha256=o10-CDt4qzgCJNPykvlNrL6WTouhVLY8C8BVpHJYt18,2795
|
|
30
|
-
craft_ai_sdk-0.68.
|
|
31
|
-
craft_ai_sdk-0.68.
|
|
32
|
-
craft_ai_sdk-0.68.
|
|
33
|
-
craft_ai_sdk-0.68.
|
|
34
|
-
craft_ai_sdk-0.68.
|
|
30
|
+
craft_ai_sdk-0.68.2rc1.dist-info/LICENSE,sha256=_2oYRJic9lZK05LceuJ9aZZw5mPHYc1WQhJiVS-oGFU,10754
|
|
31
|
+
craft_ai_sdk-0.68.2rc1.dist-info/METADATA,sha256=DbN2rnk6mZMqGMKju5vc0tPeAW6yQ51OX63LxQOleEg,1679
|
|
32
|
+
craft_ai_sdk-0.68.2rc1.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
33
|
+
craft_ai_sdk-0.68.2rc1.dist-info/entry_points.txt,sha256=QC96WcXvvUfLMRgFD-l_y7_TgC9SqZybLs9EQ8dsGiQ,417
|
|
34
|
+
craft_ai_sdk-0.68.2rc1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|