craft-ai-sdk 0.64.0__py3-none-any.whl → 0.64.1__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.
- craft_ai_sdk/__init__.py +1 -1
- craft_ai_sdk/core/endpoints.py +50 -21
- craft_ai_sdk/core/pipeline_executions.py +16 -2
- craft_ai_sdk/sdk.py +2 -1
- {craft_ai_sdk-0.64.0.dist-info → craft_ai_sdk-0.64.1.dist-info}/METADATA +1 -1
- {craft_ai_sdk-0.64.0.dist-info → craft_ai_sdk-0.64.1.dist-info}/RECORD +9 -9
- {craft_ai_sdk-0.64.0.dist-info → craft_ai_sdk-0.64.1.dist-info}/LICENSE +0 -0
- {craft_ai_sdk-0.64.0.dist-info → craft_ai_sdk-0.64.1.dist-info}/WHEEL +0 -0
- {craft_ai_sdk-0.64.0.dist-info → craft_ai_sdk-0.64.1.dist-info}/entry_points.txt +0 -0
craft_ai_sdk/__init__.py
CHANGED
craft_ai_sdk/core/endpoints.py
CHANGED
|
@@ -8,6 +8,7 @@ from ..sdk import BaseCraftAiSdk
|
|
|
8
8
|
from ..shared.logger import log_func_result
|
|
9
9
|
from ..shared.request_response_handler import handle_http_response
|
|
10
10
|
from .deployments import get_deployment
|
|
11
|
+
from ..shared.authentication import use_authentication
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
def _get_endpoint_url_path(sdk: BaseCraftAiSdk, endpoint_name: str):
|
|
@@ -55,7 +56,7 @@ def trigger_endpoint(
|
|
|
55
56
|
def trigger_endpoint(
|
|
56
57
|
sdk: BaseCraftAiSdk,
|
|
57
58
|
endpoint_name: str,
|
|
58
|
-
endpoint_token: str,
|
|
59
|
+
endpoint_token: Union[str, None] = None,
|
|
59
60
|
inputs: Union[dict[str, Any], None] = None,
|
|
60
61
|
wait_for_completion=True,
|
|
61
62
|
) -> Union[EndpointTriggerWithOutputs, EndpointTriggerBase]:
|
|
@@ -63,7 +64,8 @@ def trigger_endpoint(
|
|
|
63
64
|
|
|
64
65
|
Args:
|
|
65
66
|
endpoint_name (:obj:`str`): Name of the endpoint.
|
|
66
|
-
endpoint_token (:obj:`str
|
|
67
|
+
endpoint_token (:obj:`str`, optional): Token to access endpoint. If not set,
|
|
68
|
+
the SDK token will be used.
|
|
67
69
|
inputs (:obj:`dict`, optional): Dictionary of inputs to pass to the endpoint
|
|
68
70
|
with input names as keys and corresponding values as values.
|
|
69
71
|
For files, the value should be an instance of io.IOBase.
|
|
@@ -85,7 +87,6 @@ def trigger_endpoint(
|
|
|
85
87
|
"""
|
|
86
88
|
if inputs is None:
|
|
87
89
|
inputs = {}
|
|
88
|
-
endpoint_url_path = _get_endpoint_url_path(sdk, endpoint_name)
|
|
89
90
|
|
|
90
91
|
body = {}
|
|
91
92
|
files = {}
|
|
@@ -95,19 +96,36 @@ def trigger_endpoint(
|
|
|
95
96
|
else:
|
|
96
97
|
body[input_name] = input_value
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
if endpoint_token is None:
|
|
100
|
+
url = (
|
|
101
|
+
f"{sdk.base_environment_api_url}" f"/deployments/{endpoint_name}/executions"
|
|
102
|
+
)
|
|
103
|
+
do_post = use_authentication(
|
|
104
|
+
lambda sdk, *args, **kwargs: sdk._session.post(*args, **kwargs)
|
|
105
|
+
)
|
|
106
|
+
post_result = do_post(
|
|
107
|
+
sdk,
|
|
108
|
+
url,
|
|
109
|
+
allow_redirects=False,
|
|
110
|
+
json=body,
|
|
111
|
+
files=files,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
else:
|
|
115
|
+
endpoint_url_path = _get_endpoint_url_path(sdk, endpoint_name)
|
|
116
|
+
url = f"{sdk.base_environment_url}/endpoints/{endpoint_url_path}"
|
|
117
|
+
post_result = requests.post(
|
|
118
|
+
url,
|
|
119
|
+
headers={
|
|
120
|
+
"Authorization": f"EndpointToken {endpoint_token}",
|
|
121
|
+
"craft-ai-client": f"craft-ai-sdk@{sdk._version}",
|
|
122
|
+
},
|
|
123
|
+
allow_redirects=False,
|
|
124
|
+
json=body,
|
|
125
|
+
files=files,
|
|
126
|
+
)
|
|
127
|
+
response = handle_http_response(post_result)
|
|
128
|
+
execution_id = response.get("execution_id", "")
|
|
111
129
|
if wait_for_completion and 200 <= post_result.status_code < 400:
|
|
112
130
|
return retrieve_endpoint_results(
|
|
113
131
|
sdk,
|
|
@@ -123,7 +141,7 @@ def retrieve_endpoint_results(
|
|
|
123
141
|
sdk: BaseCraftAiSdk,
|
|
124
142
|
endpoint_name: str,
|
|
125
143
|
execution_id: str,
|
|
126
|
-
endpoint_token: str,
|
|
144
|
+
endpoint_token: Union[str, None] = None,
|
|
127
145
|
) -> EndpointTriggerWithOutputs:
|
|
128
146
|
"""Get the results of an endpoint execution.
|
|
129
147
|
|
|
@@ -131,7 +149,8 @@ def retrieve_endpoint_results(
|
|
|
131
149
|
endpoint_name (:obj:`str`): Name of the endpoint.
|
|
132
150
|
execution_id (:obj:`str`): ID of the execution returned by
|
|
133
151
|
`trigger_endpoint`.
|
|
134
|
-
endpoint_token (:obj:`str
|
|
152
|
+
endpoint_token (:obj:`str`, optional): Token to access endpoint. If not set,
|
|
153
|
+
the SDK token will be used.
|
|
135
154
|
|
|
136
155
|
Returns:
|
|
137
156
|
:obj:`dict`: Created pipeline execution represented as :obj:`dict` with the
|
|
@@ -140,6 +159,10 @@ def retrieve_endpoint_results(
|
|
|
140
159
|
* ``"outputs"`` (:obj:`dict`): Dictionary of outputs of the pipeline with
|
|
141
160
|
output names as keys and corresponding values as values.
|
|
142
161
|
"""
|
|
162
|
+
|
|
163
|
+
if endpoint_token is None:
|
|
164
|
+
return sdk.retrieve_pipeline_execution_outputs(execution_id)
|
|
165
|
+
|
|
143
166
|
endpoint_url_path = _get_endpoint_url_path(sdk, endpoint_name)
|
|
144
167
|
|
|
145
168
|
url = (
|
|
@@ -149,11 +172,13 @@ def retrieve_endpoint_results(
|
|
|
149
172
|
query = urlencode({"token": endpoint_token})
|
|
150
173
|
response = requests.get(f"{url}?{query}")
|
|
151
174
|
|
|
175
|
+
handled_response = handle_http_response(response)
|
|
176
|
+
|
|
152
177
|
# 500 is returned if the pipeline failed too. In that case, it is not a
|
|
153
178
|
# standard API error
|
|
154
179
|
if response.status_code == 500:
|
|
155
180
|
try:
|
|
156
|
-
return
|
|
181
|
+
return handled_response
|
|
157
182
|
except KeyError:
|
|
158
183
|
return response.json()
|
|
159
184
|
|
|
@@ -161,11 +186,15 @@ def retrieve_endpoint_results(
|
|
|
161
186
|
content_disposition = response.headers.get("Content-Disposition", "")
|
|
162
187
|
output_name = content_disposition.split(f"_{execution_id}_")[1]
|
|
163
188
|
return {
|
|
164
|
-
"outputs": {output_name:
|
|
189
|
+
"outputs": {output_name: handled_response},
|
|
165
190
|
"execution_id": execution_id,
|
|
166
191
|
}
|
|
167
192
|
else:
|
|
168
|
-
|
|
193
|
+
response_data = handle_http_response(response)
|
|
194
|
+
return {
|
|
195
|
+
"outputs": response_data.get("outputs", []),
|
|
196
|
+
"execution_id": execution_id,
|
|
197
|
+
}
|
|
169
198
|
|
|
170
199
|
|
|
171
200
|
def generate_new_endpoint_token(
|
|
@@ -106,12 +106,26 @@ Its execution ID is "{execution_id}".',
|
|
|
106
106
|
|
|
107
107
|
# Wait for pipeline execution to finish
|
|
108
108
|
if wait_for_completion:
|
|
109
|
-
return
|
|
109
|
+
return retrieve_pipeline_execution_outputs(sdk, execution_id)
|
|
110
110
|
return {"execution_id": execution_id}
|
|
111
111
|
|
|
112
112
|
|
|
113
113
|
@log_func_result("Pipeline execution results retrieval")
|
|
114
|
-
def
|
|
114
|
+
def retrieve_pipeline_execution_outputs(sdk: BaseCraftAiSdk, execution_id):
|
|
115
|
+
"""Get the results of a pipeline execution.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
execution_id (:obj:`str`): Name of the pipeline execution.
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
:obj:`dict`: Created pipeline execution represented as :obj:`dict` with the
|
|
122
|
+
following keys:
|
|
123
|
+
|
|
124
|
+
* ``execution_id`` (str): Name of the pipeline execution.
|
|
125
|
+
* ``"outputs"`` (:obj:`dict`): Dictionary of outputs of the pipeline with
|
|
126
|
+
output names as keys and corresponding values as values.
|
|
127
|
+
"""
|
|
128
|
+
|
|
115
129
|
url = (
|
|
116
130
|
f"{sdk.base_environment_api_url}"
|
|
117
131
|
f"/executions/{execution_id}/outputs?wait_for_completion=true"
|
craft_ai_sdk/sdk.py
CHANGED
|
@@ -93,6 +93,7 @@ class CraftAiSdk(BaseCraftAiSdk):
|
|
|
93
93
|
get_pipeline_execution_output,
|
|
94
94
|
list_pipeline_executions,
|
|
95
95
|
run_pipeline,
|
|
96
|
+
retrieve_pipeline_execution_outputs,
|
|
96
97
|
)
|
|
97
98
|
from .core.pipeline_metrics import (
|
|
98
99
|
get_list_metrics,
|
|
@@ -138,7 +139,7 @@ class CraftAiSdk(BaseCraftAiSdk):
|
|
|
138
139
|
os.environ.get("CRAFT_AI__MULTIPART_PART_SIZE__B", str(38 * 256 * 1024))
|
|
139
140
|
)
|
|
140
141
|
_access_token_margin = timedelta(seconds=30)
|
|
141
|
-
_version = "0.64.
|
|
142
|
+
_version = "0.64.1" # Would be better to share it somewhere
|
|
142
143
|
|
|
143
144
|
def __init__(
|
|
144
145
|
self,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
craft_ai_sdk/__init__.py,sha256=
|
|
1
|
+
craft_ai_sdk/__init__.py,sha256=1B7fdloJQsWnPA90TMoCRarnHriveRHWvgHMlU8CCfw,363
|
|
2
2
|
craft_ai_sdk/constants.py,sha256=rH4JrGlTpbjjjNRrKhk5oScbj5G5INrcVza6Bb6kIzY,980
|
|
3
3
|
craft_ai_sdk/core/data_store.py,sha256=dlVZajXGwcI_4mzqFctHpzKO-uySIP5lvQaJy6CKwY0,9131
|
|
4
4
|
craft_ai_sdk/core/deployments.py,sha256=-XMPQJ9ZMmd3i7gEAQB7kONfScg-8JqVAD9VI1fQNEQ,37174
|
|
5
|
-
craft_ai_sdk/core/endpoints.py,sha256=
|
|
5
|
+
craft_ai_sdk/core/endpoints.py,sha256=cB4MgEr5L0XVS_QtE1ewsFqq586NZoxqeI-ZINSS9R8,7034
|
|
6
6
|
craft_ai_sdk/core/environment_variables.py,sha256=FYxwWqz8XdmxWuJLI3MP9QOObWwly3P4k6lon-KHUmU,2224
|
|
7
|
-
craft_ai_sdk/core/pipeline_executions.py,sha256=
|
|
7
|
+
craft_ai_sdk/core/pipeline_executions.py,sha256=uasCxQewvD4pYXRSPhYQnrApFVzL5covsN1tbJkxtT8,18624
|
|
8
8
|
craft_ai_sdk/core/pipeline_metrics.py,sha256=cyDuhQCGVRMruo-ZGGd9vfQB0rbNu8Fs1sQxnfk6Aow,7174
|
|
9
9
|
craft_ai_sdk/core/pipelines.py,sha256=QrpCH9Yn6SA92xyDfF0Te-iumtkhlNRLtQAiztqcl6o,21574
|
|
10
10
|
craft_ai_sdk/core/resource_metrics.py,sha256=jwxDZJIhj28rpmFJKopt_1O0X58TGjUThRpAeMvVz1Y,3455
|
|
@@ -13,7 +13,7 @@ craft_ai_sdk/core/users.py,sha256=OBwOrjE2hrqQde28ZItGxNDj52dhKY-mxabkbLaMnGQ,61
|
|
|
13
13
|
craft_ai_sdk/core/vector_database.py,sha256=JQsz7Rj8HL9tmB8y4lSsAd3IPnuVMX2LpAK1z8yrz9M,2323
|
|
14
14
|
craft_ai_sdk/exceptions.py,sha256=IC-JfZmmmaTsbMCgirOEByRmWnatQLjKe8BErRkuwM0,1075
|
|
15
15
|
craft_ai_sdk/io.py,sha256=4BlUV2Rf3Y8YXMC2mRdUqbI8EzvbgkrLB-cbcrv2gco,13468
|
|
16
|
-
craft_ai_sdk/sdk.py,sha256=
|
|
16
|
+
craft_ai_sdk/sdk.py,sha256=3E--Ta-02FKIE1S5dAq0h_6SFA7wENn5vlb72BZplfY,10781
|
|
17
17
|
craft_ai_sdk/shared/authentication.py,sha256=OdwtAH47tOUS-u_HhxlI8JdjZT5REr5B5cGSrX7sz00,885
|
|
18
18
|
craft_ai_sdk/shared/environments.py,sha256=NI7DgQa4uj1PnffJUZ1Q4Car4r9OoFdXpYod26xgOIo,547
|
|
19
19
|
craft_ai_sdk/shared/execution_context.py,sha256=B2Ghq-wiUvq81q5mhsm79Oc59c8c00uQxMIpApFD03o,585
|
|
@@ -26,8 +26,8 @@ craft_ai_sdk/utils/__init__.py,sha256=A0sLCXSPD1Z3q2GP1uLDjvif4ivOr__Hzg9RQysEuq
|
|
|
26
26
|
craft_ai_sdk/utils/datetime_utils.py,sha256=ziWQ2Xa_ypKIm50F_1R5OtubXSNlM4JWbFUeh7qjwpE,672
|
|
27
27
|
craft_ai_sdk/utils/dict_utils.py,sha256=1HQ3A14SN48XPFDmQleujGAgksmkjIs3hyPLpwhwh24,748
|
|
28
28
|
craft_ai_sdk/utils/file_utils.py,sha256=dKn8NzrCMc5nn0ptUL6VuUOvLo474NJFWrVBe7ccYI8,2256
|
|
29
|
-
craft_ai_sdk-0.64.
|
|
30
|
-
craft_ai_sdk-0.64.
|
|
31
|
-
craft_ai_sdk-0.64.
|
|
32
|
-
craft_ai_sdk-0.64.
|
|
33
|
-
craft_ai_sdk-0.64.
|
|
29
|
+
craft_ai_sdk-0.64.1.dist-info/LICENSE,sha256=_2oYRJic9lZK05LceuJ9aZZw5mPHYc1WQhJiVS-oGFU,10754
|
|
30
|
+
craft_ai_sdk-0.64.1.dist-info/METADATA,sha256=A2IgdNLdxMtj3u5u9BssLEXTYfQ9JWapuu9o7VM_nOo,1676
|
|
31
|
+
craft_ai_sdk-0.64.1.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
32
|
+
craft_ai_sdk-0.64.1.dist-info/entry_points.txt,sha256=eV9YD0zCAb88_wNMDV99sRxVKVC-WOQF3b1Pepaytcg,385
|
|
33
|
+
craft_ai_sdk-0.64.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|