rapidata 1.7.1__py3-none-any.whl → 1.8.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.

Files changed (34) hide show
  1. rapidata/api_client/models/evaluation_workflow_config.py +5 -3
  2. rapidata/api_client/models/evaluation_workflow_model.py +5 -3
  3. rapidata/api_client/models/read_bridge_token_keys_result.py +31 -3
  4. rapidata/rapidata_client/assets/__init__.py +1 -1
  5. rapidata/rapidata_client/assets/media_asset.py +3 -0
  6. rapidata/rapidata_client/assets/text_asset.py +3 -0
  7. rapidata/rapidata_client/country_codes/country_codes.py +1 -1
  8. rapidata/rapidata_client/dataset/rapid_builders/__init__.py +4 -0
  9. rapidata/rapidata_client/dataset/rapid_builders/base_rapid_builder.py +33 -0
  10. rapidata/rapidata_client/dataset/rapid_builders/classify_rapid_builders.py +166 -0
  11. rapidata/rapidata_client/dataset/rapid_builders/compare_rapid_builders.py +145 -0
  12. rapidata/rapidata_client/dataset/rapid_builders/rapids.py +32 -0
  13. rapidata/rapidata_client/dataset/rapid_builders/transcription_rapid_builders.py +132 -0
  14. rapidata/rapidata_client/dataset/rapidata_dataset.py +3 -1
  15. rapidata/rapidata_client/dataset/rapidata_validation_set.py +24 -7
  16. rapidata/rapidata_client/dataset/validation_set_builder.py +115 -8
  17. rapidata/rapidata_client/filter/country_filter.py +3 -0
  18. rapidata/rapidata_client/filter/language_filter.py +3 -0
  19. rapidata/rapidata_client/metadata/prompt_metadata.py +5 -1
  20. rapidata/rapidata_client/order/rapidata_order.py +1 -1
  21. rapidata/rapidata_client/order/rapidata_order_builder.py +5 -5
  22. rapidata/rapidata_client/rapidata_client.py +37 -9
  23. rapidata/rapidata_client/settings/__init__.py +1 -1
  24. rapidata/rapidata_client/settings/settings.py +10 -9
  25. rapidata/rapidata_client/simple_builders/simple_classification_builders.py +132 -21
  26. rapidata/rapidata_client/simple_builders/simple_compare_builders.py +141 -15
  27. rapidata/rapidata_client/simple_builders/simple_free_text_builders.py +180 -0
  28. rapidata/rapidata_client/simple_builders/simple_transcription_builders.py +194 -0
  29. rapidata/service/openapi_service.py +4 -2
  30. {rapidata-1.7.1.dist-info → rapidata-1.8.0.dist-info}/METADATA +2 -2
  31. {rapidata-1.7.1.dist-info → rapidata-1.8.0.dist-info}/RECORD +33 -26
  32. rapidata/rapidata_client/config.py +0 -9
  33. {rapidata-1.7.1.dist-info → rapidata-1.8.0.dist-info}/LICENSE +0 -0
  34. {rapidata-1.7.1.dist-info → rapidata-1.8.0.dist-info}/WHEEL +0 -0
@@ -106,10 +106,12 @@ class RapidataDataset:
106
106
  else:
107
107
  files.append(cast(str, asset.path))
108
108
 
109
- self.openapi_service.dataset_api.dataset_create_datapoint_post(
109
+ upload_response = self.openapi_service.dataset_api.dataset_create_datapoint_post(
110
110
  model=model,
111
111
  files=files # type: ignore
112
112
  )
113
+ if upload_response.errors:
114
+ raise ValueError(f"Error uploading datapoint: {upload_response.errors}")
113
115
 
114
116
  total_uploads = len(media_paths)
115
117
  with ThreadPoolExecutor(max_workers=max_workers) as executor:
@@ -52,6 +52,27 @@ class RapidataValidationSet:
52
52
  self.openapi_service = openapi_service
53
53
  self.name = name
54
54
 
55
+ def upload_files(self, model: AddValidationRapidModel, assets: list[MediaAsset]):
56
+ """Upload a file to the validation set.
57
+
58
+ Args:
59
+ asset list[(MediaAsset)]: The asset to upload.
60
+
61
+ Returns:
62
+ str: The path to the uploaded file.
63
+ """
64
+ files = []
65
+ for asset in assets:
66
+ if isinstance(asset.path, str):
67
+ files.append(asset.path)
68
+ elif isinstance(asset.path, bytes):
69
+ files.append((asset.name, asset.path))
70
+ else:
71
+ raise ValueError("upload file failed")
72
+ self.openapi_service.validation_api.validation_add_validation_rapid_post(
73
+ model=model, files=files
74
+ )
75
+
55
76
  def add_general_validation_rapid(
56
77
  self,
57
78
  payload: (
@@ -107,9 +128,7 @@ class RapidataValidationSet:
107
128
  randomCorrectProbability=randomCorrectProbability,
108
129
  )
109
130
  if isinstance(asset, MediaAsset):
110
- self.openapi_service.validation_api.validation_add_validation_rapid_post(
111
- model=model, files=[asset.path]
112
- )
131
+ self.upload_files(model=model, assets=[asset])
113
132
 
114
133
  elif isinstance(asset, TextAsset):
115
134
  model = AddValidationTextRapidModel(
@@ -128,12 +147,10 @@ class RapidataValidationSet:
128
147
  )
129
148
 
130
149
  elif isinstance(asset, MultiAsset):
131
- files = [a.path for a in asset if isinstance(a, MediaAsset)]
150
+ files = [a for a in asset if isinstance(a, MediaAsset)]
132
151
  texts = [a.text for a in asset if isinstance(a, TextAsset)]
133
152
  if files:
134
- self.openapi_service.validation_api.validation_add_validation_rapid_post(
135
- model=model, files=files # type: ignore
136
- )
153
+ self.upload_files(model=model, assets=files)
137
154
  if texts:
138
155
  model = AddValidationTextRapidModel(
139
156
  validationSetId=self.id,
@@ -16,6 +16,14 @@ from rapidata.rapidata_client.dataset.validation_rapid_parts import ValidatioRap
16
16
  from rapidata.rapidata_client.metadata.base_metadata import Metadata
17
17
  from rapidata.service.openapi_service import OpenAPIService
18
18
 
19
+ from rapidata.rapidata_client.dataset.rapid_builders.rapids import (
20
+ Rapid,
21
+ ClassificationRapid,
22
+ CompareRapid,
23
+ TranscriptionRapid
24
+ )
25
+ from deprecated import deprecated
26
+
19
27
 
20
28
  class ValidationSetBuilder:
21
29
  """The ValidationSetBuilder is used to build a validation set.
@@ -71,7 +79,29 @@ class ValidationSetBuilder:
71
79
  )
72
80
 
73
81
  return validation_set
82
+
83
+ def add_rapid(self, rapid: Rapid):
84
+ """Add a rapid to the validation set.
85
+ To create the Rapid, use the RapidataClient.rapid_builder instance.
86
+
87
+ Args:
88
+ rapid (Rapid): The rapid to add to the validation set.
89
+ """
90
+ if not isinstance(rapid, Rapid):
91
+ raise ValueError("This method only accepts Rapid instances")
92
+
93
+ if isinstance(rapid, ClassificationRapid):
94
+ self._add_classify_rapid(rapid.asset, rapid.question, rapid.options, rapid.truths, rapid.metadata)
95
+
96
+ if isinstance(rapid, CompareRapid):
97
+ self._add_compare_rapid(rapid.asset, rapid.criteria, rapid.truth, rapid.metadata)
74
98
 
99
+ if isinstance(rapid, TranscriptionRapid):
100
+ self._add_transcription_rapid(rapid.asset, rapid.instruction, rapid.transcription, rapid.truths, rapid.strict_grading)
101
+
102
+ return self
103
+
104
+ @deprecated("Use add_rapid instead")
75
105
  def add_classify_rapid(
76
106
  self,
77
107
  asset: MediaAsset | TextAsset,
@@ -82,6 +112,33 @@ class ValidationSetBuilder:
82
112
  ):
83
113
  """Add a classify rapid to the validation set.
84
114
 
115
+ Args:
116
+ asset (MediaAsset | TextAsset): The asset for the rapid.
117
+ question (str): The question for the rapid.
118
+ categories (list[str]): The list of categories for the rapid.
119
+ truths (list[str]): The list of truths for the rapid.
120
+ metadata (list[Metadata], optional): The metadata for the rapid. Defaults to an empty list.
121
+
122
+ Returns:
123
+ ValidationSetBuilder: The ValidationSetBuilder instance.
124
+
125
+ Raises:
126
+ ValueError: If the lengths of categories and truths are inconsistent.
127
+ """
128
+ self._add_classify_rapid(asset, question, categories, truths, metadata)
129
+
130
+ return self
131
+
132
+ def _add_classify_rapid(
133
+ self,
134
+ asset: MediaAsset | TextAsset,
135
+ question: str,
136
+ categories: list[str],
137
+ truths: list[str],
138
+ metadata: list[Metadata] = [],
139
+ ):
140
+ """Add a classify rapid to the validation set.
141
+
85
142
  Args:
86
143
  asset (MediaAsset | TextAsset): The asset for the rapid.
87
144
  question (str): The question for the rapid.
@@ -113,8 +170,7 @@ class ValidationSetBuilder:
113
170
  )
114
171
  )
115
172
 
116
- return self
117
-
173
+ @deprecated("Use add_rapid instead")
118
174
  def add_compare_rapid(
119
175
  self,
120
176
  asset: MultiAsset,
@@ -136,7 +192,32 @@ class ValidationSetBuilder:
136
192
  Raises:
137
193
  ValueError: If the number of assets is not exactly two.
138
194
  """
139
- payload = ComparePayload(_t="ComparePayload", criteria=question)
195
+ self._add_compare_rapid(asset, question, truth, metadata)
196
+
197
+ return self
198
+
199
+ def _add_compare_rapid(
200
+ self,
201
+ asset: MultiAsset,
202
+ criteria: str,
203
+ truth: str,
204
+ metadata: list[Metadata] = [],
205
+ ):
206
+ """Add a compare rapid to the validation set.
207
+
208
+ Args:
209
+ asset (MultiAsset): The assets for the rapid.
210
+ criteria (str): The criteria for the comparison.
211
+ truth (str): The truth identifier for the rapid.
212
+ metadata (list[Metadata], optional): The metadata for the rapid. Defaults to an empty list.
213
+
214
+ Returns:
215
+ ValidationSetBuilder: The ValidationSetBuilder instance.
216
+
217
+ Raises:
218
+ ValueError: If the number of assets is not exactly two.
219
+ """
220
+ payload = ComparePayload(_t="ComparePayload", criteria=criteria)
140
221
  # take only last part of truth path
141
222
  truth = os.path.basename(truth)
142
223
  model_truth = CompareTruth(_t="CompareTruth", winnerId=truth)
@@ -146,7 +227,7 @@ class ValidationSetBuilder:
146
227
 
147
228
  self._rapid_parts.append(
148
229
  ValidatioRapidParts(
149
- question=question,
230
+ question=criteria,
150
231
  payload=payload,
151
232
  truths=model_truth,
152
233
  metadata=metadata,
@@ -155,8 +236,7 @@ class ValidationSetBuilder:
155
236
  )
156
237
  )
157
238
 
158
- return self
159
-
239
+ @deprecated("Use add_rapid instead")
160
240
  def add_transcription_rapid(
161
241
  self,
162
242
  asset: MediaAsset | TextAsset,
@@ -168,6 +248,35 @@ class ValidationSetBuilder:
168
248
  ):
169
249
  """Add a transcription rapid to the validation set.
170
250
 
251
+ Args:
252
+ asset (MediaAsset | TextAsset): The asset for the rapid.
253
+ question (str): The question for the rapid.
254
+ transcription (list[str]): The transcription for the rapid.
255
+ truths (list[int]): The list of indices of the true word selections.
256
+ strict_grading (bool | None, optional): The strict grading for the rapid. Defaults to None.
257
+ metadata (list[Metadata], optional): The metadata for the rapid.
258
+
259
+ Returns:
260
+ ValidationSetBuilder: The ValidationSetBuilder instance.
261
+
262
+ Raises:
263
+ ValueError: If a correct word is not found in the transcription.
264
+ """
265
+ self._add_transcription_rapid(asset, question, transcription, truths, strict_grading, metadata)
266
+
267
+ return self
268
+
269
+ def _add_transcription_rapid(
270
+ self,
271
+ asset: MediaAsset | TextAsset,
272
+ question: str,
273
+ transcription: str,
274
+ truths: list[int],
275
+ strict_grading: bool | None = None,
276
+ metadata: list[Metadata] = [],
277
+ ):
278
+ """Add a transcription rapid to the validation set.
279
+
171
280
  Args:
172
281
  asset (MediaAsset | TextAsset): The asset for the rapid.
173
282
  question (str): The question for the rapid.
@@ -213,5 +322,3 @@ class ValidationSetBuilder:
213
322
  randomCorrectProbability = 1 / len(transcription_words),
214
323
  )
215
324
  )
