rapidata 2.6.0__py3-none-any.whl → 2.7.0__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 rapidata might be problematic. Click here for more details.

@@ -6,6 +6,7 @@ from rapidata.api_client.exceptions import ApiException
6
6
  from rapidata.api_client.models.order_state import OrderState
7
7
  from typing import Optional, cast, Any
8
8
  from rapidata.api_client.models.workflow_artifact_model import WorkflowArtifactModel
9
+ from rapidata.api_client.models.preliminary_download_model import PreliminaryDownloadModel
9
10
  from tqdm import tqdm
10
11
 
11
12
  class RapidataOrder:
@@ -34,6 +35,7 @@ class RapidataOrder:
34
35
  self.__openapi_service = openapi_service
35
36
  self.__dataset = dataset
36
37
  self.__workflow_id = None
38
+ self.__pipeline_id = ""
37
39
 
38
40
  def run(self, print_link: bool=True):
39
41
  """
@@ -103,20 +105,29 @@ class RapidataOrder:
103
105
 
104
106
  sleep(refresh_rate)
105
107
 
108
+ def __get_pipeline_id(self):
109
+ if self.__pipeline_id:
110
+ return self.__pipeline_id
111
+
112
+ self.__pipeline_id = self.__openapi_service.order_api.order_get_by_id_get(self.order_id).pipeline_id
113
+ return self.__pipeline_id
114
+
106
115
  def __get_workflow_id(self):
107
116
  if self.__workflow_id:
108
117
  return self.__workflow_id
109
118
 
110
119
  for _ in range(10): # Try for 20 seconds to get the workflow id if workflow has not started by then, raise an exception
111
120
  try:
112
- order_result = self.__openapi_service.order_api.order_get_by_id_get(self.order_id)
113
- pipeline = self.__openapi_service.pipeline_api.pipeline_id_get(order_result.pipeline_id)
121
+ self.__get_pipeline_id()
122
+ pipeline = self.__openapi_service.pipeline_api.pipeline_id_get(self.__pipeline_id)
114
123
  self.__workflow_id = cast(WorkflowArtifactModel, pipeline.artifacts["workflow-artifact"].actual_instance).workflow_id
115
124
  break
116
125
  except Exception:
117
126
  sleep(2)
127
+
118
128
  if not self.__workflow_id:
119
129
  raise Exception("Something went wrong when trying to get the order progress.")
130
+
120
131
  return self.__workflow_id
121
132
 
122
133
  def __get_workflow_progress(self):
@@ -133,16 +144,42 @@ class RapidataOrder:
133
144
  raise Exception(f"Failed to get progress. Please try again in a few seconds.")
134
145
 
135
146
  return progress
136
-
147
+
148
+ def __get_preliminary_results(self) -> dict[str, Any]:
149
+ pipeline_id = self.__get_pipeline_id()
150
+ try:
151
+ download_id = self.__openapi_service.pipeline_api.pipeline_pipeline_id_preliminary_download_post(pipeline_id, PreliminaryDownloadModel(sendEmail=False)).download_id
152
+ while not (preliminary_results := self.__openapi_service.pipeline_api.pipeline_preliminary_download_preliminary_download_id_get(preliminary_download_id=download_id)):
153
+ sleep(1)
154
+ return json.loads(preliminary_results.decode())
137
155
 
138
- def get_results(self) -> dict[str, Any]:
156
+ except ApiException as e:
157
+ # Handle API exceptions
158
+ raise Exception(f"Failed to get preliminary order results: {str(e)}") from e
159
+ except json.JSONDecodeError as e:
160
+ # Handle JSON parsing errors
161
+ raise Exception(f"Failed to parse preliminary order results: {str(e)}") from e
162
+
163
+ def get_results(self, preliminary_results=False) -> dict[str, Any]:
139
164
  """
140
165
  Gets the results of the order.
141
166
  If the order is still processing, this method will block until the order is completed and then return the results.
142
167
 
