craft-ai-sdk 0.64.0__tar.gz → 0.64.1__tar.gz

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.

Files changed (33) hide show
  1. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/PKG-INFO +1 -1
  2. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/__init__.py +1 -1
  3. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/endpoints.py +50 -21
  4. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/pipeline_executions.py +16 -2
  5. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/sdk.py +2 -1
  6. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/documentation.pdf +0 -0
  7. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/pyproject.toml +1 -1
  8. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/LICENSE +0 -0
  9. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/README.md +0 -0
  10. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/constants.py +0 -0
  11. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/data_store.py +0 -0
  12. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/deployments.py +0 -0
  13. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/environment_variables.py +0 -0
  14. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/pipeline_metrics.py +0 -0
  15. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/pipelines.py +0 -0
  16. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/resource_metrics.py +0 -0
  17. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/steps.py +0 -0
  18. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/users.py +0 -0
  19. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/core/vector_database.py +0 -0
  20. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/exceptions.py +0 -0
  21. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/io.py +0 -0
  22. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/shared/authentication.py +0 -0
  23. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/shared/environments.py +0 -0
  24. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/shared/execution_context.py +0 -0
  25. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/shared/helpers.py +0 -0
  26. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/shared/logger.py +0 -0
  27. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/shared/request_response_handler.py +0 -0
  28. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/shared/types.py +0 -0
  29. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/shared/warnings.py +0 -0
  30. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/utils/__init__.py +0 -0
  31. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/utils/datetime_utils.py +0 -0
  32. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/utils/dict_utils.py +0 -0
  33. {craft_ai_sdk-0.64.0 → craft_ai_sdk-0.64.1}/craft_ai_sdk/utils/file_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: craft-ai-sdk
3
- Version: 0.64.0
3
+ Version: 0.64.1
4
4
  Summary: Craft AI MLOps platform SDK
5
5
  License: Apache-2.0
6
6
  Author: Craft AI
@@ -13,4 +13,4 @@ from .io import ( # noqa: F401
13
13
  )
14
14
  from .sdk import CraftAiSdk # noqa: F401
15
15
 
16
- __version__ = "0.64.0"
16
+ __version__ = "0.64.1"
@@ -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`): Token to access endpoint.
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
- url = f"{sdk.base_environment_url}/endpoints/{endpoint_url_path}"
99
- post_result = requests.post(
100
- url,
101
- headers={
102
- "Authorization": f"EndpointToken {endpoint_token}",
103
- "craft-ai-client": f"craft-ai-sdk@{sdk._version}",
104
- },
105
- allow_redirects=False,
106
- json=body,
107
- files=files,
108
- )
109
- handle_http_response(post_result)
110
- execution_id = post_result.headers.get("Craft-Ai-Execution-Id", "")
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`): Token to access endpoint.
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 handle_http_response(response)
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: handle_http_response(response)},
189
+ "outputs": {output_name: handled_response},
165
190
  "execution_id": execution_id,
166
191
  }
167
192
  else:
168
- return {**handle_http_response(response), "execution_id": execution_id}
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 _retrieve_pipeline_execution_outputs(sdk, execution_id)
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 _retrieve_pipeline_execution_outputs(sdk: BaseCraftAiSdk, execution_id):
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"
@@ -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.0" # Would be better to share it somewhere
142
+ _version = "0.64.1" # Would be better to share it somewhere
142
143
 
143
144
  def __init__(
144
145
  self,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "craft-ai-sdk"
3
- version = "0.64.0"
3
+ version = "0.64.1"
4
4
  description = "Craft AI MLOps platform SDK"
5
5
  license = "Apache-2.0"
6
6
  authors = ["Craft AI <contact@craft.ai>"]
File without changes
File without changes