rapidata 1.7.0__py3-none-any.whl → 1.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rapidata might be problematic. Click here for more details.
- rapidata/api_client/__init__.py +6 -1
- rapidata/api_client/api/__init__.py +1 -0
- rapidata/api_client/api/client_api.py +836 -0
- rapidata/api_client/api/identity_api.py +305 -49
- rapidata/api_client/api/order_api.py +7 -7
- rapidata/api_client/models/__init__.py +5 -1
- rapidata/api_client/models/clients_query_result.py +107 -0
- rapidata/api_client/models/clients_query_result_paged_result.py +105 -0
- rapidata/api_client/models/create_bridge_token_result.py +89 -0
- rapidata/api_client/models/create_client_model.py +1 -1
- rapidata/api_client/models/evaluation_workflow_config.py +5 -3
- rapidata/api_client/models/evaluation_workflow_model.py +5 -3
- rapidata/api_client/models/problem_details.py +133 -0
- rapidata/api_client/models/query_model.py +8 -8
- rapidata/api_client/models/read_bridge_token_keys_result.py +127 -0
- rapidata/api_client_README.md +10 -2
- rapidata/rapidata_client/assets/__init__.py +1 -1
- rapidata/rapidata_client/assets/media_asset.py +22 -0
- rapidata/rapidata_client/assets/text_asset.py +3 -0
- rapidata/rapidata_client/country_codes/country_codes.py +1 -1
- rapidata/rapidata_client/dataset/rapid_builders/__init__.py +4 -0
- rapidata/rapidata_client/dataset/rapid_builders/base_rapid_builder.py +33 -0
- rapidata/rapidata_client/dataset/rapid_builders/classify_rapid_builders.py +166 -0
- rapidata/rapidata_client/dataset/rapid_builders/compare_rapid_builders.py +145 -0
- rapidata/rapidata_client/dataset/rapid_builders/rapids.py +32 -0
- rapidata/rapidata_client/dataset/rapid_builders/transcription_rapid_builders.py +132 -0
- rapidata/rapidata_client/dataset/rapidata_dataset.py +12 -9
- rapidata/rapidata_client/dataset/rapidata_validation_set.py +24 -7
- rapidata/rapidata_client/dataset/validation_set_builder.py +115 -8
- rapidata/rapidata_client/filter/country_filter.py +3 -0
- rapidata/rapidata_client/filter/language_filter.py +3 -0
- rapidata/rapidata_client/metadata/prompt_metadata.py +5 -1
- rapidata/rapidata_client/order/rapidata_order.py +1 -1
- rapidata/rapidata_client/order/rapidata_order_builder.py +5 -5
- rapidata/rapidata_client/rapidata_client.py +37 -9
- rapidata/rapidata_client/settings/__init__.py +1 -1
- rapidata/rapidata_client/settings/settings.py +10 -9
- rapidata/rapidata_client/simple_builders/simple_classification_builders.py +132 -21
- rapidata/rapidata_client/simple_builders/simple_compare_builders.py +141 -15
- rapidata/rapidata_client/simple_builders/simple_free_text_builders.py +180 -0
- rapidata/rapidata_client/simple_builders/simple_transcription_builders.py +194 -0
- rapidata/service/openapi_service.py +4 -2
- {rapidata-1.7.0.dist-info → rapidata-1.8.0.dist-info}/METADATA +2 -2
- {rapidata-1.7.0.dist-info → rapidata-1.8.0.dist-info}/RECORD +46 -33
- rapidata/rapidata_client/config.py +0 -9
- {rapidata-1.7.0.dist-info → rapidata-1.8.0.dist-info}/LICENSE +0 -0
- {rapidata-1.7.0.dist-info → rapidata-1.8.0.dist-info}/WHEEL +0 -0
rapidata/api_client_README.md
CHANGED
|
@@ -75,6 +75,9 @@ Class | Method | HTTP request | Description
|
|
|
75
75
|
*CampaignApi* | [**campaign_pause_post**](rapidata/api_client/docs/CampaignApi.md#campaign_pause_post) | **POST** /Campaign/Pause | Pauses a campaign.
|
|
76
76
|
*CampaignApi* | [**campaign_query_get**](rapidata/api_client/docs/CampaignApi.md#campaign_query_get) | **GET** /Campaign/Query | Queries orders based on a filter, page, and sort criteria.
|
|
77
77
|
*CampaignApi* | [**campaign_resume_post**](rapidata/api_client/docs/CampaignApi.md#campaign_resume_post) | **POST** /Campaign/Resume | Resumes a campaign.
|
|
78
|
+
*ClientApi* | [**client_client_id_delete**](rapidata/api_client/docs/ClientApi.md#client_client_id_delete) | **DELETE** /Client/{clientId} | Deletes a customers client.
|
|
79
|
+
*ClientApi* | [**client_post**](rapidata/api_client/docs/ClientApi.md#client_post) | **POST** /Client | Creates a new client for the current customer.
|
|
80
|
+
*ClientApi* | [**client_query_get**](rapidata/api_client/docs/ClientApi.md#client_query_get) | **GET** /Client/Query | Gets the clients for the current customer.
|
|
78
81
|
*CocoApi* | [**coco_submit_post**](rapidata/api_client/docs/CocoApi.md#coco_submit_post) | **POST** /Coco/Submit | Creates a new validation set based on a previously uploaded CoCo set.
|
|
79
82
|
*CocoApi* | [**coco_upload_post**](rapidata/api_client/docs/CocoApi.md#coco_upload_post) | **POST** /Coco/Upload | Uploads a CoCo set to the system.
|
|
80
83
|
*CompareWorkflowApi* | [**compare_workflow_get_result_overview_get**](rapidata/api_client/docs/CompareWorkflowApi.md#compare_workflow_get_result_overview_get) | **GET** /CompareWorkflow/GetResultOverview | Get the result overview for a compare workflow.
|
|
@@ -89,7 +92,8 @@ Class | Method | HTTP request | Description
|
|
|
89
92
|
*DatasetApi* | [**dataset_upload_datapoint_post**](rapidata/api_client/docs/DatasetApi.md#dataset_upload_datapoint_post) | **POST** /Dataset/UploadDatapoint | Creates a new multi asset datapoint.
|
|
90
93
|
*DatasetApi* | [**dataset_upload_files_from_s3_post**](rapidata/api_client/docs/DatasetApi.md#dataset_upload_files_from_s3_post) | **POST** /Dataset/UploadFilesFromS3 | Uploads files from an S3 bucket to a dataset.
|
|
91
94
|
*DatasetApi* | [**dataset_upload_images_to_dataset_post**](rapidata/api_client/docs/DatasetApi.md#dataset_upload_images_to_dataset_post) | **POST** /Dataset/UploadImagesToDataset | Uploads images to a dataset.
|
|
92
|
-
*IdentityApi* | [**
|
|
95
|
+
*IdentityApi* | [**identity_create_bridge_token_post**](rapidata/api_client/docs/IdentityApi.md#identity_create_bridge_token_post) | **POST** /Identity/CreateBridgeToken | Creates a pair of read and write keys for a client. The write key is used to store the authentication result. The read key is used to retrieve the authentication result.
|
|
96
|
+
*IdentityApi* | [**identity_read_bridge_token_get**](rapidata/api_client/docs/IdentityApi.md#identity_read_bridge_token_get) | **GET** /Identity/ReadBridgeToken | Tries to read the bridge token keys for a given read key. The read key is used to retrieve the authentication result written by the write key.
|
|
93
97
|
*IdentityApi* | [**identity_register_temporary_post**](rapidata/api_client/docs/IdentityApi.md#identity_register_temporary_post) | **POST** /Identity/RegisterTemporary | Registers and logs in a temporary customer.
|
|
94
98
|
*NewsletterApi* | [**newsletter_post**](rapidata/api_client/docs/NewsletterApi.md#newsletter_post) | **POST** /Newsletter | Signs a user up to the newsletter.
|
|
95
99
|
*NewsletterApi* | [**newsletter_unsubscribe_post**](rapidata/api_client/docs/NewsletterApi.md#newsletter_unsubscribe_post) | **POST** /Newsletter/Unsubscribe | Unsubscribes a user from the newsletter.
|
|
@@ -171,6 +175,8 @@ Class | Method | HTTP request | Description
|
|
|
171
175
|
- [ClassificationMetadataFilterConfig](rapidata/api_client/docs/ClassificationMetadataFilterConfig.md)
|
|
172
176
|
- [ClassificationMetadataModel](rapidata/api_client/docs/ClassificationMetadataModel.md)
|
|
173
177
|
- [ClassifyPayload](rapidata/api_client/docs/ClassifyPayload.md)
|
|
178
|
+
- [ClientsQueryResult](rapidata/api_client/docs/ClientsQueryResult.md)
|
|
179
|
+
- [ClientsQueryResultPagedResult](rapidata/api_client/docs/ClientsQueryResultPagedResult.md)
|
|
174
180
|
- [CloneDatasetModel](rapidata/api_client/docs/CloneDatasetModel.md)
|
|
175
181
|
- [CloneOrderModel](rapidata/api_client/docs/CloneOrderModel.md)
|
|
176
182
|
- [CloneOrderResult](rapidata/api_client/docs/CloneOrderResult.md)
|
|
@@ -192,6 +198,7 @@ Class | Method | HTTP request | Description
|
|
|
192
198
|
- [CountMetadata](rapidata/api_client/docs/CountMetadata.md)
|
|
193
199
|
- [CountMetadataModel](rapidata/api_client/docs/CountMetadataModel.md)
|
|
194
200
|
- [CountryUserFilterModel](rapidata/api_client/docs/CountryUserFilterModel.md)
|
|
201
|
+
- [CreateBridgeTokenResult](rapidata/api_client/docs/CreateBridgeTokenResult.md)
|
|
195
202
|
- [CreateClientModel](rapidata/api_client/docs/CreateClientModel.md)
|
|
196
203
|
- [CreateClientResult](rapidata/api_client/docs/CreateClientResult.md)
|
|
197
204
|
- [CreateComplexOrderModel](rapidata/api_client/docs/CreateComplexOrderModel.md)
|
|
@@ -316,6 +323,7 @@ Class | Method | HTTP request | Description
|
|
|
316
323
|
- [PolygonTruth](rapidata/api_client/docs/PolygonTruth.md)
|
|
317
324
|
- [PrivateTextMetadataInput](rapidata/api_client/docs/PrivateTextMetadataInput.md)
|
|
318
325
|
- [ProbabilisticAttachCategoryRefereeConfig](rapidata/api_client/docs/ProbabilisticAttachCategoryRefereeConfig.md)
|
|
326
|
+
- [ProblemDetails](rapidata/api_client/docs/ProblemDetails.md)
|
|
319
327
|
- [PromptMetadata](rapidata/api_client/docs/PromptMetadata.md)
|
|
320
328
|
- [PromptMetadataInput](rapidata/api_client/docs/PromptMetadataInput.md)
|
|
321
329
|
- [PromptMetadataModel](rapidata/api_client/docs/PromptMetadataModel.md)
|
|
@@ -323,7 +331,6 @@ Class | Method | HTTP request | Description
|
|
|
323
331
|
- [PublicTextMetadataInput](rapidata/api_client/docs/PublicTextMetadataInput.md)
|
|
324
332
|
- [QueryCampaignsModel](rapidata/api_client/docs/QueryCampaignsModel.md)
|
|
325
333
|
- [QueryModel](rapidata/api_client/docs/QueryModel.md)
|
|
326
|
-
- [QueryOrdersModel](rapidata/api_client/docs/QueryOrdersModel.md)
|
|
327
334
|
- [QueryValidationRapidsResult](rapidata/api_client/docs/QueryValidationRapidsResult.md)
|
|
328
335
|
- [QueryValidationRapidsResultAsset](rapidata/api_client/docs/QueryValidationRapidsResultAsset.md)
|
|
329
336
|
- [QueryValidationRapidsResultPagedResult](rapidata/api_client/docs/QueryValidationRapidsResultPagedResult.md)
|
|
@@ -335,6 +342,7 @@ Class | Method | HTTP request | Description
|
|
|
335
342
|
- [RapidResultModel](rapidata/api_client/docs/RapidResultModel.md)
|
|
336
343
|
- [RapidResultModelResult](rapidata/api_client/docs/RapidResultModelResult.md)
|
|
337
344
|
- [RapidSkippedModel](rapidata/api_client/docs/RapidSkippedModel.md)
|
|
345
|
+
- [ReadBridgeTokenKeysResult](rapidata/api_client/docs/ReadBridgeTokenKeysResult.md)
|
|
338
346
|
- [RegisterTemporaryCustomerModel](rapidata/api_client/docs/RegisterTemporaryCustomerModel.md)
|
|
339
347
|
- [RootFilter](rapidata/api_client/docs/RootFilter.md)
|
|
340
348
|
- [SendCompletionMailStepModel](rapidata/api_client/docs/SendCompletionMailStepModel.md)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This package provides classes for different types of assets, including MediaAsset, TextAsset, and MultiAsset.
|
|
4
4
|
"""
|
|
5
|
-
|
|
5
|
+
from .base_asset import BaseAsset
|
|
6
6
|
from .media_asset import MediaAsset
|
|
7
7
|
from .text_asset import TextAsset
|
|
8
8
|
from .multi_asset import MultiAsset
|
|
@@ -31,14 +31,36 @@ class MediaAsset(BaseAsset):
|
|
|
31
31
|
Raises:
|
|
32
32
|
FileNotFoundError: If the provided file path does not exist.
|
|
33
33
|
"""
|
|
34
|
+
if not isinstance(path, str):
|
|
35
|
+
raise ValueError("Media must be a string, either a local file path or an image URL")
|
|
36
|
+
|
|
34
37
|
if re.match(r'^https?://', path):
|
|
35
38
|
self.path = MediaAsset.get_image_bytes(path)
|
|
39
|
+
self.name = path.split('/')[-1]
|
|
40
|
+
if not self.name.endswith(('.jpg', '.jpeg', '.png', '.gif')):
|
|
41
|
+
self.name += '.jpg'
|
|
36
42
|
return
|
|
37
43
|
|
|
38
44
|
if not os.path.exists(path):
|
|
39
45
|
raise FileNotFoundError(f"File not found: {path}, please provide a valid local file path.")
|
|
40
46
|
|
|
41
47
|
self.path: str | bytes = path
|
|
48
|
+
self.name = path
|
|
49
|
+
|
|
50
|
+
def set_custom_name(self, name: str) -> 'MediaAsset':
|
|
51
|
+
"""
|
|
52
|
+
Set a custom name for the media asset, will only work with links.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
name (str): The custom name to be set.
|
|
56
|
+
"""
|
|
57
|
+
if isinstance(self.path, bytes):
|
|
58
|
+
if not name.endswith(('.jpg', '.jpeg', '.png', '.gif')):
|
|
59
|
+
name += '.jpg'
|
|
60
|
+
self.name = name
|
|
61
|
+
else:
|
|
62
|
+
raise ValueError("Custom name can only be set for links.")
|
|
63
|
+
return self
|
|
42
64
|
|
|
43
65
|
@staticmethod
|
|
44
66
|
def get_image_bytes(image_url: str) -> bytes:
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from rapidata.service.openapi_service import OpenAPIService
|
|
2
|
+
from rapidata.rapidata_client.dataset.rapid_builders import ClassifyRapidQuestionBuilder, CompareRapidCriteriaBuilder, TranscriptionRapidInstructionBuilder
|
|
3
|
+
|
|
4
|
+
class BaseRapidBuilder:
|
|
5
|
+
"""Base class for creating different types of rapids.
|
|
6
|
+
|
|
7
|
+
This class provides factory methods to create specific rapids
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def classify_rapid(self):
|
|
11
|
+
"""Creates a classification rapid.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
ClassifyRapidQuestionBuilder: A builder for creating the classification question.
|
|
15
|
+
"""
|
|
16
|
+
return ClassifyRapidQuestionBuilder()
|
|
17
|
+
|
|
18
|
+
def compare_rapid(self):
|
|
19
|
+
"""Creates a compare rapid.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
CompareRapidCriteriaBuilder: A builder for creating a comparison criteria.
|
|
23
|
+
"""
|
|
24
|
+
return CompareRapidCriteriaBuilder()
|
|
25
|
+
|
|
26
|
+
def transcription_rapid(self):
|
|
27
|
+
"""Creates a transcription rapid.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
TranscriptionRapidInstructionBuilder: A builder for creating the transcription instruction.
|
|
31
|
+
"""
|
|
32
|
+
return TranscriptionRapidInstructionBuilder()
|
|
33
|
+
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
from rapidata.rapidata_client.assets import MediaAsset, TextAsset
|
|
2
|
+
from rapidata.rapidata_client.metadata import PromptMetadata
|
|
3
|
+
from rapidata.rapidata_client.dataset.rapid_builders.rapids import ClassificationRapid
|
|
4
|
+
|
|
5
|
+
class ClassifyRapidBuilder:
|
|
6
|
+
"""Final builder class for classification rapid.
|
|
7
|
+
|
|
8
|
+
This class handles the final construction of a classification rapid with all required parameters.
|
|
9
|
+
"""
|
|
10
|
+
def __init__(self, question: str, options: list[str], truths: list[str], asset: MediaAsset | TextAsset):
|
|
11
|
+
self._question = question
|
|
12
|
+
self._options = options
|
|
13
|
+
self._truths = truths
|
|
14
|
+
self._asset = asset
|
|
15
|
+
self._metadata = []
|
|
16
|
+
|
|
17
|
+
def prompt(self, prompt: str):
|
|
18
|
+
"""Add a prompt to provide additional context for the classification task.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
prompt (str): Additional instructions or context
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
ClassifyRapidBuilder: The builder instance for method chaining
|
|
25
|
+
"""
|
|
26
|
+
self._metadata.append(PromptMetadata(prompt))
|
|
27
|
+
return self
|
|
28
|
+
|
|
29
|
+
def build(self):
|
|
30
|
+
"""Constructs and returns the final classification rapid.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
ClassificationRapid: The constructed classification rapid
|
|
34
|
+
"""
|
|
35
|
+
return ClassificationRapid(
|
|
36
|
+
question=self._question,
|
|
37
|
+
options=self._options,
|
|
38
|
+
truths=self._truths,
|
|
39
|
+
asset=self._asset,
|
|
40
|
+
metadata=self._metadata
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
class ClassifyRapidTruthBuilder:
|
|
44
|
+
"""Builder class for the truths of the classification rapid.
|
|
45
|
+
|
|
46
|
+
This adds the truths to the classification rapid.
|
|
47
|
+
"""
|
|
48
|
+
def __init__(self, question: str, options: list[str], asset: MediaAsset | TextAsset):
|
|
49
|
+
self._question = question
|
|
50
|
+
self._options = options
|
|
51
|
+
self._asset = asset
|
|
52
|
+
self._truths = None
|
|
53
|
+
|
|
54
|
+
def truths(self, truths: list[str]):
|
|
55
|
+
"""Set the truths for the classification rapid.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
truths (list[str]): The correct answers for the classification task"""
|
|
59
|
+
|
|
60
|
+
if not isinstance(truths, list) or not all(isinstance(truth, str) for truth in truths):
|
|
61
|
+
raise ValueError("Truths must be a list of strings")
|
|
62
|
+
|
|
63
|
+
if not all(truth in self._options for truth in truths):
|
|
64
|
+
raise ValueError("Truths must be one of the selectable options")
|
|
65
|
+
|
|
66
|
+
self._truths = truths
|
|
67
|
+
return self._build()
|
|
68
|
+
|
|
69
|
+
def _build(self):
|
|
70
|
+
if self._truths is None:
|
|
71
|
+
raise ValueError("Truths are required")
|
|
72
|
+
return ClassifyRapidBuilder(
|
|
73
|
+
question=self._question,
|
|
74
|
+
options=self._options,
|
|
75
|
+
asset=self._asset,
|
|
76
|
+
truths=self._truths,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
class ClassifyRapidMediaBuilder:
|
|
80
|
+
"""Builder class for the media asset of the classification rapid.
|
|
81
|
+
|
|
82
|
+
This class adds the media asset to the classification rapid.
|
|
83
|
+
"""
|
|
84
|
+
def __init__(self, question: str, options: list[str]):
|
|
85
|
+
self._question = question
|
|
86
|
+
self._options = options
|
|
87
|
+
self._asset: MediaAsset | TextAsset | None = None
|
|
88
|
+
|
|
89
|
+
def media(self, media: str):
|
|
90
|
+
"""Set the media asset for the classification rapid.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
media (str): A local file path or an image URL. The image will be displayed with the classification task"""
|
|
94
|
+
self._asset = MediaAsset(media)
|
|
95
|
+
|
|
96
|
+
return self._build()
|
|
97
|
+
|
|
98
|
+
def text(self, text: str):
|
|
99
|
+
"""Set the text asset for the classification rapid.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
text (str): The text to be displayed with the classification task"""
|
|
103
|
+
self._asset = TextAsset(text)
|
|
104
|
+
|
|
105
|
+
return self._build()
|
|
106
|
+
|
|
107
|
+
def _build(self):
|
|
108
|
+
if self._asset is None:
|
|
109
|
+
raise ValueError("Assets are required")
|
|
110
|
+
|
|
111
|
+
return ClassifyRapidTruthBuilder(
|
|
112
|
+
question=self._question,
|
|
113
|
+
options=self._options,
|
|
114
|
+
asset=self._asset,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
class ClassifyRapidOptionsBuilder:
|
|
118
|
+
def __init__(self, question: str):
|
|
119
|
+
self._question = question
|
|
120
|
+
self._options = None
|
|
121
|
+
|
|
122
|
+
def options(self, options: list[str]):
|
|
123
|
+
"""Set the options for the classification rapid.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
options (list[str]): The selectable options for the classification task"""
|
|
127
|
+
|
|
128
|
+
if not isinstance(options, list) or not all(isinstance(option, str) for option in options):
|
|
129
|
+
raise ValueError("Options must be a list of strings")
|
|
130
|
+
|
|
131
|
+
self._options = options
|
|
132
|
+
return self._build()
|
|
133
|
+
|
|
134
|
+
def _build(self):
|
|
135
|
+
if self._options is None:
|
|
136
|
+
raise ValueError("Options are required")
|
|
137
|
+
|
|
138
|
+
return ClassifyRapidMediaBuilder(
|
|
139
|
+
question=self._question,
|
|
140
|
+
options=self._options,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class ClassifyRapidQuestionBuilder:
|
|
145
|
+
def __init__(self):
|
|
146
|
+
self._question = None
|
|
147
|
+
|
|
148
|
+
def question(self, question: str):
|
|
149
|
+
"""Set the question for the classification rapid.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
question (str): The question to be answered by the classification task"""
|
|
153
|
+
|
|
154
|
+
if not isinstance(question, str):
|
|
155
|
+
raise ValueError("Question must be a string")
|
|
156
|
+
|
|
157
|
+
self._question = question
|
|
158
|
+
return self._build()
|
|
159
|
+
|
|
160
|
+
def _build(self):
|
|
161
|
+
if self._question is None:
|
|
162
|
+
raise ValueError("Question is required")
|
|
163
|
+
|
|
164
|
+
return ClassifyRapidOptionsBuilder(
|
|
165
|
+
question=self._question,
|
|
166
|
+
)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
from rapidata.rapidata_client.assets import MultiAsset, TextAsset, MediaAsset
|
|
2
|
+
from rapidata.rapidata_client.metadata import PromptMetadata
|
|
3
|
+
from rapidata.rapidata_client.dataset.rapid_builders.rapids import CompareRapid
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
class CompareRapidBuilder:
|
|
7
|
+
"""Final builder class for comparison rapid.
|
|
8
|
+
|
|
9
|
+
This class handles the final construction of a comparison rapid with all required parameters.
|
|
10
|
+
"""
|
|
11
|
+
def __init__(self, criteria: str, truth: str, asset: MultiAsset):
|
|
12
|
+
"""Initialize the comparison rapid builder.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
criteria (str): The criteria for comparison
|
|
16
|
+
truth (str): The correct answer
|
|
17
|
+
asset (MultiAsset): Collection of assets to be compared
|
|
18
|
+
"""
|
|
19
|
+
self._criteria = criteria
|
|
20
|
+
self._truth = truth
|
|
21
|
+
self._asset = asset
|
|
22
|
+
self._metadata = []
|
|
23
|
+
|
|
24
|
+
def prompt(self, prompt: str):
|
|
25
|
+
"""Add a prompt to provide additional context for the comparison.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
prompt (str): Additional instructions or context
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
CompareRapidBuilder: The builder instance for method chaining
|
|
32
|
+
"""
|
|
33
|
+
self._metadata.append(PromptMetadata(prompt))
|
|
34
|
+
return self
|
|
35
|
+
|
|
36
|
+
def build(self):
|
|
37
|
+
"""Constructs and returns the final comparison rapid.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
CompareRapid: The constructed comparison rapid
|
|
41
|
+
"""
|
|
42
|
+
return CompareRapid(
|
|
43
|
+
criteria=self._criteria,
|
|
44
|
+
asset=self._asset,
|
|
45
|
+
truth=self._truth,
|
|
46
|
+
metadata=self._metadata
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
class CompareRapidTruthBuilder:
|
|
50
|
+
"""Builder class for the truth of the comparison rapid.
|
|
51
|
+
|
|
52
|
+
This adds the truth to the comparison rapid.
|
|
53
|
+
"""
|
|
54
|
+
def __init__(self, criteria: str, asset: MultiAsset):
|
|
55
|
+
self._criteria = criteria
|
|
56
|
+
self._asset = asset
|
|
57
|
+
self._truth = None
|
|
58
|
+
|
|
59
|
+
def truth(self, truth: str):
|
|
60
|
+
"""Set the truth for the comparison rapid.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
truth (str): The correct answer for the comparison task. Is the string of the correct media/text asset"""
|
|
64
|
+
|
|
65
|
+
if not isinstance(truth, str):
|
|
66
|
+
raise ValueError("Truth must be a string.")
|
|
67
|
+
|
|
68
|
+
self._truth = MediaAsset(truth).name
|
|
69
|
+
|
|
70
|
+
return self._build()
|
|
71
|
+
|
|
72
|
+
def _build(self):
|
|
73
|
+
if self._truth is None:
|
|
74
|
+
raise ValueError("Truth is required")
|
|
75
|
+
|
|
76
|
+
return CompareRapidBuilder(
|
|
77
|
+
criteria=self._criteria,
|
|
78
|
+
asset=self._asset,
|
|
79
|
+
truth=self._truth,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
class CompareRapidAssetBuilder:
|
|
83
|
+
"""Builder class for the asset of the comparison rapid.
|
|
84
|
+
|
|
85
|
+
This adds the asset to the comparison rapid.
|
|
86
|
+
"""
|
|
87
|
+
def __init__(self, criteria: str):
|
|
88
|
+
self._criteria = criteria
|
|
89
|
+
self._asset: MultiAsset | None = None
|
|
90
|
+
|
|
91
|
+
def media(self, medias: list[str]):
|
|
92
|
+
"""Set the media assets for the comparison rapid.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
medias (list[str]): The local file paths or links of the media assets to be compared"""
|
|
96
|
+
|
|
97
|
+
media_assets = [MediaAsset(media) for media in medias]
|
|
98
|
+
self._asset = MultiAsset(media_assets)
|
|
99
|
+
return self._build()
|
|
100
|
+
|
|
101
|
+
def text(self, texts: list[str]):
|
|
102
|
+
"""Set the text assets for the comparison rapid.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
texts (list[str]): The texts to be compared"""
|
|
106
|
+
|
|
107
|
+
text_assets = [TextAsset(text) for text in texts]
|
|
108
|
+
self._asset = MultiAsset(text_assets)
|
|
109
|
+
return self._build()
|
|
110
|
+
|
|
111
|
+
def _build(self):
|
|
112
|
+
if self._asset is None:
|
|
113
|
+
raise ValueError("Asset is required")
|
|
114
|
+
|
|
115
|
+
return CompareRapidTruthBuilder(
|
|
116
|
+
criteria=self._criteria,
|
|
117
|
+
asset=self._asset,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
class CompareRapidCriteriaBuilder:
|
|
121
|
+
"""Builder class for the criteria of the comparison rapid.
|
|
122
|
+
|
|
123
|
+
This adds the criteria to the comparison rapid."""
|
|
124
|
+
def __init__(self):
|
|
125
|
+
self._criteria = None
|
|
126
|
+
|
|
127
|
+
def criteria(self, criteria: str):
|
|
128
|
+
"""Set the criteria for the comparison rapid.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
criteria (str): The criteria for comparison"""
|
|
132
|
+
|
|
133
|
+
if not isinstance(criteria, str):
|
|
134
|
+
raise ValueError("Criteria must be a string")
|
|
135
|
+
|
|
136
|
+
self._criteria = criteria
|
|
137
|
+
return self._build()
|
|
138
|
+
|
|
139
|
+
def _build(self):
|
|
140
|
+
if self._criteria is None:
|
|
141
|
+
raise ValueError("Criteria is required")
|
|
142
|
+
|
|
143
|
+
return CompareRapidAssetBuilder(
|
|
144
|
+
criteria=self._criteria,
|
|
145
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from rapidata.rapidata_client.assets import MediaAsset, TextAsset, MultiAsset
|
|
2
|
+
from rapidata.rapidata_client.metadata import Metadata
|
|
3
|
+
|
|
4
|
+
class Rapid:
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
class ClassificationRapid(Rapid):
|
|
8
|
+
"""A classification rapid. This represents the question, options, truths, asset and metadata that will be given to the user."""
|
|
9
|
+
def __init__(self, question: str, options: list[str], truths: list[str], asset: MediaAsset | TextAsset, metadata: list[Metadata]):
|
|
10
|
+
self.question = question
|
|
11
|
+
self.options = options
|
|
12
|
+
self.truths = truths
|
|
13
|
+
self.asset = asset
|
|
14
|
+
self.metadata = metadata
|
|
15
|
+
|
|
16
|
+
class CompareRapid(Rapid):
|
|
17
|
+
"""A comparison rapid. This represents the criteria, asset, truth and metadata that will be given to the user."""
|
|
18
|
+
def __init__(self, criteria: str, truth: str, asset: MultiAsset, metadata: list[Metadata]):
|
|
19
|
+
self.criteria = criteria
|
|
20
|
+
self.asset = asset
|
|
21
|
+
self.truth = truth
|
|
22
|
+
self.metadata = metadata
|
|
23
|
+
|
|
24
|
+
class TranscriptionRapid(Rapid):
|
|
25
|
+
"""A transcription rapid. This represents the instruction, truths, asset, transcription and strict grading that will be given to the user."""
|
|
26
|
+
def __init__(self, instruction: str, truths: list[int], asset: MediaAsset, transcription: str, strict_grading: bool):
|
|
27
|
+
self.instruction = instruction
|
|
28
|
+
self.truths = truths
|
|
29
|
+
self.asset = asset
|
|
30
|
+
self.transcription = transcription
|
|
31
|
+
self.strict_grading = strict_grading
|
|
32
|
+
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
from rapidata.rapidata_client.assets import MediaAsset
|
|
2
|
+
from rapidata.rapidata_client.dataset.rapid_builders.rapids import TranscriptionRapid
|
|
3
|
+
|
|
4
|
+
class TranscriptionRapidBuilder:
|
|
5
|
+
"""Final builder class for transcription rapid.
|
|
6
|
+
|
|
7
|
+
This class handles the final construction of a transcription rapid with all required parameters.
|
|
8
|
+
"""
|
|
9
|
+
def __init__(self, instruction: str, truths: list[int], asset: MediaAsset, transcription_text: str):
|
|
10
|
+
self._instruction = instruction
|
|
11
|
+
self._truths = truths
|
|
12
|
+
self._asset = asset
|
|
13
|
+
self._transcription_text = transcription_text
|
|
14
|
+
self._strict_grading = True
|
|
15
|
+
|
|
16
|
+
def strict_grading(self, strict_grading: bool = True):
|
|
17
|
+
"""Set whether to use strict grading for the transcription.
|
|
18
|
+
Strict grading true: In order to be correct, you must select all of the right words
|
|
19
|
+
Strict grading false: In order to be correct, you must select at least one right word
|
|
20
|
+
In both cases it will be incorrect if you select any wrong words
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
strict_grading (bool): Whether to use strict grading. Defaults to True.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
TranscriptionRapidBuilder: The builder instance for method chaining
|
|
27
|
+
"""
|
|
28
|
+
self._strict_grading = strict_grading
|
|
29
|
+
return self
|
|
30
|
+
|
|
31
|
+
def build(self):
|
|
32
|
+
"""Constructs and returns the final transcription rapid.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
TranscriptionRapid: The constructed transcription rapid
|
|
36
|
+
"""
|
|
37
|
+
return TranscriptionRapid(
|
|
38
|
+
instruction=self._instruction,
|
|
39
|
+
truths=self._truths,
|
|
40
|
+
asset=self._asset,
|
|
41
|
+
transcription=self._transcription_text,
|
|
42
|
+
strict_grading=self._strict_grading
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
class TranscriptionRapidTruthsBuilder:
|
|
46
|
+
"""Builder class for the truths of the transcription rapid.
|
|
47
|
+
|
|
48
|
+
This adds the truths to the transcription rapid.
|
|
49
|
+
"""
|
|
50
|
+
def __init__(self, instruction: str, media: MediaAsset, transcription_text: str):
|
|
51
|
+
self._instruction = instruction
|
|
52
|
+
self._media = media
|
|
53
|
+
self._transcription_text = transcription_text
|
|
54
|
+
self._truths = None
|
|
55
|
+
|
|
56
|
+
def truths(self, truths: list[int]):
|
|
57
|
+
"""Set the truths for the transcription rapid.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
truths (list[int]): The correct answers for the transcription task. \
|
|
61
|
+
Each integer represents the index of the correct word in the transcription text."""
|
|
62
|
+
|
|
63
|
+
if not isinstance(truths, list) or not all(isinstance(truth, int) for truth in truths):
|
|
64
|
+
raise ValueError("Truths must be a list of integers")
|
|
65
|
+
|
|
66
|
+
self._truths = truths
|
|
67
|
+
return self._build()
|
|
68
|
+
|
|
69
|
+
def _build(self):
|
|
70
|
+
if self._truths is None:
|
|
71
|
+
raise ValueError("Truths are required")
|
|
72
|
+
|
|
73
|
+
return TranscriptionRapidBuilder(
|
|
74
|
+
instruction=self._instruction,
|
|
75
|
+
truths=self._truths,
|
|
76
|
+
asset=self._media,
|
|
77
|
+
transcription_text=self._transcription_text
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
class TranscriptionRapidAssetBuilder:
|
|
81
|
+
"""Builder class for the asset of the transcription rapid.
|
|
82
|
+
|
|
83
|
+
This adds the asset to the transcription rapid.
|
|
84
|
+
"""
|
|
85
|
+
def __init__(self, instruction: str):
|
|
86
|
+
self._instruction = instruction
|
|
87
|
+
|
|
88
|
+
def media(self, media: str, transcription_text: str):
|
|
89
|
+
"""Set the media asset for the transcription rapid.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
media (str): The local file path of the audio or video file to be transcribed
|
|
93
|
+
transcription_text (str): The text to be transcribed from the media asset""" # is video file okay?
|
|
94
|
+
|
|
95
|
+
self._asset = MediaAsset(media)
|
|
96
|
+
self._transcription_text = transcription_text
|
|
97
|
+
|
|
98
|
+
return self._build()
|
|
99
|
+
|
|
100
|
+
def _build(self):
|
|
101
|
+
if not self._asset:
|
|
102
|
+
raise ValueError("Media is required")
|
|
103
|
+
|
|
104
|
+
return TranscriptionRapidTruthsBuilder(
|
|
105
|
+
instruction=self._instruction,
|
|
106
|
+
media=self._asset,
|
|
107
|
+
transcription_text=self._transcription_text
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
class TranscriptionRapidInstructionBuilder:
|
|
111
|
+
def __init__(self):
|
|
112
|
+
self._instruction = None
|
|
113
|
+
|
|
114
|
+
def instruction(self, instruction: str):
|
|
115
|
+
"""Set the instruction for the transcription rapid.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
instruction (str): The instruction for the transcription task"""
|
|
119
|
+
|
|
120
|
+
if not isinstance(instruction, str):
|
|
121
|
+
raise ValueError("Instruction must be a string")
|
|
122
|
+
|
|
123
|
+
self._instruction = instruction
|
|
124
|
+
return self._build()
|
|
125
|
+
|
|
126
|
+
def _build(self):
|
|
127
|
+
if self._instruction is None:
|
|
128
|
+
raise ValueError("Instruction is required")
|
|
129
|
+
|
|
130
|
+
return TranscriptionRapidAssetBuilder(
|
|
131
|
+
instruction=self._instruction,
|
|
132
|
+
)
|