rapidata 2.6.0__py3-none-any.whl → 2.7.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.

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
 
@@ -58,7 +58,7 @@ class RapidataOrderManager:
58
58
  return [ValidationSelection(validation_set_id=validation_set_id), LabelingSelection(amount=labeling_amount-1)]
59
59
  return [LabelingSelection(amount=labeling_amount)]
60
60
 
61
- def __create_general_order(self,
61
+ def _create_general_order(self,
62
62
  name: str,
63
63
  workflow: Workflow,
64
64
  assets: list[MediaAsset] | list[TextAsset] | list[MultiAsset],
@@ -168,7 +168,7 @@ class RapidataOrderManager:
168
168
  else:
169
169
  raise ValueError(f"Unsupported data type: {data_type}, must be one of {RapidataDataTypes._possible_values()}")
170
170
 
171
- return self.__create_general_order(
171
+ return self._create_general_order(
172
172
  name=name,
173
173
  workflow=ClassifyWorkflow(
174
174
  instruction=instruction,
@@ -226,7 +226,7 @@ class RapidataOrderManager:
226
226
  else:
227
227
  raise ValueError(f"Unsupported data type: {data_type}, must be one of {RapidataDataTypes._possible_values()}")
228
228
 
229
- return self.__create_general_order(
229
+ return self._create_general_order(
230
230
  name=name,
231
231
  workflow=CompareWorkflow(
232
232
  instruction=instruction
@@ -273,7 +273,7 @@ class RapidataOrderManager:
273
273
  else:
274
274
  raise ValueError(f"Unsupported data type: {data_type}, must be one of {RapidataDataTypes._possible_values()}")
275
275
 
276
- return self.__create_general_order(
276
+ return self._create_general_order(
277
277
  name=name,
278
278
  workflow=FreeTextWorkflow(
279
279
  instruction=instruction
@@ -316,7 +316,7 @@ class RapidataOrderManager:
316
316
 
317
317
  assets = [MediaAsset(path=path) for path in datapoints]
318
318
 
319
- return self.__create_general_order(
319
+ return self._create_general_order(
320
320
  name=name,
321
321
  workflow=SelectWordsWorkflow(
322
322
  instruction=instruction
@@ -361,7 +361,7 @@ class RapidataOrderManager:
361
361
 
362
362
  assets = [MediaAsset(path=path) for path in datapoints]
363
363
 
364
- return self.__create_general_order(
364
+ return self._create_general_order(
365
365
  name=name,
366
366
  workflow=LocateWorkflow(target=instruction),
367
367
  assets=assets,
@@ -403,7 +403,7 @@ class RapidataOrderManager:
403
403
 
404
404
  assets = [MediaAsset(path=path) for path in datapoints]
405
405
 
406
- return self.__create_general_order(
406
+ return self._create_general_order(
407
407
  name=name,
408
408
  workflow=DrawWorkflow(target=instruction),
409
409
  assets=assets,
@@ -448,7 +448,7 @@ class RapidataOrderManager:
448
448
  if not asset.get_duration():
449
449
  raise ValueError("The datapoints for this order must have a duration. (e.g. video or audio)")
450
450
 
451
- return self.__create_general_order(
451
+ return self._create_general_order(
452
452
  name=name,
453
453
  workflow=TimestampWorkflow(
454
454
  instruction=instruction
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rapidata
3
- Version: 2.6.0
3
+ Version: 2.7.1
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,8 +396,8 @@ 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
400
- rapidata/rapidata_client/order/rapidata_order_manager.py,sha256=0sbQWNHUjwKPTwAB-a_fOeOLuJYK7xl6rAj54BTn2gg,27201
399
+ rapidata/rapidata_client/order/rapidata_order.py,sha256=Yf-GSlkFRRnC_dOh6VKKO_XJENu7sym77iO6u-q0R2Y,8497
400
+ rapidata/rapidata_client/order/rapidata_order_manager.py,sha256=I1Gk0lChJQYH7Qm7Y0ceX9BV9vs_a6GzBoKt8p_X_cE,27193
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
403
403
  rapidata/rapidata_client/referee/_base_referee.py,sha256=MdFOhdxt3sRnWXLDKLJZKFdVpjBGn9jypPnWWQ6msQA,496
@@ -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.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
449
+ rapidata-2.7.1.dist-info/METADATA,sha256=9oASXys_fZTGsOE2ewEGzvb3LPEk1JvCvMEnTR0sqjw,1107
450
+ rapidata-2.7.1.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
451
+ rapidata-2.7.1.dist-info/RECORD,,