168
+ Args:
169
+ preliminary_results: If True, returns the preliminary results of the order. Defaults to False.
170
+ Note that preliminary results are not final and may not contain all the datapoints & responses. Only the onese that are already available.
171
+ This will throw an exception if there are no responses available yet.
172
+
143
173
  Returns:
144
174
  The results of the order.
145
175
  """
176
+
177
+ if preliminary_results and self.get_status() not in [OrderState.COMPLETED]:
178
+ return self.__get_preliminary_results()
179
+
180
+ elif preliminary_results and self.get_status() in [OrderState.COMPLETED]:
181
+ print("Order is already completed. Returning final results.")
182
+
146
183
  while self.get_status() not in [OrderState.COMPLETED, OrderState.PAUSED, OrderState.MANUALREVIEW, OrderState.FAILED]:
147
184
  sleep(5)
148
185
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rapidata
3
- Version: 2.6.0
3
+ Version: 2.7.0
4
4
  Summary: Rapidata package containing the Rapidata Python Client to interact with the Rapidata Web API in an easy way.
5
5
  License: Apache-2.0
6
6
  Author: Rapidata AG
@@ -396,7 +396,7 @@ rapidata/rapidata_client/metadata/_select_words_metadata.py,sha256=I4qVtCkj60ljk
396
396
  rapidata/rapidata_client/order/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
397
397
  rapidata/rapidata_client/order/_rapidata_dataset.py,sha256=t1OFfHXz3Pe0S8qVGdReZm4aGVvxpVWH-VUgfnNtcgQ,5300
398
398
  rapidata/rapidata_client/order/_rapidata_order_builder.py,sha256=N6mqmgneJSsb_no_Ps9BG3EhDekLgKxFYpjDCN-VVeg,13095
399
- rapidata/rapidata_client/order/rapidata_order.py,sha256=ti5fHd-KAvI_WRwe9UWF6QDx-VYzlU_Kqmi44wphJzc,6588
399
+ rapidata/rapidata_client/order/rapidata_order.py,sha256=Yf-GSlkFRRnC_dOh6VKKO_XJENu7sym77iO6u-q0R2Y,8497
400
400
  rapidata/rapidata_client/order/rapidata_order_manager.py,sha256=0sbQWNHUjwKPTwAB-a_fOeOLuJYK7xl6rAj54BTn2gg,27201
401
401
  rapidata/rapidata_client/rapidata_client.py,sha256=A9mnSX6wzVF9TxS1YH87hTi4jCn75dIuP3KZj5Y_vFg,1957
402
402
  rapidata/rapidata_client/referee/__init__.py,sha256=q0Hv9nmfEpyChejtyMLT8hWKL0vTTf_UgUXPYNJ-H6M,153
@@ -445,7 +445,7 @@ rapidata/service/credential_manager.py,sha256=Of0BQs_V1T7rkrWX9groLX790nOknaARwn
445
445
  rapidata/service/local_file_service.py,sha256=pgorvlWcx52Uh3cEG6VrdMK_t__7dacQ_5AnfY14BW8,877
446
446
  rapidata/service/openapi_service.py,sha256=Z4NrAuilLlIWBdGOv6otz36tHS_vvU36w5jmvOUTmqo,3198
447
447
  rapidata/service/token_manager.py,sha256=JZ5YbR5Di8dO3H4kK11d0kzWlrXxjgCmeNkHA4AapCM,6425
448
- rapidata-2.6.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
449
- rapidata-2.6.0.dist-info/METADATA,sha256=nIa0vi7gX1BLbGcWVLvSNUsy-xTw90VfLdYyPdzlco0,1107
450
- rapidata-2.6.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
451
- rapidata-2.6.0.dist-info/RECORD,,
448
+ rapidata-2.7.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
449
+ rapidata-2.7.0.dist-info/METADATA,sha256=30UXvN02zlclEO7PGLNXf8LzcTHC6L25hUqL2TEyMhY,1107
450
+ rapidata-2.7.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
451
+ rapidata-2.7.0.dist-info/RECORD,,