rapidata 1.4.6__py3-none-any.whl → 1.6.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.
- rapidata/__init__.py +2 -1
- rapidata/api_client/__init__.py +3 -2
- rapidata/api_client/api/validation_api.py +270 -6
- rapidata/api_client/models/__init__.py +3 -2
- rapidata/api_client/models/get_validation_set_by_id_result.py +94 -0
- rapidata/api_client/models/rapid_answer.py +5 -3
- rapidata/api_client/models/validation_set_model.py +96 -0
- rapidata/api_client/models/validation_set_model_paged_result.py +105 -0
- rapidata/api_client_README.md +4 -2
- rapidata/rapidata_client/__init__.py +1 -1
- rapidata/rapidata_client/dataset/rapidata_validation_set.py +5 -4
- rapidata/rapidata_client/dataset/validation_set_builder.py +1 -0
- rapidata/rapidata_client/order/rapidata_order.py +20 -28
- rapidata/rapidata_client/order/rapidata_order_builder.py +27 -9
- rapidata/rapidata_client/rapidata_client.py +35 -21
- rapidata/rapidata_client/{feature_flags → settings}/__init__.py +1 -0
- rapidata/rapidata_client/{feature_flags → settings}/feature_flags.py +3 -1
- rapidata/rapidata_client/settings/settings.py +123 -0
- rapidata/rapidata_client/workflow/base_workflow.py +3 -3
- rapidata/service/openapi_service.py +30 -3
- {rapidata-1.4.6.dist-info → rapidata-1.6.0.dist-info}/METADATA +1 -1
- {rapidata-1.4.6.dist-info → rapidata-1.6.0.dist-info}/RECORD +24 -24
- rapidata/rapidata_client/utils/__init__.py +0 -0
- rapidata/rapidata_client/utils/utils.py +0 -22
- rapidata/utils/__init__.py +0 -0
- rapidata/utils/image_utils.py +0 -13
- {rapidata-1.4.6.dist-info → rapidata-1.6.0.dist-info}/LICENSE +0 -0
- {rapidata-1.4.6.dist-info → rapidata-1.6.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Rapidata.Dataset
|
|
5
|
+
|
|
6
|
+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: v1
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictInt
|
|
21
|
+
from typing import Any, ClassVar, Dict, List, Optional
|
|
22
|
+
from rapidata.api_client.models.validation_set_model import ValidationSetModel
|
|
23
|
+
from typing import Optional, Set
|
|
24
|
+
from typing_extensions import Self
|
|
25
|
+
|
|
26
|
+
class ValidationSetModelPagedResult(BaseModel):
|
|
27
|
+
"""
|
|
28
|
+
ValidationSetModelPagedResult
|
|
29
|
+
""" # noqa: E501
|
|
30
|
+
total: StrictInt
|
|
31
|
+
page: StrictInt
|
|
32
|
+
page_size: StrictInt = Field(alias="pageSize")
|
|
33
|
+
items: List[ValidationSetModel]
|
|
34
|
+
total_pages: Optional[StrictInt] = Field(default=None, alias="totalPages")
|
|
35
|
+
__properties: ClassVar[List[str]] = ["total", "page", "pageSize", "items", "totalPages"]
|
|
36
|
+
|
|
37
|
+
model_config = ConfigDict(
|
|
38
|
+
populate_by_name=True,
|
|
39
|
+
validate_assignment=True,
|
|
40
|
+
protected_namespaces=(),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def to_str(self) -> str:
|
|
45
|
+
"""Returns the string representation of the model using alias"""
|
|
46
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
47
|
+
|
|
48
|
+
def to_json(self) -> str:
|
|
49
|
+
"""Returns the JSON representation of the model using alias"""
|
|
50
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
51
|
+
return json.dumps(self.to_dict())
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
55
|
+
"""Create an instance of ValidationSetModelPagedResult from a JSON string"""
|
|
56
|
+
return cls.from_dict(json.loads(json_str))
|
|
57
|
+
|
|
58
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
59
|
+
"""Return the dictionary representation of the model using alias.
|
|
60
|
+
|
|
61
|
+
This has the following differences from calling pydantic's
|
|
62
|
+
`self.model_dump(by_alias=True)`:
|
|
63
|
+
|
|
64
|
+
* `None` is only added to the output dict for nullable fields that
|
|
65
|
+
were set at model initialization. Other fields with value `None`
|
|
66
|
+
are ignored.
|
|
67
|
+
* OpenAPI `readOnly` fields are excluded.
|
|
68
|
+
"""
|
|
69
|
+
excluded_fields: Set[str] = set([
|
|
70
|
+
"total_pages",
|
|
71
|
+
])
|
|
72
|
+
|
|
73
|
+
_dict = self.model_dump(
|
|
74
|
+
by_alias=True,
|
|
75
|
+
exclude=excluded_fields,
|
|
76
|
+
exclude_none=True,
|
|
77
|
+
)
|
|
78
|
+
# override the default output from pydantic by calling `to_dict()` of each item in items (list)
|
|
79
|
+
_items = []
|
|
80
|
+
if self.items:
|
|
81
|
+
for _item_items in self.items:
|
|
82
|
+
if _item_items:
|
|
83
|
+
_items.append(_item_items.to_dict())
|
|
84
|
+
_dict['items'] = _items
|
|
85
|
+
return _dict
|
|
86
|
+
|
|
87
|
+
@classmethod
|
|
88
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
89
|
+
"""Create an instance of ValidationSetModelPagedResult from a dict"""
|
|
90
|
+
if obj is None:
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
if not isinstance(obj, dict):
|
|
94
|
+
return cls.model_validate(obj)
|
|
95
|
+
|
|
96
|
+
_obj = cls.model_validate({
|
|
97
|
+
"total": obj.get("total"),
|
|
98
|
+
"page": obj.get("page"),
|
|
99
|
+
"pageSize": obj.get("pageSize"),
|
|
100
|
+
"items": [ValidationSetModel.from_dict(_item) for _item in obj["items"]] if obj.get("items") is not None else None,
|
|
101
|
+
"totalPages": obj.get("totalPages")
|
|
102
|
+
})
|
|
103
|
+
return _obj
|
|
104
|
+
|
|
105
|
+
|
rapidata/api_client_README.md
CHANGED
|
@@ -128,6 +128,7 @@ Class | Method | HTTP request | Description
|
|
|
128
128
|
*ValidationApi* | [**validation_add_validation_text_rapid_post**](rapidata/api_client/docs/ValidationApi.md#validation_add_validation_text_rapid_post) | **POST** /Validation/AddValidationTextRapid | Adds a new validation rapid to the specified validation set.
|
|
129
129
|
*ValidationApi* | [**validation_create_validation_set_post**](rapidata/api_client/docs/ValidationApi.md#validation_create_validation_set_post) | **POST** /Validation/CreateValidationSet | Creates a new empty validation set.
|
|
130
130
|
*ValidationApi* | [**validation_get_available_validation_sets_get**](rapidata/api_client/docs/ValidationApi.md#validation_get_available_validation_sets_get) | **GET** /Validation/GetAvailableValidationSets | Gets the available validation sets for the current user.
|
|
131
|
+
*ValidationApi* | [**validation_get_by_id_get**](rapidata/api_client/docs/ValidationApi.md#validation_get_by_id_get) | **GET** /Validation/GetById | Gets a validation set by the id.
|
|
131
132
|
*ValidationApi* | [**validation_import_compare_post**](rapidata/api_client/docs/ValidationApi.md#validation_import_compare_post) | **POST** /Validation/ImportCompare | Imports a compare validation set from a zip file.
|
|
132
133
|
*ValidationApi* | [**validation_import_post**](rapidata/api_client/docs/ValidationApi.md#validation_import_post) | **POST** /Validation/Import | Imports a validation set from a zip file.
|
|
133
134
|
*ValidationApi* | [**validation_query_validation_sets_get**](rapidata/api_client/docs/ValidationApi.md#validation_query_validation_sets_get) | **GET** /Validation/QueryValidationSets | Queries validation sets based on the provided filter, paging and sorting criteria.
|
|
@@ -255,6 +256,7 @@ Class | Method | HTTP request | Description
|
|
|
255
256
|
- [GetPipelineByIdResultArtifactsValue](rapidata/api_client/docs/GetPipelineByIdResultArtifactsValue.md)
|
|
256
257
|
- [GetPublicOrdersResult](rapidata/api_client/docs/GetPublicOrdersResult.md)
|
|
257
258
|
- [GetSimpleWorkflowResultOverviewResult](rapidata/api_client/docs/GetSimpleWorkflowResultOverviewResult.md)
|
|
259
|
+
- [GetValidationSetByIdResult](rapidata/api_client/docs/GetValidationSetByIdResult.md)
|
|
258
260
|
- [GetWorkflowByIdResult](rapidata/api_client/docs/GetWorkflowByIdResult.md)
|
|
259
261
|
- [GetWorkflowByIdResultWorkflow](rapidata/api_client/docs/GetWorkflowByIdResultWorkflow.md)
|
|
260
262
|
- [GetWorkflowProgressResult](rapidata/api_client/docs/GetWorkflowProgressResult.md)
|
|
@@ -380,9 +382,9 @@ Class | Method | HTTP request | Description
|
|
|
380
382
|
- [ValidationChance](rapidata/api_client/docs/ValidationChance.md)
|
|
381
383
|
- [ValidationImportPostRequestBlueprint](rapidata/api_client/docs/ValidationImportPostRequestBlueprint.md)
|
|
382
384
|
- [ValidationSelection](rapidata/api_client/docs/ValidationSelection.md)
|
|
383
|
-
- [
|
|
385
|
+
- [ValidationSetModel](rapidata/api_client/docs/ValidationSetModel.md)
|
|
386
|
+
- [ValidationSetModelPagedResult](rapidata/api_client/docs/ValidationSetModelPagedResult.md)
|
|
384
387
|
- [ValidationSetOverviewModel](rapidata/api_client/docs/ValidationSetOverviewModel.md)
|
|
385
|
-
- [ValidationSetPagedResult](rapidata/api_client/docs/ValidationSetPagedResult.md)
|
|
386
388
|
- [WorkflowAggregationStepModel](rapidata/api_client/docs/WorkflowAggregationStepModel.md)
|
|
387
389
|
- [WorkflowArtifactModel](rapidata/api_client/docs/WorkflowArtifactModel.md)
|
|
388
390
|
- [WorkflowConfigArtifactModel](rapidata/api_client/docs/WorkflowConfigArtifactModel.md)
|
|
@@ -19,7 +19,7 @@ from .metadata import (
|
|
|
19
19
|
PromptMetadata,
|
|
20
20
|
TranscriptionMetadata,
|
|
21
21
|
)
|
|
22
|
-
from .
|
|
22
|
+
from .settings import Settings, FeatureFlags # remove FeatureFlags next major version
|
|
23
23
|
from .country_codes import CountryCodes
|
|
24
24
|
from .assets import MediaAsset, TextAsset, MultiAsset
|
|
25
25
|
from .filter import (
|
|
@@ -47,9 +47,10 @@ class RapidataValidationSet:
|
|
|
47
47
|
Get a `ValidationSet` either by using `rapi.get_validation_set(id)` to get an existing validation set or by using `rapi.new_validation_set(name)` to create a new validation set.
|
|
48
48
|
"""
|
|
49
49
|
|
|
50
|
-
def __init__(self, validation_set_id, openapi_service: OpenAPIService):
|
|
50
|
+
def __init__(self, validation_set_id, openapi_service: OpenAPIService, name: str):
|
|
51
51
|
self.id = validation_set_id
|
|
52
52
|
self.openapi_service = openapi_service
|
|
53
|
+
self.name = name
|
|
53
54
|
|
|
54
55
|
def add_general_validation_rapid(
|
|
55
56
|
self,
|
|
@@ -153,7 +154,7 @@ class RapidataValidationSet:
|
|
|
153
154
|
else:
|
|
154
155
|
raise ValueError("Invalid asset type")
|
|
155
156
|
|
|
156
|
-
def
|
|
157
|
+
def add_classify_rapid(
|
|
157
158
|
self,
|
|
158
159
|
asset: MediaAsset | TextAsset,
|
|
159
160
|
question: str,
|
|
@@ -188,7 +189,7 @@ class RapidataValidationSet:
|
|
|
188
189
|
randomCorrectProbability=len(truths) / len(categories),
|
|
189
190
|
)
|
|
190
191
|
|
|
191
|
-
def
|
|
192
|
+
def add_compare_rapid(
|
|
192
193
|
self,
|
|
193
194
|
asset: MultiAsset,
|
|
194
195
|
question: str,
|
|
@@ -225,7 +226,7 @@ class RapidataValidationSet:
|
|
|
225
226
|
randomCorrectProbability=1 / len(asset),
|
|
226
227
|
)
|
|
227
228
|
|
|
228
|
-
def
|
|
229
|
+
def add_transcription_rapid(
|
|
229
230
|
self,
|
|
230
231
|
asset: MediaAsset | TextAsset,
|
|
231
232
|
question: str,
|
|
@@ -3,7 +3,7 @@ from rapidata.rapidata_client.dataset.rapidata_dataset import RapidataDataset
|
|
|
3
3
|
from rapidata.service.openapi_service import OpenAPIService
|
|
4
4
|
import json
|
|
5
5
|
from rapidata.api_client.exceptions import ApiException
|
|
6
|
-
from typing import Optional, cast
|
|
6
|
+
from typing import Optional, cast, Any
|
|
7
7
|
from rapidata.api_client.models.workflow_artifact_model import WorkflowArtifactModel
|
|
8
8
|
from tqdm import tqdm
|
|
9
9
|
|
|
@@ -11,12 +11,11 @@ class RapidataOrder:
|
|
|
11
11
|
"""
|
|
12
12
|
Represents a Rapidata order.
|
|
13
13
|
|
|
14
|
-
:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
:type rapidata_service: RapidataService
|
|
14
|
+
Args:
|
|
15
|
+
The ID of the order.
|
|
16
|
+
The optional Dataset associated with the order.
|
|
17
|
+
The OpenAPIService instance used to interact with the Rapidata API.
|
|
18
|
+
The name of the order.
|
|
20
19
|
"""
|
|
21
20
|
|
|
22
21
|
def __init__(
|
|
@@ -36,30 +35,23 @@ class RapidataOrder:
|
|
|
36
35
|
"""
|
|
37
36
|
Submits the order for processing.
|
|
38
37
|
"""
|
|
39
|
-
|
|
40
38
|
self.openapi_service.order_api.order_submit_post(self.order_id)
|
|
41
39
|
|
|
42
|
-
def
|
|
43
|
-
"""
|
|
44
|
-
Approves the order for execution.
|
|
45
|
-
"""
|
|
46
|
-
self.openapi_service.order_api.order_approve_post(self.order_id)
|
|
47
|
-
|
|
48
|
-
def get_status(self):
|
|
40
|
+
def get_status(self) -> str:
|
|
49
41
|
"""
|
|
50
42
|
Gets the status of the order.
|
|
51
|
-
|
|
52
|
-
:
|
|
53
|
-
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
The status of the order.
|
|
54
46
|
"""
|
|
55
|
-
return self.openapi_service.order_api.order_get_by_id_get(self.order_id)
|
|
47
|
+
return self.openapi_service.order_api.order_get_by_id_get(self.order_id).state
|
|
56
48
|
|
|
57
49
|
def display_progress_bar(self, refresh_rate=5):
|
|
58
50
|
"""
|
|
59
51
|
Displays a progress bar for the order processing using tqdm.
|
|
60
52
|
|
|
61
|
-
:
|
|
62
|
-
|
|
53
|
+
Prameter:
|
|
54
|
+
How often to refresh the progress bar, in seconds.
|
|
63
55
|
"""
|
|
64
56
|
total_rapids = self._get_workflow_progress().total
|
|
65
57
|
with tqdm(total=total_rapids, desc="Processing order", unit="rapids") as pbar:
|
|
@@ -107,15 +99,15 @@ class RapidataOrder:
|
|
|
107
99
|
return progress
|
|
108
100
|
|
|
109
101
|
|
|
110
|
-
def get_results(self):
|
|
102
|
+
def get_results(self) -> dict[str, Any]:
|
|
111
103
|
"""
|
|
112
104
|
Gets the results of the order.
|
|
113
105
|
If the order is still processing, this method will block until the order is completed and then return the results.
|
|
114
106
|
|
|
115
|
-
:
|
|
116
|
-
|
|
107
|
+
Returns:
|
|
108
|
+
The results of the order.
|
|
117
109
|
"""
|
|
118
|
-
while self.get_status()
|
|
110
|
+
while self.get_status() == "Processing":
|
|
119
111
|
sleep(5)
|
|
120
112
|
|
|
121
113
|
try:
|
|
@@ -131,10 +123,10 @@ class RapidataOrder:
|
|
|
131
123
|
raise Exception(f"Failed to parse order results: {str(e)}") from e
|
|
132
124
|
|
|
133
125
|
@property
|
|
134
|
-
def dataset(self):
|
|
126
|
+
def dataset(self) -> RapidataDataset | None:
|
|
135
127
|
"""
|
|
136
128
|
The dataset associated with the order.
|
|
137
|
-
:
|
|
138
|
-
|
|
129
|
+
Returns:
|
|
130
|
+
The RapidataDataset instance.
|
|
139
131
|
"""
|
|
140
132
|
return self._dataset
|
|
@@ -14,11 +14,7 @@ from rapidata.api_client.models.create_order_model_user_filters_inner import (
|
|
|
14
14
|
from rapidata.api_client.models.create_order_model_workflow import (
|
|
15
15
|
CreateOrderModelWorkflow,
|
|
16
16
|
)
|
|
17
|
-
from rapidata.
|
|
18
|
-
from rapidata.api_client.models.language_user_filter_model import (
|
|
19
|
-
LanguageUserFilterModel,
|
|
20
|
-
)
|
|
21
|
-
from rapidata.rapidata_client.feature_flags import FeatureFlags
|
|
17
|
+
from rapidata.rapidata_client.settings import FeatureFlags, Settings
|
|
22
18
|
from rapidata.rapidata_client.metadata.base_metadata import Metadata
|
|
23
19
|
from rapidata.rapidata_client.dataset.rapidata_dataset import RapidataDataset
|
|
24
20
|
from rapidata.rapidata_client.referee.naive_referee import NaiveReferee
|
|
@@ -35,6 +31,8 @@ from rapidata.rapidata_client.assets import MediaAsset, TextAsset, MultiAsset
|
|
|
35
31
|
|
|
36
32
|
from typing import Optional, cast, Sequence
|
|
37
33
|
|
|
34
|
+
from deprecated import deprecated
|
|
35
|
+
|
|
38
36
|
|
|
39
37
|
class RapidataOrderBuilder:
|
|
40
38
|
"""Builder object for creating Rapidata orders.
|
|
@@ -66,7 +64,7 @@ class RapidataOrderBuilder:
|
|
|
66
64
|
self._metadata: list[Metadata] | None = None
|
|
67
65
|
self._aggregator: AggregatorType | None = None
|
|
68
66
|
self._validation_set_id: str | None = None
|
|
69
|
-
self.
|
|
67
|
+
self._settings: Settings | FeatureFlags | None = None # remove featureflag next big release
|
|
70
68
|
self._user_filters: list[Filter] = []
|
|
71
69
|
self._selections: list[Selection] = []
|
|
72
70
|
self._rapids_per_bag: int = 2
|
|
@@ -101,8 +99,8 @@ class RapidataOrderBuilder:
|
|
|
101
99
|
referee=CreateOrderModelReferee(self._referee.to_model()),
|
|
102
100
|
validationSetId=self._validation_set_id,
|
|
103
101
|
featureFlags=(
|
|
104
|
-
self.
|
|
105
|
-
if self.
|
|
102
|
+
self._settings.to_list()
|
|
103
|
+
if self._settings is not None
|
|
106
104
|
else None
|
|
107
105
|
),
|
|
108
106
|
selections=[
|
|
@@ -269,6 +267,26 @@ class RapidataOrderBuilder:
|
|
|
269
267
|
self._metadata = metadata # type: ignore
|
|
270
268
|
return self
|
|
271
269
|
|
|
270
|
+
def settings(self, settings: Settings) -> "RapidataOrderBuilder":
|
|
271
|
+
"""
|
|
272
|
+
Set the settings for the order.
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
settings (Settings): The settings to be set.
|
|
276
|
+
|
|
277
|
+
Returns:
|
|
278
|
+
RapidataOrderBuilder: The updated RapidataOrderBuilder instance.
|
|
279
|
+
"""
|
|
280
|
+
if not isinstance(settings, Settings):
|
|
281
|
+
raise TypeError("Settings must be of type Settings.")
|
|
282
|
+
|
|
283
|
+
self._settings = settings
|
|
284
|
+
return self
|
|
285
|
+
|
|
286
|
+
@deprecated(
|
|
287
|
+
version="1.6.0",
|
|
288
|
+
reason="The feature_flags method is deprecated, use settings instead.",
|
|
289
|
+
)
|
|
272
290
|
def feature_flags(self, feature_flags: FeatureFlags) -> "RapidataOrderBuilder":
|
|
273
291
|
"""
|
|
274
292
|
Set the feature flags for the order.
|
|
@@ -282,7 +300,7 @@ class RapidataOrderBuilder:
|
|
|
282
300
|
if not isinstance(feature_flags, FeatureFlags):
|
|
283
301
|
raise TypeError("Feature flags must be of type FeatureFlags.")
|
|
284
302
|
|
|
285
|
-
self.
|
|
303
|
+
self._settings = feature_flags
|
|
286
304
|
return self
|
|
287
305
|
|
|
288
306
|
def filters(self, filters: Sequence[Filter]) -> "RapidataOrderBuilder":
|
|
@@ -3,7 +3,6 @@ from rapidata.rapidata_client.dataset.rapidata_validation_set import (
|
|
|
3
3
|
)
|
|
4
4
|
from rapidata.rapidata_client.dataset.validation_set_builder import ValidationSetBuilder
|
|
5
5
|
from rapidata.rapidata_client.order.rapidata_order_builder import RapidataOrderBuilder
|
|
6
|
-
from rapidata.rapidata_client.utils.utils import Utils
|
|
7
6
|
from rapidata.service.openapi_service import OpenAPIService
|
|
8
7
|
from rapidata.rapidata_client.order.rapidata_order import RapidataOrder
|
|
9
8
|
from rapidata.rapidata_client.dataset.rapidata_dataset import RapidataDataset
|
|
@@ -20,6 +19,8 @@ from rapidata.api_client.models.root_filter import RootFilter
|
|
|
20
19
|
from rapidata.api_client.models.filter import Filter
|
|
21
20
|
from rapidata.api_client.models.sort_criterion import SortCriterion
|
|
22
21
|
|
|
22
|
+
from rapidata.api_client.models.query_validation_set_model import QueryValidationSetModel
|
|
23
|
+
|
|
23
24
|
|
|
24
25
|
class RapidataClient:
|
|
25
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()`."""
|
|
@@ -71,17 +72,6 @@ class RapidataClient:
|
|
|
71
72
|
"""
|
|
72
73
|
return ValidationSetBuilder(name=name, openapi_service=self.openapi_service)
|
|
73
74
|
|
|
74
|
-
def get_validation_set(self, validation_set_id: str) -> RapidataValidationSet:
|
|
75
|
-
"""Get a validation set by ID.
|
|
76
|
-
|
|
77
|
-
Args:
|
|
78
|
-
validation_set_id (str): The ID of the validation set.
|
|
79
|
-
|
|
80
|
-
Returns:
|
|
81
|
-
RapidataValidationSet: The ValidationSet instance.
|
|
82
|
-
"""
|
|
83
|
-
return RapidataValidationSet(validation_set_id, self.openapi_service)
|
|
84
|
-
|
|
85
75
|
def get_order(self, order_id: str) -> RapidataOrder:
|
|
86
76
|
"""Get an order by ID.
|
|
87
77
|
|
|
@@ -132,6 +122,39 @@ class RapidataClient:
|
|
|
132
122
|
|
|
133
123
|
orders = [self.get_order(order.id) for order in order_page_result.items]
|
|
134
124
|
return orders
|
|
125
|
+
|
|
126
|
+
def get_validation_set(self, validation_set_id: str) -> RapidataValidationSet:
|
|
127
|
+
"""Get a validation set by ID.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
validation_set_id (str): The ID of the validation set.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
RapidataValidationSet: The ValidationSet instance.
|
|
134
|
+
"""
|
|
135
|
+
try:
|
|
136
|
+
validation_set = self.openapi_service.validation_api.validation_get_by_id_get(id=validation_set_id)
|
|
137
|
+
except Exception:
|
|
138
|
+
raise ValueError(f"ValidationSet with ID {validation_set_id} not found.")
|
|
139
|
+
|
|
140
|
+
return RapidataValidationSet(validation_set_id, self.openapi_service, validation_set.name)
|
|
141
|
+
|
|
142
|
+
def find_validation_sets(self, name: str = "", amount: int = 1) -> list[RapidataValidationSet]:
|
|
143
|
+
try:
|
|
144
|
+
validation_page_result = self.openapi_service.validation_api.validation_query_validation_sets_get(QueryValidationSetModel(
|
|
145
|
+
pageInfo=PageInfo(index=1, size=amount),
|
|
146
|
+
filter=RootFilter(filters=[Filter(field="Name", operator="Contains", value=name)]),
|
|
147
|
+
sortCriteria=[SortCriterion(direction="Desc", propertyName="CreatedAt")]
|
|
148
|
+
))
|
|
149
|
+
|
|
150
|
+
except BadRequestException as e:
|
|
151
|
+
raise ValueError(f"Error occured during request. \nError: {e.body} \nTraceid: {e.headers.get('X-Trace-Id') if isinstance(e.headers, HTTPHeaderDict) else 'Unknown'}")
|
|
152
|
+
|
|
153
|
+
except Exception as e:
|
|
154
|
+
raise ValueError(f"Unknown error occured: {e}")
|
|
155
|
+
|
|
156
|
+
orders = [self.get_validation_set(validation_set.id) for validation_set in validation_page_result.items] # type: ignore # will be fixed with the next backend deployment
|
|
157
|
+
return orders
|
|
135
158
|
|
|
136
159
|
def create_classify_order(self, name: str) -> ClassificationQuestionBuilder:
|
|
137
160
|
"""Create a new classification order where people are asked to classify an image.
|
|
@@ -154,12 +177,3 @@ class RapidataClient:
|
|
|
154
177
|
CompareQuestionBuilder: A CompareQuestionBuilder instance.
|
|
155
178
|
"""
|
|
156
179
|
return CompareCriteriaBuilder(name=name, openapi_service=self.openapi_service)
|
|
157
|
-
|
|
158
|
-
@property
|
|
159
|
-
def utils(self) -> Utils:
|
|
160
|
-
"""Get the Utils instance.
|
|
161
|
-
|
|
162
|
-
Returns:
|
|
163
|
-
Utils: The Utils instance associated with this client.
|
|
164
|
-
"""
|
|
165
|
-
return Utils(openapi_service=self.openapi_service)
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
from rapidata.api_client.models.feature_flag_model import FeatureFlagModel
|
|
2
2
|
from enum import Enum
|
|
3
|
+
from deprecated import deprecated
|
|
3
4
|
|
|
4
5
|
class TranslationBehaviour(Enum):
|
|
5
6
|
BOTH = "both"
|
|
6
7
|
ONLY_ORIGINAL = "only original"
|
|
7
8
|
ONLY_TRANSLATED = "only translated"
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
@deprecated(version="1.6.0", reason="Use the Settings class instead.")
|
|
10
11
|
class FeatureFlags:
|
|
11
12
|
"""A class to manage feature flags.
|
|
12
13
|
|
|
@@ -17,6 +18,7 @@ class FeatureFlags:
|
|
|
17
18
|
_flags (dict[str, str]): A dictionary to store feature flags.
|
|
18
19
|
"""
|
|
19
20
|
|
|
21
|
+
@deprecated(version="1.6.0", reason="Use the Settings class instead.")
|
|
20
22
|
def __init__(self):
|
|
21
23
|
"""Initialize the FeatureFlags object with an empty flags dictionary."""
|
|
22
24
|
self._flags: dict[str, str] = {}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from rapidata.api_client.models.feature_flag_model import FeatureFlagModel
|
|
2
|
+
from enum import Enum
|
|
3
|
+
|
|
4
|
+
class TranslationBehaviour(Enum):
|
|
5
|
+
BOTH = "both"
|
|
6
|
+
ONLY_ORIGINAL = "only original"
|
|
7
|
+
ONLY_TRANSLATED = "only translated"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Settings:
|
|
11
|
+
"""A class to manage settings.
|
|
12
|
+
|
|
13
|
+
This class provides methods to set and manage various settings
|
|
14
|
+
used in the application.
|
|
15
|
+
|
|
16
|
+
Attributes:
|
|
17
|
+
_settings (dict[str, str]): A dictionary to store settings.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self):
|
|
21
|
+
"""Initialize the Settings object with an empty flags dictionary."""
|
|
22
|
+
self._settings: dict[str, str] = {}
|
|
23
|
+
|
|
24
|
+
def to_list(self) -> list[FeatureFlagModel]:
|
|
25
|
+
"""Convert the settings to a list of FeatureFlagModel objects.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
list[FeatureFlagModel]: A list of FeatureFlagModel objects
|
|
29
|
+
representing the current settings.
|
|
30
|
+
"""
|
|
31
|
+
return [
|
|
32
|
+
FeatureFlagModel(key=name, value=value)
|
|
33
|
+
for name, value in self._settings.items()
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
def alert_on_fast_response(self, milliseconds: int):
|
|
37
|
+
"""Gives an alert as a pop up on the UI when the response time is less than the threshold.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
milliseconds (int): if the user responds in less than this time, an alert will be shown.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
Settings: The current Settings instance for method chaining.
|
|
44
|
+
"""
|
|
45
|
+
if milliseconds < 10:
|
|
46
|
+
print(
|
|
47
|
+
f"Warning: Are you sure you want to set the threshold so low ({milliseconds} milliseconds)?"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if milliseconds > 30000:
|
|
51
|
+
print(
|
|
52
|
+
f"Warning: Are you sure you want to set the threshold so high ({milliseconds/1000} seconds)?"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
self._settings["alert_on_fast_response"] = str(milliseconds)
|
|
56
|
+
return self
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def translation_behaviour(self, behaviour: TranslationBehaviour = TranslationBehaviour.BOTH):
|
|
60
|
+
"""Defines what's the behaviour of the translation in the UI.
|
|
61
|
+
|
|
62
|
+
The behaviour can be set to:
|
|
63
|
+
- TranslationBehaviour.BOTH: Show both the original and the translated text.
|
|
64
|
+
- TranslationBehaviour.ONLY_ORIGINAL: Show only the original text.
|
|
65
|
+
- TranslationBehaviour.ONLY_TRANSLATED: Show only the translated text.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
behaviour (TranslationBehaviour): The translation behaviour. Defaults to TranslationBehaviour.BOTH.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Settings: The current Settings instance for method chaining.
|
|
72
|
+
"""
|
|
73
|
+
self._settings["translation_behaviour"] = behaviour.value
|
|
74
|
+
return self
|
|
75
|
+
|
|
76
|
+
def free_text_minimum_characters(self, value: int):
|
|
77
|
+
"""Set the minimum number of characters a user has to type before the task can be successfully submitted.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
value (int): The minimum number of characters for free text.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
Settings: The current Settings instance for method chaining.
|
|
84
|
+
"""
|
|
85
|
+
self._settings["free_text_minimum_characters"] = str(value)
|
|
86
|
+
return self
|
|
87
|
+
|
|
88
|
+
def no_shuffle(self, value: bool = True):
|
|
89
|
+
"""Only for classify tasks. If true, the order of the categories will be the same as the one in the workflow.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
value (bool, optional): Whether to disable shuffling. Defaults to True.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
Settings: The current Settings instance for method chaining.
|
|
96
|
+
"""
|
|
97
|
+
self._settings["no_shuffle"] = str(value)
|
|
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
|
+
|
|
103
|
+
Args:
|
|
104
|
+
value (bool, optional): Whether to enable compare with prompt design. Defaults to True.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
Settings: The current Settings instance for method chaining.
|
|
108
|
+
"""
|
|
109
|
+
self._settings["claire"] = str(value)
|
|
110
|
+
return self
|
|
111
|
+
|
|
112
|
+
def key_value(self, key: str, value: str):
|
|
113
|
+
"""Set a custom setting with the given key and value. Use this to enable features that do not have a dedicated method (yet).
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
key (str): The key for the custom setting.
|
|
117
|
+
value (str): The value for the custom setting.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
Settings: The current Settings instance for method chaining.
|
|
121
|
+
"""
|
|
122
|
+
self._settings[key] = value
|
|
123
|
+
return self
|
|
@@ -4,7 +4,7 @@ from typing import Any
|
|
|
4
4
|
from rapidata.api_client.models.simple_workflow_model import SimpleWorkflowModel
|
|
5
5
|
from rapidata.api_client.models.evaluation_workflow_model import EvaluationWorkflowModel
|
|
6
6
|
from rapidata.api_client.models.compare_workflow_model import CompareWorkflowModel
|
|
7
|
-
from rapidata.rapidata_client.
|
|
7
|
+
from rapidata.rapidata_client.settings import Settings
|
|
8
8
|
from rapidata.rapidata_client.referee.base_referee import Referee
|
|
9
9
|
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ class Workflow(ABC):
|
|
|
13
13
|
def __init__(self, type: str):
|
|
14
14
|
self._type = type
|
|
15
15
|
self._target_country_codes: list[str] = []
|
|
16
|
-
self._feature_flags:
|
|
16
|
+
self._feature_flags: Settings = Settings()
|
|
17
17
|
|
|
18
18
|
def to_dict(self) -> dict[str, Any]:
|
|
19
19
|
return {
|
|
@@ -37,6 +37,6 @@ class Workflow(ABC):
|
|
|
37
37
|
self._target_country_codes = target_country_codes
|
|
38
38
|
return self
|
|
39
39
|
|
|
40
|
-
def feature_flags(self, feature_flags:
|
|
40
|
+
def feature_flags(self, feature_flags: Settings):
|
|
41
41
|
self._feature_flags = feature_flags
|
|
42
42
|
return self
|