216
-
217
- return self
@@ -7,6 +7,9 @@ class CountryFilter(Filter):
7
7
 
8
8
  def __init__(self, country_codes: list[str]):
9
9
  # check that all characters in the country codes are uppercase
10
+ if not isinstance(country_codes, list):
11
+ raise ValueError("Country codes must be a list")
12
+
10
13
  if not all([code.isupper() for code in country_codes]):
11
14
  raise ValueError("Country codes must be uppercase")
12
15
 
@@ -8,6 +8,9 @@ from rapidata.api_client.models.language_user_filter_model import (
8
8
  class LanguageFilter(Filter):
9
9
 
10
10
  def __init__(self, language_codes: list[str]):
11
+ if not isinstance(language_codes, list):
12
+ raise ValueError("Language codes must be a list")
13
+
11
14
  # check that all characters in the language codes are lowercase
12
15
  if not all([code.islower() for code in language_codes]):
13
16
  raise ValueError("Language codes must be lowercase")
@@ -6,8 +6,12 @@ class PromptMetadata(Metadata):
6
6
 
7
7
  def __init__(self, prompt: str, identifier: str = "prompt"):
8
8
  super().__init__(identifier=identifier)
9
+
10
+ if not isinstance(prompt, str):
11
+ raise ValueError("Prompt must be a string")
12
+
9
13
  self._prompt = prompt
10
14
 
11
15
 
12
16
  def to_model(self):
13
- return PromptMetadataInput(_t="PromptMetadataInput", identifier=self._identifier, prompt=self._prompt)
17
+ return PromptMetadataInput(_t="PromptMetadataInput", identifier=self._identifier, prompt=self._prompt)
@@ -106,7 +106,7 @@ class RapidataOrder:
106
106
  Returns:
107
107
  The results of the order.
108
108
  """
109
- while self.get_status() == "Processing":
109
+ while self.get_status() not in ["Completed", "Paused", "ManuelReview"]:
110
110
  sleep(5)
111
111
 
112
112
  try:
@@ -27,7 +27,7 @@ from rapidata.service.openapi_service import OpenAPIService
27
27
 
28
28
  from rapidata.rapidata_client.workflow.compare_workflow import CompareWorkflow
29
29
 
30
- from rapidata.rapidata_client.assets import MediaAsset, TextAsset, MultiAsset
30
+ from rapidata.rapidata_client.assets import MediaAsset, TextAsset, MultiAsset, BaseAsset
31
31
 
32
32
  from typing import Optional, cast, Sequence
33
33
 
@@ -69,7 +69,7 @@ class RapidataOrderBuilder:
69
69
  self._selections: list[Selection] = []
70
70
  self._rapids_per_bag: int = 2
71
71
  self._priority: int = 50
72
- self._assets: list[MediaAsset] | list[TextAsset] | list[MultiAsset] = []
72
+ self._assets: Sequence[BaseAsset] = []
73
73
 
74
74
  def _to_model(self) -> CreateOrderModel:
75
75
  """
@@ -202,7 +202,7 @@ class RapidataOrderBuilder:
202
202
  order.submit()
203
203
 
204
204
  if not disable_link:
205
- print(f"Order '{self._name}' is now viewable under https://app.rapidata.ai/order/detail/{order.order_id}.")
205
+ print(f"Order '{self._name}' is now viewable under: https://app.{self._openapi_service.enviroment}/order/detail/{order.order_id}")
206
206
 
207
207
  return order
208
208
 
@@ -240,8 +240,8 @@ class RapidataOrderBuilder:
240
240
 
241
241
  def media(
242
242
  self,
243
- asset: list[MediaAsset] | list[TextAsset] | list[MultiAsset],
244
- metadata: Sequence[Metadata] | None = None,
243
+ asset: Sequence[BaseAsset],
244
+ metadata: Sequence[Metadata] | None = None, # make this a list of metadata on next major release
245
245
  ) -> "RapidataOrderBuilder":
246
246
  """
247
247
  Set the media assets for the order.
@@ -1,6 +1,4 @@
1
- from rapidata.rapidata_client.dataset.rapidata_validation_set import (
2
- RapidataValidationSet,
3
- )
1
+ from rapidata.rapidata_client.dataset.rapidata_validation_set import RapidataValidationSet
4
2
  from rapidata.rapidata_client.dataset.validation_set_builder import ValidationSetBuilder
5
3
  from rapidata.rapidata_client.order.rapidata_order_builder import RapidataOrderBuilder
6
4
  from rapidata.service.openapi_service import OpenAPIService
@@ -9,6 +7,10 @@ from rapidata.rapidata_client.dataset.rapidata_dataset import RapidataDataset
9
7
 
10
8
  from rapidata.rapidata_client.simple_builders.simple_classification_builders import ClassificationQuestionBuilder
11
9
  from rapidata.rapidata_client.simple_builders.simple_compare_builders import CompareCriteriaBuilder
10
+ from rapidata.rapidata_client.simple_builders.simple_free_text_builders import FreeTextQuestionBuilder
11
+ from rapidata.rapidata_client.simple_builders.simple_transcription_builders import TranscriptionInstructionBuilder
12
+
13
+ from rapidata.rapidata_client.dataset.rapid_builders import BaseRapidBuilder
12
14
 
13
15
  from rapidata.api_client.exceptions import BadRequestException
14
16
  from urllib3._collections import HTTPHeaderDict
@@ -21,16 +23,19 @@ from rapidata.api_client.models.sort_criterion import SortCriterion
21
23
 
22
24
  from rapidata.api_client.models.query_validation_set_model import QueryValidationSetModel
23
25
 
26
+ from deprecated import deprecated
27
+
24
28
 
25
29
  class RapidataClient:
26
- """The Rapidata client is the main entry point for interacting with the Rapidata API. It allows you to create orders and validation sets. For creating a new order, check out `new_order()`. For creating a new validation set, check out `new_validation_set()`."""
30
+ """The Rapidata client is the main entry point for interacting with the Rapidata API. It allows you to create orders and validation sets."""
27
31
 
32
+ rapid_builder = BaseRapidBuilder()
33
+
28
34
  def __init__(
29
35
  self,
30
36
  client_id: str | None = None,
31
37
  client_secret: str | None = None,
32
- endpoint: str = "https://api.rapidata.ai",
33
- token_url: str = "https://auth.rapidata.ai",
38
+ enviroment: str = "rapidata.ai",
34
39
  oauth_scope: str = "openid",
35
40
  cert_path: str | None = None,
36
41
  ):
@@ -44,12 +49,12 @@ class RapidataClient:
44
49
  self.openapi_service = OpenAPIService(
45
50
  client_id=client_id,
46
51
  client_secret=client_secret,
47
- endpoint=endpoint,
48
- token_url=token_url,
52
+ enviroment=enviroment,
49
53
  oauth_scope=oauth_scope,
50
54
  cert_path=cert_path
51
55
  )
52
-
56
+
57
+ @deprecated("Use the specific builder methods instead.")
53
58
  def new_order(self, name: str) -> RapidataOrderBuilder:
54
59
  """Create a new order using a RapidataOrderBuilder instance.
55
60
 
@@ -177,3 +182,26 @@ class RapidataClient:
177
182
  CompareQuestionBuilder: A CompareQuestionBuilder instance.
178
183
  """
179
184
  return CompareCriteriaBuilder(name=name, openapi_service=self.openapi_service)
185
+
186
+ def create_free_text_order(self, name: str) -> FreeTextQuestionBuilder:
187
+ """Create a new free text order where people are asked to provide a free text answer.
188
+
189
+ Args:
190
+ name (str): The name of the order.
191
+
192
+ Returns:
193
+ FreeTextQuestionBuilder: A FreeTextQuestionBuilder instance.
194
+ """
195
+ return FreeTextQuestionBuilder(name=name, openapi_service=self.openapi_service)
196
+
197
+ def create_transcription_order(self, name: str) -> TranscriptionInstructionBuilder:
198
+ """Create a new transcription order where people are asked to transcribe an audio file.
199
+
200
+ Args:
201
+ name (str): The name of the order.
202
+
203
+ Returns:
204
+ TranscriptionInstructionBuilder: A TranscriptionInstructionBuilder instance.
205
+ """
206
+ return TranscriptionInstructionBuilder(name=name, openapi_service=self.openapi_service)
207
+
@@ -1,2 +1,2 @@
1
1
  from .feature_flags import FeatureFlags
2
- from .settings import Settings
2
+ from .settings import Settings, TranslationBehaviour
@@ -96,17 +96,18 @@ class Settings:
96
96
  """
97
97
  self._settings["no_shuffle"] = str(value)
98
98
  return self
99
-
100
- def compare_with_prompt_design(self, value: bool = True):
101
- """A special design to compare two texts/images based on a criteria and a given prompt.
102
-
99
+
100
+ def play_video_until_the_end(self, additional_time=0):
101
+ """Allows users to only answer once the video has finished playing.
102
+ The additional time gets added on top. Can be negative to allow answers before the video ends.
103
+
103
104
  Args:
104
- value (bool, optional): Whether to enable compare with prompt design. Defaults to True.
105
-
105
+ additional_time (int, optional): Additional time in milliseconds. Defaults to 0.
106
+
106
107
  Returns:
107
- Settings: The current Settings instance for method chaining.
108
- """
109
- self._settings["claire"] = str(value)
108
+ Settings: The current Settings instance for method chaining."""
109
+
110
+ self._settings["alert_on_fast_response_add_media_duration"] = str(additional_time)
110
111
  return self
111
112
 
112
113
  def key_value(self, key: str, value: str):