rapidata 1.10.0__py3-none-any.whl → 2.0.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 (138) hide show
  1. rapidata/__init__.py +21 -17
  2. rapidata/api_client/__init__.py +15 -5
  3. rapidata/api_client/api/coco_api.py +14 -29
  4. rapidata/api_client/api/dataset_api.py +6 -6
  5. rapidata/api_client/api/identity_api.py +3 -3
  6. rapidata/api_client/api/pipeline_api.py +1008 -95
  7. rapidata/api_client/api/rapid_api.py +6 -6
  8. rapidata/api_client/api/validation_api.py +12 -42
  9. rapidata/api_client/models/__init__.py +15 -5
  10. rapidata/api_client/models/add_campaign_model.py +1 -3
  11. rapidata/api_client/models/add_validation_text_rapid_model.py +1 -1
  12. rapidata/api_client/models/age_group.py +5 -4
  13. rapidata/api_client/models/base_error.py +1 -4
  14. rapidata/api_client/models/compare_workflow_config.py +9 -24
  15. rapidata/api_client/models/compare_workflow_config_model.py +9 -29
  16. rapidata/api_client/models/compare_workflow_config_model_pair_maker_config.py +140 -0
  17. rapidata/api_client/models/compare_workflow_config_pair_maker_config.py +140 -0
  18. rapidata/api_client/models/compare_workflow_model.py +7 -3
  19. rapidata/api_client/models/compare_workflow_model1.py +7 -3
  20. rapidata/api_client/models/compare_workflow_model1_pair_maker_information.py +140 -0
  21. rapidata/api_client/models/compare_workflow_model_pair_maker_config.py +140 -0
  22. rapidata/api_client/models/file_asset_model_metadata_inner.py +8 -22
  23. rapidata/api_client/models/get_classify_workflow_result_overview_result.py +144 -0
  24. rapidata/api_client/models/get_pipeline_by_id_result.py +13 -3
  25. rapidata/api_client/models/identity_read_bridge_token_get202_response.py +140 -0
  26. rapidata/api_client/models/not_available_yet_result.py +96 -0
  27. rapidata/api_client/models/online_pair_maker_config.py +98 -0
  28. rapidata/api_client/models/online_pair_maker_config_model.py +98 -0
  29. rapidata/api_client/models/online_pair_maker_information.py +100 -0
  30. rapidata/api_client/models/pipeline_id_workflow_put_request.py +140 -0
  31. rapidata/api_client/models/pre_arranged_pair_maker_config.py +100 -0
  32. rapidata/api_client/models/pre_arranged_pair_maker_config_model.py +96 -0
  33. rapidata/api_client/models/pre_arranged_pair_maker_information.py +102 -0
  34. rapidata/api_client/models/read_bridge_token_keys_result.py +11 -2
  35. rapidata/api_client/models/simple_workflow_config.py +7 -26
  36. rapidata/api_client/models/simple_workflow_config_model.py +4 -28
  37. rapidata/api_client/models/simple_workflow_get_result_overview_get200_response.py +16 -16
  38. rapidata/api_client/models/simple_workflow_model1.py +3 -3
  39. rapidata/api_client/models/update_campaign_model.py +99 -0
  40. rapidata/api_client/models/validation_import_post_request_blueprint.py +1 -1
  41. rapidata/api_client_README.md +20 -7
  42. rapidata/rapidata_client/__init__.py +18 -9
  43. rapidata/rapidata_client/assets/__init__.py +5 -4
  44. rapidata/rapidata_client/assets/{media_asset.py → _media_asset.py} +32 -11
  45. rapidata/rapidata_client/assets/{multi_asset.py → _multi_asset.py} +1 -1
  46. rapidata/rapidata_client/assets/{text_asset.py → _text_asset.py} +1 -1
  47. rapidata/rapidata_client/assets/data_type_enum.py +7 -0
  48. rapidata/rapidata_client/filter/__init__.py +1 -1
  49. rapidata/rapidata_client/filter/_base_filter.py +10 -0
  50. rapidata/rapidata_client/filter/age_filter.py +12 -5
  51. rapidata/rapidata_client/filter/campaign_filter.py +12 -3
  52. rapidata/rapidata_client/filter/country_filter.py +10 -3
  53. rapidata/rapidata_client/filter/gender_filter.py +12 -5
  54. rapidata/rapidata_client/filter/language_filter.py +14 -3
  55. rapidata/rapidata_client/filter/models/age_group.py +26 -0
  56. rapidata/rapidata_client/filter/models/gender.py +19 -0
  57. rapidata/rapidata_client/filter/rapidata_filters.py +31 -0
  58. rapidata/rapidata_client/filter/user_score_filter.py +20 -4
  59. rapidata/rapidata_client/metadata/__init__.py +5 -5
  60. rapidata/rapidata_client/metadata/{base_metadata.py → _base_metadata.py} +2 -1
  61. rapidata/rapidata_client/metadata/{private_text_metadata.py → _private_text_metadata.py} +2 -2
  62. rapidata/rapidata_client/metadata/{prompt_metadata.py → _prompt_metadata.py} +3 -2
  63. rapidata/rapidata_client/metadata/{public_text_metadata.py → _public_text_metadata.py} +2 -2
  64. rapidata/rapidata_client/metadata/{select_words_metadata.py → _select_words_metadata.py} +3 -2
  65. rapidata/rapidata_client/{dataset/rapidata_dataset.py → order/_rapidata_dataset.py} +7 -8
  66. rapidata/rapidata_client/order/_rapidata_order_builder.py +365 -0
  67. rapidata/rapidata_client/order/rapidata_order.py +49 -31
  68. rapidata/rapidata_client/order/rapidata_order_manager.py +461 -0
  69. rapidata/rapidata_client/rapidata_client.py +12 -201
  70. rapidata/rapidata_client/referee/__init__.py +3 -3
  71. rapidata/rapidata_client/referee/{base_referee.py → _base_referee.py} +3 -3
  72. rapidata/rapidata_client/referee/{early_stopping_referee.py → _early_stopping_referee.py} +14 -11
  73. rapidata/rapidata_client/referee/{naive_referee.py → _naive_referee.py} +9 -9
  74. rapidata/rapidata_client/selection/__init__.py +1 -1
  75. rapidata/rapidata_client/{filter/base_filter.py → selection/_base_selection.py} +2 -2
  76. rapidata/rapidata_client/selection/capped_selection.py +15 -5
  77. rapidata/rapidata_client/selection/conditional_validation_selection.py +17 -4
  78. rapidata/rapidata_client/selection/demographic_selection.py +18 -7
  79. rapidata/rapidata_client/selection/labeling_selection.py +10 -3
  80. rapidata/rapidata_client/selection/rapidata_selections.py +21 -0
  81. rapidata/rapidata_client/selection/validation_selection.py +11 -4
  82. rapidata/rapidata_client/settings/__init__.py +9 -2
  83. rapidata/rapidata_client/settings/_rapidata_setting.py +11 -0
  84. rapidata/rapidata_client/settings/alert_on_fast_response.py +21 -0
  85. rapidata/rapidata_client/settings/custom_setting.py +16 -0
  86. rapidata/rapidata_client/settings/free_text_minimum_characters.py +16 -0
  87. rapidata/rapidata_client/settings/models/__init__.py +1 -0
  88. rapidata/rapidata_client/settings/models/translation_behaviour_options.py +14 -0
  89. rapidata/rapidata_client/settings/no_shuffle.py +16 -0
  90. rapidata/rapidata_client/settings/play_video_until_the_end.py +16 -0
  91. rapidata/rapidata_client/settings/rapidata_settings.py +31 -0
  92. rapidata/rapidata_client/settings/translation_behaviour.py +18 -0
  93. rapidata/rapidata_client/validation/__init__.py +1 -0
  94. rapidata/rapidata_client/{dataset/validation_rapid_parts.py → validation/_validation_rapid_parts.py} +7 -6
  95. rapidata/rapidata_client/validation/_validation_set_builder.py +371 -0
  96. rapidata/rapidata_client/{dataset → validation}/rapidata_validation_set.py +54 -50
  97. rapidata/rapidata_client/validation/rapids/__init__.py +1 -0
  98. rapidata/rapidata_client/validation/rapids/box.py +17 -0
  99. rapidata/rapidata_client/validation/rapids/rapids.py +94 -0
  100. rapidata/rapidata_client/validation/rapids/rapids_manager.py +163 -0
  101. rapidata/rapidata_client/validation/validation_set_manager.py +335 -0
  102. rapidata/rapidata_client/workflow/__init__.py +8 -6
  103. rapidata/rapidata_client/workflow/_base_workflow.py +25 -0
  104. rapidata/rapidata_client/workflow/{classify_workflow.py → _classify_workflow.py} +6 -6
  105. rapidata/rapidata_client/workflow/{compare_workflow.py → _compare_workflow.py} +10 -16
  106. rapidata/rapidata_client/workflow/_draw_workflow.py +22 -0
  107. rapidata/rapidata_client/workflow/_evaluation_workflow.py +26 -0
  108. rapidata/rapidata_client/workflow/{free_text_workflow.py → _free_text_workflow.py} +10 -16
  109. rapidata/rapidata_client/workflow/_locate_workflow.py +22 -0
  110. rapidata/rapidata_client/workflow/{select_words_workflow.py → _select_words_workflow.py} +2 -8
  111. rapidata/service/credential_manager.py +11 -1
  112. rapidata/service/openapi_service.py +23 -4
  113. {rapidata-1.10.0.dist-info → rapidata-2.0.0.dist-info}/METADATA +2 -1
  114. {rapidata-1.10.0.dist-info → rapidata-2.0.0.dist-info}/RECORD +118 -94
  115. rapidata/constants.py +0 -1
  116. rapidata/rapidata_client/dataset/rapid_builders/__init__.py +0 -4
  117. rapidata/rapidata_client/dataset/rapid_builders/base_rapid_builder.py +0 -33
  118. rapidata/rapidata_client/dataset/rapid_builders/classify_rapid_builders.py +0 -166
  119. rapidata/rapidata_client/dataset/rapid_builders/compare_rapid_builders.py +0 -145
  120. rapidata/rapidata_client/dataset/rapid_builders/rapids.py +0 -33
  121. rapidata/rapidata_client/dataset/rapid_builders/select_words_rapid_builders.py +0 -124
  122. rapidata/rapidata_client/dataset/validation_set_builder.py +0 -336
  123. rapidata/rapidata_client/order/order_builder.py +0 -25
  124. rapidata/rapidata_client/order/rapidata_order_builder.py +0 -463
  125. rapidata/rapidata_client/selection/base_selection.py +0 -9
  126. rapidata/rapidata_client/settings/feature_flags.py +0 -125
  127. rapidata/rapidata_client/settings/settings.py +0 -124
  128. rapidata/rapidata_client/simple_builders/__init__.py +0 -0
  129. rapidata/rapidata_client/simple_builders/simple_classification_builders.py +0 -271
  130. rapidata/rapidata_client/simple_builders/simple_compare_builders.py +0 -267
  131. rapidata/rapidata_client/simple_builders/simple_free_text_builders.py +0 -192
  132. rapidata/rapidata_client/simple_builders/simple_select_words_builders.py +0 -196
  133. rapidata/rapidata_client/workflow/base_workflow.py +0 -42
  134. rapidata/rapidata_client/workflow/evaluation_workflow.py +0 -15
  135. /rapidata/rapidata_client/assets/{base_asset.py → _base_asset.py} +0 -0
  136. /rapidata/rapidata_client/{dataset → filter/models}/__init__.py +0 -0
  137. {rapidata-1.10.0.dist-info → rapidata-2.0.0.dist-info}/LICENSE +0 -0
  138. {rapidata-1.10.0.dist-info → rapidata-2.0.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,335 @@
1
+ from rapidata.rapidata_client.validation._validation_set_builder import ValidationSetBuilder
2
+ from rapidata.rapidata_client.validation.rapidata_validation_set import RapidataValidationSet
3
+ from rapidata.service.openapi_service import OpenAPIService
4
+ from rapidata.rapidata_client.assets.data_type_enum import RapidataDataTypes
5
+ from rapidata.rapidata_client.validation.rapids.rapids_manager import RapidsManager
6
+ from rapidata.rapidata_client.validation.rapids.rapids import Rapid
7
+ from rapidata.rapidata_client.metadata import PromptMetadata
8
+
9
+ from rapidata.api_client.models.page_info import PageInfo
10
+ from rapidata.api_client.models.root_filter import RootFilter
11
+ from rapidata.api_client.models.filter import Filter
12
+ from rapidata.api_client.models.sort_criterion import SortCriterion
13
+ from rapidata.api_client.exceptions import BadRequestException
14
+ from urllib3._collections import HTTPHeaderDict
15
+
16
+ from rapidata.rapidata_client.validation.rapids.box import Box
17
+
18
+ from rapidata.api_client.models.query_validation_set_model import QueryValidationSetModel
19
+
20
+ from typing import Sequence
21
+
22
+
23
+ class ValidationSetManager:
24
+ """
25
+ Responsible for everything related to validation sets. From creation to retrieval.
26
+ """
27
+ def __init__(self, openapi_service: OpenAPIService) -> None:
28
+ self.__openapi_service = openapi_service
29
+ self.rapid = RapidsManager()
30
+
31
+ def create_classification_set(self,
32
+ name: str,
33
+ instruction: str,
34
+ answer_options: list[str],
35
+ datapoints: list[str],
36
+ truths: list[list[str]],
37
+ data_type: str = RapidataDataTypes.MEDIA,
38
+ contexts: list[str] | None = None,
39
+ print_confirmation: bool = True
40
+ ) -> RapidataValidationSet:
41
+ """Create a classification validation set.
42
+
43
+ Args:
44
+ name (str): The name of the validation set. (will not be shown to the labeler)
45
+ instruction (str): The instruction by which the labeler will answer.
46
+ answer_options (list[str]): The options to choose from when answering.
47
+ datapoints (list[str]): The datapoints that will be used for validation.
48
+ truths (list[list[str]]): The truths for each datapoint. Outher list is for each datapoint, inner list is for each truth.\n
49
+ example:
50
+ options: ["yes", "no", "maybe"]
51
+ datapoints: ["datapoint1", "datapoint2"]
52
+ truths: [["yes"], ["no", "maybe"]] -> first datapoint correct answer is "yes", second datapoint is "no" or "maybe"
53
+ data_type (str, optional): The type of data. Defaults to RapidataDataTypes.MEDIA. Other option: RapidataDataTypes.TEXT ("text").
54
+ contexts (list[str], optional): The contexts for each datapoint. Defaults to None.\n
55
+ If provided has to be the same length as datapoints and will be shown in addition to the instruction and answer options. (Therefore will be different for each datapoint)
56
+ Will be match up with the datapoints using the list index.
57
+ print_confirmation (bool, optional): Whether to print a confirmation message that validation set has been created. Defaults to True.
58
+ """
59
+
60
+ if len(datapoints) != len(truths):
61
+ raise ValueError("The number of datapoints and truths must be equal")
62
+ if contexts and len(contexts) != len(datapoints):
63
+ raise ValueError("The number of contexts and datapoints must be equal")
64
+
65
+ rapids = []
66
+ for i in range(len(datapoints)):
67
+ rapids.append(
68
+ self.rapid.classification_rapid(
69
+ instruction=instruction,
70
+ answer_options=answer_options,
71
+ datapoint=datapoints[i],
72
+ truths=truths[i],
73
+ data_type=data_type,
74
+ metadata=[PromptMetadata(contexts[i])] if contexts else []
75
+ )
76
+ )
77
+
78
+ validation_set_builder = ValidationSetBuilder(name, self.__openapi_service)
79
+ for rapid in rapids:
80
+ validation_set_builder._add_rapid(rapid)
81
+
82
+ return validation_set_builder._submit(print_confirmation)
83
+
84
+ def create_compare_set(self,
85
+ name: str,
86
+ instruction: str,
87
+ datapoints: list[list[str]],
88
+ truths: list[str],
89
+ data_type: str = RapidataDataTypes.MEDIA,
90
+ contexts: list[str] | None = None,
91
+ print_confirmation: bool = True
92
+ ) -> RapidataValidationSet:
93
+ """Create a comparison validation set.
94
+
95
+ Args:
96
+ name (str): The name of the validation set. (will not be shown to the labeler)
97
+ instruction (str): The instruction to compare against.
98
+ truths (list[str]): The truths for each comparison. List is for each comparison.\n
99
+ example:
100
+ instruction: "Which image has a cat?"
101
+ datapoints = [["image1.jpg", "image2.jpg"], ["image3.jpg", "image4.jpg"]]
102
+ truths: ["image1.jpg", "image4.jpg"] -> first comparison image1.jpg has a cat, second comparison image4.jpg has a cat
103
+ datapoints (list[list[str]]): The compare datapoints to create the validation set with.
104
+ Outer list is for each comparison, inner list the two images/texts that will be compared.
105
+ data_type (str, optional): The type of data. Defaults to RapidataDataTypes.MEDIA. Other option: RapidataDataTypes.TEXT ("text").
106
+ contexts (list[str], optional): The contexts for each datapoint. Defaults to None.\n
107
+ If provided has to be the same length as datapoints and will be shown in addition to the instruction and truth. (Therefore will be different for each datapoint)
108
+ Will be match up with the datapoints using the list index.
109
+ print_confirmation (bool, optional): Whether to print a confirmation message that validation set has been created. Defaults to True.
110
+ """
111
+
112
+ if len(datapoints) != len(truths):
113
+ raise ValueError("The number of datapoints and truths must be equal")
114
+
115
+ if contexts and len(contexts) != len(datapoints):
116
+ raise ValueError("The number of contexts and datapoints must be equal")
117
+
118
+ rapids = []
119
+ for i in range(len(datapoints)):
120
+ rapids.append(
121
+ self.rapid.compare_rapid(
122
+ instruction=instruction,
123
+ truth=truths[i],
124
+ datapoint=datapoints[i],
125
+ data_type=data_type,
126
+ metadata=[PromptMetadata(contexts[i])] if contexts else []
127
+ )
128
+ )
129
+
130
+ validation_set_builder = ValidationSetBuilder(name, self.__openapi_service)
131
+ for rapid in rapids:
132
+ validation_set_builder._add_rapid(rapid)
133
+
134
+ return validation_set_builder._submit(print_confirmation)
135
+
136
+ def create_select_words_set(self,
137
+ name: str,
138
+ instruction: str,
139
+ truths: list[list[int]],
140
+ datapoints: list[str],
141
+ sentences: list[str],
142
+ strict_grading: bool = True,
143
+ print_confirmation: bool = True
144
+ ) -> RapidataValidationSet:
145
+ """Create a select words validation set.
146
+
147
+ Args:
148
+ name (str): The name of the validation set. (will not be shown to the labeler)
149
+ instruction (str): The instruction to show to the labeler.
150
+ truths (list[list[int]]): The truths for each datapoint. Outher list is for each datapoint, inner list is for each truth.\n
151
+ example:
152
+ datapoints: ["datapoint1", "datapoint2"]
153
+ sentences: ["this example 1", "this example 2"]
154
+ truths: [[0, 1], [2]] -> first datapoint correct words are "this" and "example", second datapoint is "2"
155
+ datapoints (list[str]): The datapoints that will be used for validation.
156
+ sentences (list[str]): The sentences that will be used for validation. The sentece will be split up by spaces to be selected by the labeler.
157
+ Must be the same length as datapoints.
158
+ strict_grading (bool, optional): Whether to grade strictly. Defaults to True.\n
159
+ If True, the labeler must select all correct words to be graded as correct. (and no wrong words)
160
+ If False, the labeler must select at least one correct word to be graded as correct. (and no wrong words)
161
+ print_confirmation (bool, optional): Whether to print a confirmation message that validation set has been created. Defaults to True.
162
+ """
163
+
164
+ if len(datapoints) != len(truths) or len(datapoints) != len(sentences):
165
+ raise ValueError("The number of datapoints, truths, and sentences must be equal")
166
+
167
+ rapids = []
168
+ for i in range(len(datapoints)):
169
+ rapids.append(
170
+ self.rapid.select_words_rapid(
171
+ instruction=instruction,
172
+ truths=truths[i],
173
+ datapoint=datapoints[i],
174
+ sentence=sentences[i],
175
+ strict_grading=strict_grading
176
+ )
177
+ )
178
+
179
+ validation_set_builder = ValidationSetBuilder(name, self.__openapi_service)
180
+ for rapid in rapids:
181
+ validation_set_builder._add_rapid(rapid)
182
+
183
+ return validation_set_builder._submit(print_confirmation)
184
+
185
+ def create_locate_set(self,
186
+ name: str,
187
+ instruction: str,
188
+ truths: list[list[Box]],
189
+ datapoints: list[str],
190
+ contexts: list[str] | None = None,
191
+ print_confirmation: bool = True
192
+ ) -> RapidataValidationSet:
193
+ """Create a locate validation set.
194
+
195
+ Args:
196
+ name (str): The name of the validation set. (will not be shown to the labeler)
197
+ instruction (str): The instruction to show to the labeler.
198
+ truths (list[list[Box]]): The truths for each datapoint. Outher list is for each datapoint, inner list is for each truth.\n
199
+ example:
200
+ datapoints: ["datapoint1", "datapoint2"]
201
+ truths: [[Box(0, 0, 100, 100)], [Box(50, 50, 150, 150)]] -> first datapoint the object is in the top left corner, second datapoint the object is in the center
202
+ datapoints (list[str]): The datapoints that will be used for validation.
203
+ contexts (list[str], optional): The contexts for each datapoint. Defaults to None.
204
+ print_confirmation (bool, optional): Whether to print a confirmation message that validation set has been created. Defaults to True.
205
+ """
206
+
207
+ if len(datapoints) != len(truths):
208
+ raise ValueError("The number of datapoints and truths must be equal")
209
+
210
+ if contexts and len(contexts) != len(datapoints):
211
+ raise ValueError("The number of contexts and datapoints must be equal")
212
+
213
+ rapids = []
214
+ for i in range(len(datapoints)):
215
+ rapids.append(
216
+ self.rapid.locate_rapid(
217
+ instruction=instruction,
218
+ truths=truths[i],
219
+ datapoint=datapoints[i],
220
+ metadata=[PromptMetadata(contexts[i])] if contexts else []
221
+ )
222
+ )
223
+
224
+ validation_set_builder = ValidationSetBuilder(name, self.__openapi_service)
225
+ for rapid in rapids:
226
+ validation_set_builder._add_rapid(rapid)
227
+
228
+ return validation_set_builder._submit(print_confirmation)
229
+
230
+ def create_draw_set(self,
231
+ name: str,
232
+ instruction: str,
233
+ truths: list[list[Box]],
234
+ datapoints: list[str],
235
+ contexts: list[str] | None = None,
236
+ print_confirmation: bool = True
237
+ ) -> RapidataValidationSet:
238
+ """Create a draw validation set.
239
+
240
+ Args:
241
+ name (str): The name of the validation set. (will not be shown to the labeler)
242
+ instruction (str): The instruction to show to the labeler.
243
+ truths (list[list[Box]]): The truths for each datapoint. Outher list is for each datapoint, inner list is for each truth.\n
244
+ example:
245
+ datapoints: ["datapoint1", "datapoint2"]
246
+ truths: [[Box(0, 0, 100, 100)], [Box(50, 50, 150, 150)]] -> first datapoint the object is in the top left corner, second datapoint the object is in the center
247
+ datapoints (list[str]): The datapoints that will be used for validation.
248
+ contexts (list[str], optional): The contexts for each datapoint. Defaults to None.
249
+ print_confirmation (bool, optional): Whether to print a confirmation message that validation set has been created. Defaults to True.
250
+ """
251
+
252
+ if len(datapoints) != len(truths):
253
+ raise ValueError("The number of datapoints and truths must be equal")
254
+
255
+ if contexts and len(contexts) != len(datapoints):
256
+ raise ValueError("The number of contexts and datapoints must be equal")
257
+
258
+ rapids = []
259
+ for i in range(len(datapoints)):
260
+ rapids.append(
261
+ self.rapid.draw_rapid(
262
+ instruction=instruction,
263
+ truths=truths[i],
264
+ datapoint=datapoints[i],
265
+ metadata=[PromptMetadata(contexts[i])] if contexts else []
266
+ )
267
+ )
268
+
269
+ validation_set_builder = ValidationSetBuilder(name, self.__openapi_service)
270
+ for rapid in rapids:
271
+ validation_set_builder._add_rapid(rapid)
272
+
273
+ return validation_set_builder._submit(print_confirmation)
274
+
275
+ def create_mixed_set(self,
276
+ name: str,
277
+ rapids: Sequence[Rapid],
278
+ print_confirmation: bool = True
279
+ ) -> RapidataValidationSet:
280
+ """Create a validation set with a list of rapids.
281
+
282
+ Args:
283
+ name (str): The name of the validation set. (will not be shown to the labeler)
284
+ rapids (Sequence[Rapid]): The list of rapids to add to the validation set.
285
+ print_confirmation (bool, optional): Whether to print a confirmation message that validation set has been created. Defaults to True.
286
+ """
287
+
288
+ validation_set_builder = ValidationSetBuilder(name, self.__openapi_service)
289
+ for rapid in rapids:
290
+ validation_set_builder._add_rapid(rapid)
291
+
292
+ return validation_set_builder._submit(print_confirmation)
293
+
294
+ def get_validation_set_by_id(self, validation_set_id: str) -> RapidataValidationSet:
295
+ """Get a validation set by ID.
296
+
297
+ Args:
298
+ validation_set_id (str): The ID of the validation set.
299
+
300
+ Returns:
301
+ RapidataValidationSet: The ValidationSet instance.
302
+ """
303
+ try:
304
+ validation_set = self.__openapi_service.validation_api.validation_get_by_id_get(id=validation_set_id)
305
+ except Exception:
306
+ raise ValueError(f"ValidationSet with ID {validation_set_id} not found.")
307
+
308
+ return RapidataValidationSet(validation_set_id, self.__openapi_service, validation_set.name)
309
+
310
+ def find_validation_sets(self, name: str = "", amount: int = 1) -> list[RapidataValidationSet]:
311
+ """Find validation sets by name.
312
+
313
+ Args:
314
+ name (str, optional): The name to search for. Defaults to "" to match with any set.
315
+ amount (int, optional): The amount of validation sets to return. Defaults to 1.
316
+
317
+ Returns:
318
+ list[RapidataValidationSet]: The list of validation sets.
319
+ """
320
+ try:
321
+ validation_page_result = self.__openapi_service.validation_api.validation_query_validation_sets_get(QueryValidationSetModel(
322
+ pageInfo=PageInfo(index=1, size=amount),
323
+ filter=RootFilter(filters=[Filter(field="Name", operator="Contains", value=name)]),
324
+ sortCriteria=[SortCriterion(direction="Desc", propertyName="CreatedAt")]
325
+ ))
326
+
327
+ except BadRequestException as e:
328
+ raise ValueError(f"Error occured during request. \nError: {e.body} \nTraceid: {e.headers.get('X-Trace-Id') if isinstance(e.headers, HTTPHeaderDict) else 'Unknown'}")
329
+
330
+ except Exception as e:
331
+ raise ValueError(f"Unknown error occured: {e}")
332
+
333
+ validation_sets = [self.get_validation_set_by_id(validation_set.id) for validation_set in validation_page_result.items]
334
+ return validation_sets
335
+
@@ -1,6 +1,8 @@
1
- from .base_workflow import Workflow
2
- from .classify_workflow import ClassifyWorkflow
3
- from .compare_workflow import CompareWorkflow
4
- from .free_text_workflow import FreeTextWorkflow
5
- from .select_words_workflow import SelectWordsWorkflow
6
- from .evaluation_workflow import EvaluationWorkflow
1
+ from ._locate_workflow import LocateWorkflow
2
+ from ._draw_workflow import DrawWorkflow
3
+ from ._base_workflow import Workflow
4
+ from ._classify_workflow import ClassifyWorkflow
5
+ from ._compare_workflow import CompareWorkflow
6
+ from ._free_text_workflow import FreeTextWorkflow
7
+ from ._select_words_workflow import SelectWordsWorkflow
8
+ from ._evaluation_workflow import EvaluationWorkflow
@@ -0,0 +1,25 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Any
3
+
4
+ from rapidata.api_client.models.simple_workflow_model import SimpleWorkflowModel
5
+ from rapidata.api_client.models.evaluation_workflow_model import EvaluationWorkflowModel
6
+ from rapidata.api_client.models.compare_workflow_model import CompareWorkflowModel
7
+ from rapidata.rapidata_client.referee._base_referee import Referee
8
+
9
+
10
+ class Workflow(ABC):
11
+
12
+ def __init__(self, type: str):
13
+ self._type = type
14
+ self._target_country_codes: list[str] = []
15
+
16
+ def _to_dict(self) -> dict[str, Any]:
17
+ return {
18
+ "_t": self._type,
19
+ }
20
+
21
+ @abstractmethod
22
+ def _to_model(
23
+ self,
24
+ ) -> SimpleWorkflowModel | CompareWorkflowModel | EvaluationWorkflowModel:
25
+ pass
@@ -21,14 +21,14 @@ class ClassifyWorkflow(Workflow):
21
21
  _options (list[str]): The list of classification options.
22
22
  """
23
23
 
24
- def __init__(self, question: str, options: list[str]):
24
+ def __init__(self, instruction: str, answer_options: list[str]):
25
25
  super().__init__(type="SimpleWorkflowConfig")
26
- self._question = question
27
- self._options = options
26
+ self._question = instruction
27
+ self._options = answer_options
28
28
 
29
- def to_dict(self) -> dict[str, Any]:
29
+ def _to_dict(self) -> dict[str, Any]:
30
30
  return {
31
- **super().to_dict(),
31
+ **super()._to_dict(),
32
32
  "blueprint": {
33
33
  "_t": "ClassifyBlueprint",
34
34
  "title": self._question,
@@ -36,7 +36,7 @@ class ClassifyWorkflow(Workflow):
36
36
  }
37
37
  }
38
38
 
39
- def to_model(self) -> SimpleWorkflowModel:
39
+ def _to_model(self) -> SimpleWorkflowModel:
40
40
  blueprint = AttachCategoryRapidBlueprint(
41
41
  _t="ClassifyBlueprint",
42
42
  title=self._question,
@@ -10,35 +10,29 @@ class CompareWorkflow(Workflow):
10
10
  A workflow for comparison tasks.
11
11
 
12
12
  This class represents a comparison workflow where items are compared based on
13
- specified criteria.
13
+ specified instruction.
14
14
 
15
15
  Attributes:
16
- _criteria (str): The criteria used for comparison.
16
+ _instruction (str): The instruction used for comparison.
17
17
 
18
18
  Args:
19
- criteria (str): The criteria to be used for comparison.
19
+ instruction (str): The instruction to be used for comparison.
20
20
  """
21
21
 
22
- def __init__(self, criteria: str):
23
- """
24
- Initialize a CompareWorkflow instance.
25
-
26
- Args:
27
- criteria (str): The criteria to be used for comparison.
28
- """
22
+ def __init__(self, instruction: str):
29
23
  super().__init__(type="CompareWorkflowConfig")
30
- self._criteria = criteria
24
+ self._instruction = instruction
31
25
 
32
- def to_dict(self) -> dict[str, Any]:
26
+ def _to_dict(self) -> dict[str, Any]:
33
27
  return {
34
- **super().to_dict(),
35
- "criteria": self._criteria,
28
+ **super()._to_dict(),
29
+ "criteria": self._instruction,
36
30
  }
37
31
 
38
- def to_model(self) -> SimpleWorkflowModel:
32
+ def _to_model(self) -> SimpleWorkflowModel:
39
33
  blueprint = CompareRapidBlueprint(
40
34
  _t="CompareBlueprint",
41
- criteria=self._criteria,
35
+ criteria=self._instruction,
42
36
  )
43
37
 
44
38
  return SimpleWorkflowModel(
@@ -0,0 +1,22 @@
1
+ from rapidata.api_client.models.simple_workflow_model import SimpleWorkflowModel
2
+ from rapidata.api_client.models.simple_workflow_model_blueprint import SimpleWorkflowModelBlueprint
3
+ from rapidata.api_client.models.line_rapid_blueprint import LineRapidBlueprint
4
+ from rapidata.rapidata_client.workflow._base_workflow import Workflow
5
+
6
+
7
+ class DrawWorkflow(Workflow):
8
+
9
+ def __init__(self, target: str):
10
+ super().__init__(type="SimpleWorkflowConfig")
11
+ self._target = target
12
+
13
+ def _to_model(self) -> SimpleWorkflowModel:
14
+ blueprint = LineRapidBlueprint(
15
+ _t="LineBlueprint",
16
+ target=self._target
17
+ )
18
+
19
+ return SimpleWorkflowModel(
20
+ _t="SimpleWorkflow",
21
+ blueprint=SimpleWorkflowModelBlueprint(blueprint)
22
+ )
@@ -0,0 +1,26 @@
1
+ from rapidata.api_client.models.evaluation_workflow_model import EvaluationWorkflowModel
2
+ from rapidata.rapidata_client.workflow._base_workflow import Workflow
3
+
4
+
5
+ class EvaluationWorkflow(Workflow):
6
+ """
7
+ A workflow to run evaluation orders.
8
+
9
+ This is used internally only and should not be necessary to be used by clients.
10
+
11
+ Args:
12
+ validation_set_id (str): a source for the tasks that will be sent to the user
13
+ should_accept_incorrect (bool): indicates if the user should get feedback on their answers if they answer wrong. If set to true the user will not notice that he was tested.
14
+ """
15
+
16
+ def __init__(self, validation_set_id: str, should_accept_incorrect: bool):
17
+ super().__init__("EvaluationWorkflow")
18
+ self.validation_set_id = validation_set_id
19
+ self.should_accept_incorrect = should_accept_incorrect
20
+
21
+ def _to_model(self):
22
+ return EvaluationWorkflowModel(
23
+ _t="EvaluationWorkflow",
24
+ validationSetId=self.validation_set_id,
25
+ shouldAcceptIncorrect=self.should_accept_incorrect,
26
+ )
@@ -10,38 +10,32 @@ class FreeTextWorkflow(Workflow):
10
10
  A workflow for free text input tasks.
11
11
 
12
12
  This class represents a workflow where users can provide free-form text responses
13
- to a given question.
13
+ to a given instruction.
14
14
 
15
15
  Attributes:
16
- _question (str): The question to be answered with free text.
16
+ _instruction (str): The instruction to be answered with free text.
17
17
 
18
18
  Args:
19
- question (str): The question to be presented for free text input.
19
+ instruction (str): The instruction to be presented for free text input.
20
20
  """
21
21
 
22
- def __init__(self, question: str):
23
- """
24
- Initialize a FreeTextWorkflow instance.
25
-
26
- Args:
27
- question (str): The question to be presented for free text input.
28
- """
22
+ def __init__(self, instruction: str):
29
23
  super().__init__(type="SimpleWorkflowConfig")
30
- self._question = question
24
+ self._instruction = instruction
31
25
 
32
- def to_dict(self) -> dict[str, Any]:
26
+ def _to_dict(self) -> dict[str, Any]:
33
27
  return {
34
- **super().to_dict(),
28
+ **super()._to_dict(),
35
29
  "blueprint": {
36
30
  "_t": "FreeTextBlueprint",
37
- "question": self._question,
31
+ "question": self._instruction,
38
32
  },
39
33
  }
40
34
 
41
- def to_model(self) -> SimpleWorkflowModel:
35
+ def _to_model(self) -> SimpleWorkflowModel:
42
36
  blueprint = FreeTextRapidBlueprint(
43
37
  _t="FreeTextBlueprint",
44
- question=self._question,
38
+ question=self._instruction,
45
39
  )
46
40
 
47
41
  return SimpleWorkflowModel(
@@ -0,0 +1,22 @@
1
+ from rapidata.api_client.models.simple_workflow_model import SimpleWorkflowModel
2
+ from rapidata.api_client.models.simple_workflow_model_blueprint import SimpleWorkflowModelBlueprint
3
+ from rapidata.api_client.models.locate_rapid_blueprint import LocateRapidBlueprint
4
+ from rapidata.rapidata_client.workflow._base_workflow import Workflow
5
+
6
+
7
+ class LocateWorkflow(Workflow):
8
+
9
+ def __init__(self, target: str):
10
+ super().__init__(type="SimpleWorkflowConfig")
11
+ self._target = target
12
+
13
+ def _to_model(self) -> SimpleWorkflowModel:
14
+ blueprint = LocateRapidBlueprint(
15
+ _t="LocateBlueprint",
16
+ target=self._target
17
+ )
18
+
19
+ return SimpleWorkflowModel(
20
+ _t="SimpleWorkflow",
21
+ blueprint=SimpleWorkflowModelBlueprint(blueprint)
22
+ )
@@ -1,7 +1,7 @@
1
1
  from rapidata.api_client.models.simple_workflow_model import SimpleWorkflowModel
2
2
  from rapidata.api_client.models.simple_workflow_model_blueprint import SimpleWorkflowModelBlueprint
3
3
  from rapidata.api_client.models.transcription_rapid_blueprint import TranscriptionRapidBlueprint
4
- from rapidata.rapidata_client.workflow.base_workflow import Workflow
4
+ from rapidata.rapidata_client.workflow._base_workflow import Workflow
5
5
 
6
6
 
7
7
  class SelectWordsWorkflow(Workflow):
@@ -19,16 +19,10 @@ class SelectWordsWorkflow(Workflow):
19
19
  """
20
20
 
21
21
  def __init__(self, instruction: str):
22
- """
23
- Initialize a SelectWordsWorkflow instance.
24
-
25
- Args:
26
- instruction (str): The instruction to be provided for the select words task.
27
- """
28
22
  super().__init__(type="SimpleWorkflowConfig")
29
23
  self._instruction = instruction
30
24
 
31
- def to_model(self) -> SimpleWorkflowModel:
25
+ def _to_model(self) -> SimpleWorkflowModel:
32
26
  blueprint = TranscriptionRapidBlueprint(
33
27
  _t="TranscriptionBlueprint",
34
28
  title=self._instruction
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import os
3
3
  import time
4
+ import urllib.parse
4
5
  import webbrowser
5
6
  from datetime import datetime, timezone
6
7
  from pathlib import Path
@@ -8,6 +9,7 @@ from socket import gethostname
8
9
  from typing import Dict, List, Optional, Tuple
9
10
 
10
11
  import requests
12
+ from colorama import Fore
11
13
  from pydantic import BaseModel
12
14
 
13
15
 
@@ -206,7 +208,15 @@ class CredentialManager:
206
208
  return None
207
209
 
208
210
  auth_url = f"{self.endpoint}/connect/authorize/external?clientId=rapidata-cli&scope=openid profile email roles&writeKey={bridge_endpoint.write_key}"
209
- webbrowser.open(auth_url)
211
+ could_open_browser = webbrowser.open(auth_url)
212
+
213
+ if not could_open_browser:
214
+ encoded_url = urllib.parse.quote(auth_url, safe="%/:=&?~#+!$,;'@()*[]")
215
+ print(
216
+ Fore.RED
217
+ + f'Please open the following URL in your browser to log in: "{encoded_url}"'
218
+ + Fore.RESET
219
+ )
210
220
 
211
221
  access_token = self._poll_read_key(bridge_endpoint.read_key)
212
222
  if not access_token: