rapidata 1.10.1__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.
- rapidata/__init__.py +21 -17
- rapidata/api_client/__init__.py +15 -5
- rapidata/api_client/api/coco_api.py +14 -29
- rapidata/api_client/api/dataset_api.py +6 -6
- rapidata/api_client/api/identity_api.py +3 -3
- rapidata/api_client/api/pipeline_api.py +1008 -95
- rapidata/api_client/api/rapid_api.py +6 -6
- rapidata/api_client/api/validation_api.py +12 -42
- rapidata/api_client/models/__init__.py +15 -5
- rapidata/api_client/models/add_campaign_model.py +1 -3
- rapidata/api_client/models/add_validation_text_rapid_model.py +1 -1
- rapidata/api_client/models/age_group.py +5 -4
- rapidata/api_client/models/base_error.py +1 -4
- rapidata/api_client/models/compare_workflow_config.py +9 -24
- rapidata/api_client/models/compare_workflow_config_model.py +9 -29
- rapidata/api_client/models/compare_workflow_config_model_pair_maker_config.py +140 -0
- rapidata/api_client/models/compare_workflow_config_pair_maker_config.py +140 -0
- rapidata/api_client/models/compare_workflow_model.py +7 -3
- rapidata/api_client/models/compare_workflow_model1.py +7 -3
- rapidata/api_client/models/compare_workflow_model1_pair_maker_information.py +140 -0
- rapidata/api_client/models/compare_workflow_model_pair_maker_config.py +140 -0
- rapidata/api_client/models/file_asset_model_metadata_inner.py +8 -22
- rapidata/api_client/models/get_classify_workflow_result_overview_result.py +144 -0
- rapidata/api_client/models/get_pipeline_by_id_result.py +13 -3
- rapidata/api_client/models/identity_read_bridge_token_get202_response.py +140 -0
- rapidata/api_client/models/not_available_yet_result.py +96 -0
- rapidata/api_client/models/online_pair_maker_config.py +98 -0
- rapidata/api_client/models/online_pair_maker_config_model.py +98 -0
- rapidata/api_client/models/online_pair_maker_information.py +100 -0
- rapidata/api_client/models/pipeline_id_workflow_put_request.py +140 -0
- rapidata/api_client/models/pre_arranged_pair_maker_config.py +100 -0
- rapidata/api_client/models/pre_arranged_pair_maker_config_model.py +96 -0
- rapidata/api_client/models/pre_arranged_pair_maker_information.py +102 -0
- rapidata/api_client/models/read_bridge_token_keys_result.py +11 -2
- rapidata/api_client/models/simple_workflow_config.py +7 -26
- rapidata/api_client/models/simple_workflow_config_model.py +4 -28
- rapidata/api_client/models/simple_workflow_get_result_overview_get200_response.py +16 -16
- rapidata/api_client/models/simple_workflow_model1.py +3 -3
- rapidata/api_client/models/update_campaign_model.py +99 -0
- rapidata/api_client/models/validation_import_post_request_blueprint.py +1 -1
- rapidata/api_client_README.md +20 -7
- rapidata/rapidata_client/__init__.py +18 -9
- rapidata/rapidata_client/assets/__init__.py +5 -4
- rapidata/rapidata_client/assets/{media_asset.py → _media_asset.py} +32 -11
- rapidata/rapidata_client/assets/{multi_asset.py → _multi_asset.py} +1 -1
- rapidata/rapidata_client/assets/{text_asset.py → _text_asset.py} +1 -1
- rapidata/rapidata_client/assets/data_type_enum.py +7 -0
- rapidata/rapidata_client/filter/__init__.py +1 -1
- rapidata/rapidata_client/filter/_base_filter.py +10 -0
- rapidata/rapidata_client/filter/age_filter.py +12 -5
- rapidata/rapidata_client/filter/campaign_filter.py +12 -3
- rapidata/rapidata_client/filter/country_filter.py +10 -3
- rapidata/rapidata_client/filter/gender_filter.py +12 -5
- rapidata/rapidata_client/filter/language_filter.py +14 -3
- rapidata/rapidata_client/filter/models/age_group.py +26 -0
- rapidata/rapidata_client/filter/models/gender.py +19 -0
- rapidata/rapidata_client/filter/rapidata_filters.py +31 -0
- rapidata/rapidata_client/filter/user_score_filter.py +20 -4
- rapidata/rapidata_client/metadata/__init__.py +5 -5
- rapidata/rapidata_client/metadata/{base_metadata.py → _base_metadata.py} +2 -1
- rapidata/rapidata_client/metadata/{private_text_metadata.py → _private_text_metadata.py} +2 -2
- rapidata/rapidata_client/metadata/{prompt_metadata.py → _prompt_metadata.py} +3 -2
- rapidata/rapidata_client/metadata/{public_text_metadata.py → _public_text_metadata.py} +2 -2
- rapidata/rapidata_client/metadata/{select_words_metadata.py → _select_words_metadata.py} +3 -2
- rapidata/rapidata_client/{dataset/rapidata_dataset.py → order/_rapidata_dataset.py} +7 -8
- rapidata/rapidata_client/order/_rapidata_order_builder.py +365 -0
- rapidata/rapidata_client/order/rapidata_order.py +49 -31
- rapidata/rapidata_client/order/rapidata_order_manager.py +461 -0
- rapidata/rapidata_client/rapidata_client.py +12 -201
- rapidata/rapidata_client/referee/__init__.py +3 -3
- rapidata/rapidata_client/referee/{base_referee.py → _base_referee.py} +3 -3
- rapidata/rapidata_client/referee/{early_stopping_referee.py → _early_stopping_referee.py} +14 -11
- rapidata/rapidata_client/referee/{naive_referee.py → _naive_referee.py} +9 -9
- rapidata/rapidata_client/selection/__init__.py +1 -1
- rapidata/rapidata_client/{filter/base_filter.py → selection/_base_selection.py} +2 -2
- rapidata/rapidata_client/selection/capped_selection.py +15 -5
- rapidata/rapidata_client/selection/conditional_validation_selection.py +17 -4
- rapidata/rapidata_client/selection/demographic_selection.py +18 -7
- rapidata/rapidata_client/selection/labeling_selection.py +10 -3
- rapidata/rapidata_client/selection/rapidata_selections.py +21 -0
- rapidata/rapidata_client/selection/validation_selection.py +11 -4
- rapidata/rapidata_client/settings/__init__.py +9 -2
- rapidata/rapidata_client/settings/_rapidata_setting.py +11 -0
- rapidata/rapidata_client/settings/alert_on_fast_response.py +21 -0
- rapidata/rapidata_client/settings/custom_setting.py +16 -0
- rapidata/rapidata_client/settings/free_text_minimum_characters.py +16 -0
- rapidata/rapidata_client/settings/models/__init__.py +1 -0
- rapidata/rapidata_client/settings/models/translation_behaviour_options.py +14 -0
- rapidata/rapidata_client/settings/no_shuffle.py +16 -0
- rapidata/rapidata_client/settings/play_video_until_the_end.py +16 -0
- rapidata/rapidata_client/settings/rapidata_settings.py +31 -0
- rapidata/rapidata_client/settings/translation_behaviour.py +18 -0
- rapidata/rapidata_client/validation/__init__.py +1 -0
- rapidata/rapidata_client/{dataset/validation_rapid_parts.py → validation/_validation_rapid_parts.py} +7 -6
- rapidata/rapidata_client/validation/_validation_set_builder.py +371 -0
- rapidata/rapidata_client/{dataset → validation}/rapidata_validation_set.py +54 -50
- rapidata/rapidata_client/validation/rapids/__init__.py +1 -0
- rapidata/rapidata_client/validation/rapids/box.py +17 -0
- rapidata/rapidata_client/validation/rapids/rapids.py +94 -0
- rapidata/rapidata_client/validation/rapids/rapids_manager.py +163 -0
- rapidata/rapidata_client/validation/validation_set_manager.py +335 -0
- rapidata/rapidata_client/workflow/__init__.py +8 -6
- rapidata/rapidata_client/workflow/_base_workflow.py +25 -0
- rapidata/rapidata_client/workflow/{classify_workflow.py → _classify_workflow.py} +6 -6
- rapidata/rapidata_client/workflow/{compare_workflow.py → _compare_workflow.py} +10 -16
- rapidata/rapidata_client/workflow/_draw_workflow.py +22 -0
- rapidata/rapidata_client/workflow/_evaluation_workflow.py +26 -0
- rapidata/rapidata_client/workflow/{free_text_workflow.py → _free_text_workflow.py} +10 -16
- rapidata/rapidata_client/workflow/_locate_workflow.py +22 -0
- rapidata/rapidata_client/workflow/{select_words_workflow.py → _select_words_workflow.py} +2 -8
- rapidata/service/credential_manager.py +11 -1
- rapidata/service/openapi_service.py +23 -4
- {rapidata-1.10.1.dist-info → rapidata-2.0.0.dist-info}/METADATA +2 -1
- {rapidata-1.10.1.dist-info → rapidata-2.0.0.dist-info}/RECORD +118 -94
- rapidata/constants.py +0 -1
- rapidata/rapidata_client/dataset/rapid_builders/__init__.py +0 -4
- rapidata/rapidata_client/dataset/rapid_builders/base_rapid_builder.py +0 -33
- rapidata/rapidata_client/dataset/rapid_builders/classify_rapid_builders.py +0 -166
- rapidata/rapidata_client/dataset/rapid_builders/compare_rapid_builders.py +0 -145
- rapidata/rapidata_client/dataset/rapid_builders/rapids.py +0 -33
- rapidata/rapidata_client/dataset/rapid_builders/select_words_rapid_builders.py +0 -124
- rapidata/rapidata_client/dataset/validation_set_builder.py +0 -336
- rapidata/rapidata_client/order/order_builder.py +0 -25
- rapidata/rapidata_client/order/rapidata_order_builder.py +0 -463
- rapidata/rapidata_client/selection/base_selection.py +0 -9
- rapidata/rapidata_client/settings/feature_flags.py +0 -125
- rapidata/rapidata_client/settings/settings.py +0 -124
- rapidata/rapidata_client/simple_builders/__init__.py +0 -0
- rapidata/rapidata_client/simple_builders/simple_classification_builders.py +0 -271
- rapidata/rapidata_client/simple_builders/simple_compare_builders.py +0 -267
- rapidata/rapidata_client/simple_builders/simple_free_text_builders.py +0 -192
- rapidata/rapidata_client/simple_builders/simple_select_words_builders.py +0 -196
- rapidata/rapidata_client/workflow/base_workflow.py +0 -42
- rapidata/rapidata_client/workflow/evaluation_workflow.py +0 -15
- /rapidata/rapidata_client/assets/{base_asset.py → _base_asset.py} +0 -0
- /rapidata/rapidata_client/{dataset → filter/models}/__init__.py +0 -0
- {rapidata-1.10.1.dist-info → rapidata-2.0.0.dist-info}/LICENSE +0 -0
- {rapidata-1.10.1.dist-info → rapidata-2.0.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
from typing import Sequence
|
|
2
|
+
from urllib3._collections import HTTPHeaderDict
|
|
3
|
+
|
|
4
|
+
from rapidata.service.openapi_service import OpenAPIService
|
|
5
|
+
from rapidata.rapidata_client.assets.data_type_enum import RapidataDataTypes
|
|
6
|
+
from rapidata.rapidata_client.assets import MediaAsset, TextAsset, MultiAsset
|
|
7
|
+
from rapidata.rapidata_client.order.rapidata_order import RapidataOrder
|
|
8
|
+
from rapidata.rapidata_client.order._rapidata_order_builder import RapidataOrderBuilder
|
|
9
|
+
from rapidata.rapidata_client.metadata import PromptMetadata, SelectWordsMetadata
|
|
10
|
+
from rapidata.rapidata_client.referee._naive_referee import NaiveReferee
|
|
11
|
+
from rapidata.rapidata_client.referee._early_stopping_referee import EarlyStoppingReferee
|
|
12
|
+
from rapidata.rapidata_client.selection._base_selection import RapidataSelection
|
|
13
|
+
from rapidata.rapidata_client.selection.validation_selection import ValidationSelection
|
|
14
|
+
from rapidata.rapidata_client.selection.labeling_selection import LabelingSelection
|
|
15
|
+
from rapidata.rapidata_client.workflow import (
|
|
16
|
+
Workflow,
|
|
17
|
+
ClassifyWorkflow,
|
|
18
|
+
CompareWorkflow,
|
|
19
|
+
FreeTextWorkflow,
|
|
20
|
+
SelectWordsWorkflow,
|
|
21
|
+
LocateWorkflow,
|
|
22
|
+
DrawWorkflow)
|
|
23
|
+
from rapidata.rapidata_client.selection.validation_selection import ValidationSelection
|
|
24
|
+
from rapidata.rapidata_client.selection.labeling_selection import LabelingSelection
|
|
25
|
+
from rapidata.rapidata_client.assets import MediaAsset, TextAsset, MultiAsset
|
|
26
|
+
from rapidata.rapidata_client.filter import RapidataFilter
|
|
27
|
+
from rapidata.rapidata_client.filter.rapidata_filters import RapidataFilters
|
|
28
|
+
from rapidata.rapidata_client.settings import RapidataSettings, RapidataSetting
|
|
29
|
+
from rapidata.rapidata_client.selection.rapidata_selections import RapidataSelections
|
|
30
|
+
|
|
31
|
+
from rapidata.api_client.exceptions import BadRequestException
|
|
32
|
+
from rapidata.api_client.models.query_model import QueryModel
|
|
33
|
+
from rapidata.api_client.models.page_info import PageInfo
|
|
34
|
+
from rapidata.api_client.models.root_filter import RootFilter
|
|
35
|
+
from rapidata.api_client.models.filter import Filter
|
|
36
|
+
from rapidata.api_client.models.sort_criterion import SortCriterion
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class RapidataOrderManager:
|
|
40
|
+
"""
|
|
41
|
+
Handels everything regarding the orders from creation to retrieval.
|
|
42
|
+
|
|
43
|
+
Attributes:
|
|
44
|
+
filters (RapidataFilters): The RapidataFilters instance.
|
|
45
|
+
settings (RapidataSettings): The RapidataSettings instance.
|
|
46
|
+
selections (RapidataSelections): The RapidataSelections instance."""
|
|
47
|
+
|
|
48
|
+
def __init__(self, openapi_service: OpenAPIService):
|
|
49
|
+
self._openapi_service = openapi_service
|
|
50
|
+
self.filters = RapidataFilters
|
|
51
|
+
self.settings = RapidataSettings
|
|
52
|
+
self.selections = RapidataSelections
|
|
53
|
+
self.__priority = 50
|
|
54
|
+
|
|
55
|
+
def __get_selections(self, validation_set_id: str | None, labeling_amount=3) -> Sequence[RapidataSelection]:
|
|
56
|
+
if validation_set_id:
|
|
57
|
+
return [ValidationSelection(validation_set_id=validation_set_id), LabelingSelection(amount=labeling_amount-1)]
|
|
58
|
+
return [LabelingSelection(amount=labeling_amount)]
|
|
59
|
+
|
|
60
|
+
def __create_general_order(self,
|
|
61
|
+
name: str,
|
|
62
|
+
workflow: Workflow,
|
|
63
|
+
assets: list[MediaAsset] | list[TextAsset] | list[MultiAsset],
|
|
64
|
+
data_type: str = RapidataDataTypes.MEDIA,
|
|
65
|
+
responses_per_datapoint: int = 10,
|
|
66
|
+
contexts: list[str] | None = None,
|
|
67
|
+
validation_set_id: str | None = None,
|
|
68
|
+
confidence_threshold: float | None = None,
|
|
69
|
+
filters: Sequence[RapidataFilter] = [],
|
|
70
|
+
settings: Sequence[RapidataSetting] = [],
|
|
71
|
+
sentences: list[str] | None = None,
|
|
72
|
+
selections: Sequence[RapidataSelection] | None = None,
|
|
73
|
+
default_labeling_amount: int = 3
|
|
74
|
+
) -> RapidataOrder:
|
|
75
|
+
|
|
76
|
+
if contexts and len(contexts) != len(assets):
|
|
77
|
+
raise ValueError("Number of contexts must match number of datapoints")
|
|
78
|
+
|
|
79
|
+
if sentences and len(sentences) != len(assets):
|
|
80
|
+
raise ValueError("Number of sentences must match number of datapoints")
|
|
81
|
+
|
|
82
|
+
if sentences and contexts:
|
|
83
|
+
raise ValueError("You can only use contexts or sentences, not both")
|
|
84
|
+
|
|
85
|
+
if contexts and data_type == RapidataDataTypes.TEXT:
|
|
86
|
+
print("Warning: Contexts are not supported for text data type. Ignoring contexts.")
|
|
87
|
+
|
|
88
|
+
if not confidence_threshold:
|
|
89
|
+
referee = NaiveReferee(responses=responses_per_datapoint)
|
|
90
|
+
else:
|
|
91
|
+
referee = EarlyStoppingReferee(
|
|
92
|
+
threshold=confidence_threshold,
|
|
93
|
+
max_vote_count=responses_per_datapoint,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
order_builder = RapidataOrderBuilder(name=name, openapi_service=self._openapi_service)
|
|
97
|
+
|
|
98
|
+
if selections and validation_set_id:
|
|
99
|
+
print("Warning: You provided both selections and validation_set_id. Ignoring validation_set_id.")
|
|
100
|
+
|
|
101
|
+
if selections is None:
|
|
102
|
+
selections = self.__get_selections(validation_set_id, labeling_amount=default_labeling_amount)
|
|
103
|
+
|
|
104
|
+
prompts_metadata = [PromptMetadata(prompt=prompt) for prompt in contexts] if contexts else None
|
|
105
|
+
sentence_metadata = [SelectWordsMetadata(select_words=sentence) for sentence in sentences] if sentences else None
|
|
106
|
+
|
|
107
|
+
metadata = prompts_metadata or sentence_metadata or None
|
|
108
|
+
|
|
109
|
+
order = (order_builder
|
|
110
|
+
._workflow(workflow)
|
|
111
|
+
._media(
|
|
112
|
+
asset=assets,
|
|
113
|
+
metadata=metadata
|
|
114
|
+
)
|
|
115
|
+
._referee(referee)
|
|
116
|
+
._filters(filters)
|
|
117
|
+
._selections(selections)
|
|
118
|
+
._settings(settings)
|
|
119
|
+
._priority(self.__priority)
|
|
120
|
+
._create()
|
|
121
|
+
)
|
|
122
|
+
return order
|
|
123
|
+
|
|
124
|
+
def _set_priority(self, priority: int):
|
|
125
|
+
self.__priority = priority
|
|
126
|
+
|
|
127
|
+
def create_classification_order(self,
|
|
128
|
+
name: str,
|
|
129
|
+
instruction: str,
|
|
130
|
+
answer_options: list[str],
|
|
131
|
+
datapoints: list[str],
|
|
132
|
+
data_type: str = RapidataDataTypes.MEDIA,
|
|
133
|
+
responses_per_datapoint: int = 10,
|
|
134
|
+
contexts: list[str] | None = None,
|
|
135
|
+
validation_set_id: str | None = None,
|
|
136
|
+
confidence_threshold: float | None = None,
|
|
137
|
+
filters: Sequence[RapidataFilter] = [],
|
|
138
|
+
settings: Sequence[RapidataSetting] = [],
|
|
139
|
+
selections: Sequence[RapidataSelection] | None = None,
|
|
140
|
+
) -> RapidataOrder:
|
|
141
|
+
"""Create a classification order.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
name (str): The name of the order. (Will not be shown to the labeler)
|
|
145
|
+
instruction (str): The instruction for how the data should be classified.
|
|
146
|
+
answer_options (list[str]): The list of options for the classification.
|
|
147
|
+
datapoints (list[str]): The list of datapoints for the classification - each datapoint will be labeled.
|
|
148
|
+
data_type (str, optional): The data type of the datapoints. Defaults to RapidataDataTypes.MEDIA. \n
|
|
149
|
+
Other option: RapidataDataTypes.TEXT ("text").
|
|
150
|
+
responses_per_datapoint (int, optional): The number of responses that will be collected per datapoint. Defaults to 10.
|
|
151
|
+
contexts (list[str], optional): The list of contexts for the classification. Defaults to None.\n
|
|
152
|
+
If provided has to be the same length as datapoints and will be shown in addition to the instruction and options. (Therefore will be different for each datapoint)
|
|
153
|
+
Will be match up with the datapoints using the list index.
|
|
154
|
+
validation_set_id (str, optional): The ID of the validation set. Defaults to None.\n
|
|
155
|
+
If provided, one validation task will be shown infront of the datapoints that will be labeled.
|
|
156
|
+
confidence_threshold (float, optional): The probability threshold for the classification. Defaults to None.\n
|
|
157
|
+
If provided, the classification datapoint will stop after the threshold is reached or at the number of responses, whatever happens first.
|
|
158
|
+
filters (Sequence[RapidataFilter], optional): The list of filters for the classification. Defaults to []. Decides who the tasks should be shown to.
|
|
159
|
+
settings (Sequence[RapidataSetting], optional): The list of settings for the classification. Defaults to []. Decides how the tasks should be shown.
|
|
160
|
+
selections (Sequence[RapidataSelection], optional): The list of selections for the classification. Defaults to None. Decides in what order the tasks should be shown.
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
if data_type == RapidataDataTypes.MEDIA:
|
|
164
|
+
assets = [MediaAsset(path=path) for path in datapoints]
|
|
165
|
+
elif data_type == RapidataDataTypes.TEXT:
|
|
166
|
+
assets = [TextAsset(text=text) for text in datapoints]
|
|
167
|
+
else:
|
|
168
|
+
raise ValueError(f"Unsupported data type: {data_type}, must be one of {RapidataDataTypes._possible_values()}")
|
|
169
|
+
|
|
170
|
+
return self.__create_general_order(
|
|
171
|
+
name=name,
|
|
172
|
+
workflow=ClassifyWorkflow(
|
|
173
|
+
instruction=instruction,
|
|
174
|
+
answer_options=answer_options
|
|
175
|
+
),
|
|
176
|
+
assets=assets,
|
|
177
|
+
data_type=data_type,
|
|
178
|
+
responses_per_datapoint=responses_per_datapoint,
|
|
179
|
+
contexts=contexts,
|
|
180
|
+
validation_set_id=validation_set_id,
|
|
181
|
+
confidence_threshold=confidence_threshold,
|
|
182
|
+
filters=filters,
|
|
183
|
+
selections=selections,
|
|
184
|
+
settings=settings
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
def create_compare_order(self,
|
|
188
|
+
name: str,
|
|
189
|
+
instruction: str,
|
|
190
|
+
datapoints: list[list[str]],
|
|
191
|
+
data_type: str = RapidataDataTypes.MEDIA,
|
|
192
|
+
responses_per_datapoint: int = 10,
|
|
193
|
+
contexts: list[str] | None = None,
|
|
194
|
+
validation_set_id: str | None = None,
|
|
195
|
+
confidence_threshold: float | None = None,
|
|
196
|
+
filters: Sequence[RapidataFilter] = [],
|
|
197
|
+
settings: Sequence[RapidataSetting] = [],
|
|
198
|
+
selections: Sequence[RapidataSelection] | None = None,
|
|
199
|
+
) -> RapidataOrder:
|
|
200
|
+
"""Create a compare order.
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
name (str): The name of the order. (Will not be shown to the labeler)
|
|
204
|
+
instruction (str): The instruction for the comparison. Will be shown along side each datapoint.
|
|
205
|
+
datapoints (list[list[str]]): Outher list is the datapoints, inner list is the options for the comparison - each datapoint will be labeled.
|
|
206
|
+
data_type (str, optional): The data type of the datapoints. Defaults to RapidataDataTypes.MEDIA. \n
|
|
207
|
+
Other option: RapidataDataTypes.TEXT ("text").
|
|
208
|
+
responses_per_datapoint (int, optional): The number of responses that will be collected per datapoint. Defaults to 10.
|
|
209
|
+
contexts (list[str], optional): The list of contexts for the comparison. Defaults to None.\n
|
|
210
|
+
If provided has to be the same length as datapoints and will be shown in addition to the instruction. (Therefore will be different for each datapoint)
|
|
211
|
+
Will be match up with the datapoints using the list index.
|
|
212
|
+
validation_set_id (str, optional): The ID of the validation set. Defaults to None.\n
|
|
213
|
+
If provided, one validation task will be shown infront of the datapoints that will be labeled.
|
|
214
|
+
confidence_threshold (float, optional): The probability threshold for the comparison. Defaults to None.\n
|
|
215
|
+
If provided, the comparison datapoint will stop after the threshold is reached or at the number of responses, whatever happens first.
|
|
216
|
+
filters (Sequence[RapidataFilter], optional): The list of filters for the comparison. Defaults to []. Decides who the tasks should be shown to.
|
|
217
|
+
settings (Sequence[RapidataSetting], optional): The list of settings for the comparison. Defaults to []. Decides how the tasks should be shown.
|
|
218
|
+
selections (Sequence[RapidataSelection], optional): The list of selections for the comparison. Defaults to None. Decides in what order the tasks should be shown.
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
if data_type == RapidataDataTypes.MEDIA:
|
|
222
|
+
assets = [MultiAsset([MediaAsset(path=path) for path in datapoint]) for datapoint in datapoints]
|
|
223
|
+
elif data_type == RapidataDataTypes.TEXT:
|
|
224
|
+
assets = [MultiAsset([TextAsset(text=text) for text in datapoint]) for datapoint in datapoints]
|
|
225
|
+
else:
|
|
226
|
+
raise ValueError(f"Unsupported data type: {data_type}, must be one of {RapidataDataTypes._possible_values()}")
|
|
227
|
+
|
|
228
|
+
return self.__create_general_order(
|
|
229
|
+
name=name,
|
|
230
|
+
workflow=CompareWorkflow(
|
|
231
|
+
instruction=instruction
|
|
232
|
+
),
|
|
233
|
+
assets=assets,
|
|
234
|
+
data_type=data_type,
|
|
235
|
+
responses_per_datapoint=responses_per_datapoint,
|
|
236
|
+
contexts=contexts,
|
|
237
|
+
validation_set_id=validation_set_id,
|
|
238
|
+
confidence_threshold=confidence_threshold,
|
|
239
|
+
filters=filters,
|
|
240
|
+
selections=selections,
|
|
241
|
+
settings=settings
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
def create_free_text_order(self,
|
|
245
|
+
name: str,
|
|
246
|
+
instruction: str,
|
|
247
|
+
datapoints: list[str],
|
|
248
|
+
data_type: str = RapidataDataTypes.MEDIA,
|
|
249
|
+
responses_per_datapoint: int = 10,
|
|
250
|
+
filters: Sequence[RapidataFilter] = [],
|
|
251
|
+
settings: Sequence[RapidataSetting] = [],
|
|
252
|
+
selections: Sequence[RapidataSelection] | None = None,
|
|
253
|
+
) -> RapidataOrder:
|
|
254
|
+
"""Create a free text order.
|
|
255
|
+
|
|
256
|
+
Args:
|
|
257
|
+
name (str): The name of the order.
|
|
258
|
+
instruction (str): The instruction to answer with free text. Will be shown along side each datapoint.
|
|
259
|
+
datapoints (list[str]): The list of datapoints for the free text - each datapoint will be labeled.
|
|
260
|
+
data_type (str, optional): The data type of the datapoints. Defaults to RapidataDataTypes.MEDIA. \n
|
|
261
|
+
Other option: RapidataDataTypes.TEXT ("text").
|
|
262
|
+
responses_per_datapoint (int, optional): The number of responses that will be collected per datapoint. Defaults to 10.
|
|
263
|
+
filters (Sequence[RapidataFilter], optional): The list of filters for the free text. Defaults to []. Decides who the tasks should be shown to.
|
|
264
|
+
settings (Sequence[RapidataSetting], optional): The list of settings for the free text. Defaults to []. Decides how the tasks should be shown.
|
|
265
|
+
selections (Sequence[RapidataSelection], optional): The list of selections for the free text. Defaults to None. Decides in what order the tasks should be shown.
|
|
266
|
+
"""
|
|
267
|
+
|
|
268
|
+
if data_type == RapidataDataTypes.MEDIA:
|
|
269
|
+
assets = [MediaAsset(path=path) for path in datapoints]
|
|
270
|
+
elif data_type == RapidataDataTypes.TEXT:
|
|
271
|
+
assets = [TextAsset(text=text) for text in datapoints]
|
|
272
|
+
else:
|
|
273
|
+
raise ValueError(f"Unsupported data type: {data_type}, must be one of {RapidataDataTypes._possible_values()}")
|
|
274
|
+
|
|
275
|
+
return self.__create_general_order(
|
|
276
|
+
name=name,
|
|
277
|
+
workflow=FreeTextWorkflow(
|
|
278
|
+
instruction=instruction
|
|
279
|
+
),
|
|
280
|
+
assets=assets,
|
|
281
|
+
data_type=data_type,
|
|
282
|
+
responses_per_datapoint=responses_per_datapoint,
|
|
283
|
+
filters=filters,
|
|
284
|
+
selections=selections,
|
|
285
|
+
settings=settings,
|
|
286
|
+
default_labeling_amount=1
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
def create_select_words_order(self,
|
|
290
|
+
name: str,
|
|
291
|
+
instruction: str,
|
|
292
|
+
datapoints: list[str],
|
|
293
|
+
sentences: list[str],
|
|
294
|
+
responses_per_datapoint: int = 10,
|
|
295
|
+
validation_set_id: str | None = None,
|
|
296
|
+
filters: Sequence[RapidataFilter] = [],
|
|
297
|
+
settings: Sequence[RapidataSetting] = [],
|
|
298
|
+
selections: Sequence[RapidataSelection] | None = None,
|
|
299
|
+
) -> RapidataOrder:
|
|
300
|
+
"""Create a select words order.
|
|
301
|
+
|
|
302
|
+
Args:
|
|
303
|
+
name (str): The name of the order.
|
|
304
|
+
instruction (str): The instruction for how the words should be selected. Will be shown along side each datapoint.
|
|
305
|
+
datapoints (list[str]): The list of datapoints for the select words - each datapoint will be labeled.
|
|
306
|
+
sentences (list[str]): The list of sentences for the select words - Will be split up by spaces and shown along side each datapoint.\n
|
|
307
|
+
Must be the same length as datapoints.
|
|
308
|
+
responses_per_datapoint (int, optional): The number of responses that will be collected per datapoint. Defaults to 10.
|
|
309
|
+
validation_set_id (str, optional): The ID of the validation set. Defaults to None.\n
|
|
310
|
+
If provided, one validation task will be shown infront of the datapoints that will be labeled.
|
|
311
|
+
filters (Sequence[RapidataFilter], optional): The list of filters for the select words. Defaults to []. Decides who the tasks should be shown to.
|
|
312
|
+
settings (Sequence[RapidataSetting], optional): The list of settings for the select words. Defaults to []. Decides how the tasks should be shown.
|
|
313
|
+
selections (Sequence[RapidataSelection], optional): The list of selections for the select words. Defaults to None. Decides in what order the tasks should be shown.
|
|
314
|
+
"""
|
|
315
|
+
|
|
316
|
+
assets = [MediaAsset(path=path) for path in datapoints]
|
|
317
|
+
|
|
318
|
+
return self.__create_general_order(
|
|
319
|
+
name=name,
|
|
320
|
+
workflow=SelectWordsWorkflow(
|
|
321
|
+
instruction=instruction
|
|
322
|
+
),
|
|
323
|
+
assets=assets,
|
|
324
|
+
responses_per_datapoint=responses_per_datapoint,
|
|
325
|
+
validation_set_id=validation_set_id,
|
|
326
|
+
filters=filters,
|
|
327
|
+
selections=selections,
|
|
328
|
+
settings=settings,
|
|
329
|
+
sentences=sentences,
|
|
330
|
+
default_labeling_amount=2
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
def create_locate_order(self,
|
|
334
|
+
name: str,
|
|
335
|
+
target: str,
|
|
336
|
+
datapoints: list[str],
|
|
337
|
+
responses_per_datapoint: int = 10,
|
|
338
|
+
contexts: list[str] | None = None,
|
|
339
|
+
validation_set_id: str | None = None,
|
|
340
|
+
filters: Sequence[RapidataFilter] = [],
|
|
341
|
+
settings: Sequence[RapidataSetting] = [],
|
|
342
|
+
selections: Sequence[RapidataSelection] | None = None,
|
|
343
|
+
) -> RapidataOrder:
|
|
344
|
+
"""Create a locate order.
|
|
345
|
+
|
|
346
|
+
Args:
|
|
347
|
+
name (str): The name of the order.
|
|
348
|
+
target (str): The target what should be located. Will be shown along side each datapoint.
|
|
349
|
+
datapoints (list[str]): The list of datapoints for the locate - each datapoint will be labeled.
|
|
350
|
+
responses_per_datapoint (int, optional): The number of responses that will be collected per datapoint. Defaults to 10.
|
|
351
|
+
contexts (list[str], optional): The list of contexts for the comparison. Defaults to None.\n
|
|
352
|
+
If provided has to be the same length as datapoints and will be shown in addition to the instruction. (Therefore will be different for each datapoint)
|
|
353
|
+
Will be match up with the datapoints using the list index.
|
|
354
|
+
validation_set_id (str, optional): The ID of the validation set. Defaults to None.\n
|
|
355
|
+
If provided, one validation task will be shown infront of the datapoints that will be labeled.
|
|
356
|
+
filters (Sequence[RapidataFilter], optional): The list of filters for the locate. Defaults to []. Decides who the tasks should be shown to.
|
|
357
|
+
settings (Sequence[RapidataSetting], optional): The list of settings for the locate. Defaults to []. Decides how the tasks should be shown.
|
|
358
|
+
selections (Sequence[RapidataSelection], optional): The list of selections for the locate. Defaults to None. Decides in what order the tasks should be shown.
|
|
359
|
+
"""
|
|
360
|
+
|
|
361
|
+
assets = [MediaAsset(path=path) for path in datapoints]
|
|
362
|
+
|
|
363
|
+
return self.__create_general_order(
|
|
364
|
+
name=name,
|
|
365
|
+
workflow=LocateWorkflow(target=target),
|
|
366
|
+
assets=assets,
|
|
367
|
+
responses_per_datapoint=responses_per_datapoint,
|
|
368
|
+
contexts=contexts,
|
|
369
|
+
validation_set_id=validation_set_id,
|
|
370
|
+
filters=filters,
|
|
371
|
+
selections=selections,
|
|
372
|
+
settings=settings
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
def create_draw_order(self,
|
|
376
|
+
name: str,
|
|
377
|
+
target: str,
|
|
378
|
+
datapoints: list[str],
|
|
379
|
+
responses_per_datapoint: int = 10,
|
|
380
|
+
contexts: list[str] | None = None,
|
|
381
|
+
validation_set_id: str | None = None,
|
|
382
|
+
filters: Sequence[RapidataFilter] = [],
|
|
383
|
+
settings: Sequence[RapidataSetting] = [],
|
|
384
|
+
selections: Sequence[RapidataSelection] | None = None,
|
|
385
|
+
) -> RapidataOrder:
|
|
386
|
+
"""Create a draw order.
|
|
387
|
+
|
|
388
|
+
Args:
|
|
389
|
+
name (str): The name of the order.
|
|
390
|
+
target (str): The target for how the lines should be drawn. Will be shown along side each datapoint.
|
|
391
|
+
datapoints (list[str]): The list of datapoints for the draw lines - each datapoint will be labeled.
|
|
392
|
+
responses_per_datapoint (int, optional): The number of responses that will be collected per datapoint. Defaults to 10.
|
|
393
|
+
contexts (list[str], optional): The list of contexts for the comparison. Defaults to None.\n
|
|
394
|
+
If provided has to be the same length as datapoints and will be shown in addition to the instruction. (Therefore will be different for each datapoint)
|
|
395
|
+
Will be match up with the datapoints using the list index.
|
|
396
|
+
validation_set_id (str, optional): The ID of the validation set. Defaults to None.\n
|
|
397
|
+
If provided, one validation task will be shown infront of the datapoints that will be labeled.
|
|
398
|
+
filters (Sequence[RapidataFilter], optional): The list of filters for the draw lines. Defaults to []. Decides who the tasks should be shown to.
|
|
399
|
+
settings (Sequence[RapidataSetting], optional): The list of settings for the draw lines. Defaults to []. Decides how the tasks should be shown.
|
|
400
|
+
selections (Sequence[RapidataSelection], optional): The list of selections for the draw lines. Defaults to None. Decides in what order the tasks should be shown.
|
|
401
|
+
"""
|
|
402
|
+
|
|
403
|
+
assets = [MediaAsset(path=path) for path in datapoints]
|
|
404
|
+
|
|
405
|
+
return self.__create_general_order(
|
|
406
|
+
name=name,
|
|
407
|
+
workflow=DrawWorkflow(target=target),
|
|
408
|
+
assets=assets,
|
|
409
|
+
responses_per_datapoint=responses_per_datapoint,
|
|
410
|
+
contexts=contexts,
|
|
411
|
+
validation_set_id=validation_set_id,
|
|
412
|
+
filters=filters,
|
|
413
|
+
selections=selections,
|
|
414
|
+
settings=settings
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
def get_order_by_id(self, order_id: str) -> RapidataOrder:
|
|
418
|
+
"""Get an order by ID.
|
|
419
|
+
|
|
420
|
+
Args:
|
|
421
|
+
order_id (str): The ID of the order.
|
|
422
|
+
|
|
423
|
+
Returns:
|
|
424
|
+
RapidataOrder: The Order instance.
|
|
425
|
+
"""
|
|
426
|
+
|
|
427
|
+
try:
|
|
428
|
+
order = self._openapi_service.order_api.order_get_by_id_get(order_id)
|
|
429
|
+
except Exception:
|
|
430
|
+
raise ValueError(f"Order with ID {order_id} not found.")
|
|
431
|
+
|
|
432
|
+
return RapidataOrder(
|
|
433
|
+
order_id=order_id,
|
|
434
|
+
name=order.order_name,
|
|
435
|
+
openapi_service=self._openapi_service)
|
|
436
|
+
|
|
437
|
+
def find_orders(self, name: str = "", amount: int = 1) -> list[RapidataOrder]:
|
|
438
|
+
"""Find your recent orders given criteria. If nothing is provided, it will return the most recent order.
|
|
439
|
+
|
|
440
|
+
Args:
|
|
441
|
+
name (str, optional): The name of the order - matching order will contain the name. Defaults to "" for any order.
|
|
442
|
+
amount (int, optional): The amount of orders to return. Defaults to 1.
|
|
443
|
+
|
|
444
|
+
Returns:
|
|
445
|
+
list[RapidataOrder]: A list of RapidataOrder instances.
|
|
446
|
+
"""
|
|
447
|
+
try:
|
|
448
|
+
order_page_result = self._openapi_service.order_api.order_query_get(QueryModel(
|
|
449
|
+
page=PageInfo(index=1, size=amount),
|
|
450
|
+
filter=RootFilter(filters=[Filter(field="OrderName", operator="Contains", value=name)]),
|
|
451
|
+
sortCriteria=[SortCriterion(direction="Desc", propertyName="OrderDate")]
|
|
452
|
+
))
|
|
453
|
+
|
|
454
|
+
except BadRequestException as e:
|
|
455
|
+
raise ValueError(f"Error occured during request. \nError: {e.body} \nTraceid: {e.headers.get('X-Trace-Id') if isinstance(e.headers, HTTPHeaderDict) else 'Unknown'}")
|
|
456
|
+
|
|
457
|
+
except Exception as e:
|
|
458
|
+
raise ValueError(f"Unknown error occured: {e}")
|
|
459
|
+
|
|
460
|
+
orders = [self.get_order_by_id(order.id) for order in order_page_result.items]
|
|
461
|
+
return orders
|