label-studio-sdk 1.0.5__py3-none-any.whl → 1.0.7__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.
- label_studio_sdk/__init__.py +70 -0
- label_studio_sdk/_extensions/eval/categorical.py +83 -0
- label_studio_sdk/_extensions/label_studio_tools/core/utils/io.py +35 -17
- label_studio_sdk/annotations/__init__.py +3 -0
- label_studio_sdk/annotations/client.py +109 -0
- label_studio_sdk/annotations/types/__init__.py +5 -0
- label_studio_sdk/annotations/types/annotations_create_bulk_response_item.py +29 -0
- label_studio_sdk/base_client.py +9 -0
- label_studio_sdk/comments/__init__.py +2 -0
- label_studio_sdk/comments/client.py +512 -0
- label_studio_sdk/converter/converter.py +2 -0
- label_studio_sdk/converter/imports/coco.py +14 -13
- label_studio_sdk/converter/utils.py +72 -3
- label_studio_sdk/core/client_wrapper.py +1 -1
- label_studio_sdk/files/client.py +26 -16
- label_studio_sdk/label_interface/interface.py +38 -5
- label_studio_sdk/model_providers/__init__.py +2 -0
- label_studio_sdk/model_providers/client.py +190 -0
- label_studio_sdk/projects/client.py +32 -16
- label_studio_sdk/projects/exports/client.py +133 -40
- label_studio_sdk/prompts/__init__.py +21 -0
- label_studio_sdk/prompts/client.py +862 -0
- label_studio_sdk/prompts/indicators/__init__.py +2 -0
- label_studio_sdk/prompts/indicators/client.py +194 -0
- label_studio_sdk/prompts/runs/__init__.py +5 -0
- label_studio_sdk/prompts/runs/client.py +354 -0
- label_studio_sdk/prompts/runs/types/__init__.py +5 -0
- label_studio_sdk/prompts/runs/types/runs_list_request_project_subset.py +5 -0
- label_studio_sdk/prompts/types/__init__.py +15 -0
- label_studio_sdk/prompts/types/prompts_batch_failed_predictions_request_failed_predictions_item.py +42 -0
- label_studio_sdk/prompts/types/prompts_batch_failed_predictions_response.py +29 -0
- label_studio_sdk/prompts/types/prompts_batch_predictions_request_results_item.py +62 -0
- label_studio_sdk/prompts/types/prompts_batch_predictions_response.py +29 -0
- label_studio_sdk/prompts/versions/__init__.py +2 -0
- label_studio_sdk/prompts/versions/client.py +921 -0
- label_studio_sdk/types/__init__.py +52 -0
- label_studio_sdk/types/comment.py +39 -0
- label_studio_sdk/types/comment_created_by.py +5 -0
- label_studio_sdk/types/inference_run.py +43 -0
- label_studio_sdk/types/inference_run_created_by.py +5 -0
- label_studio_sdk/types/inference_run_organization.py +5 -0
- label_studio_sdk/types/inference_run_project_subset.py +5 -0
- label_studio_sdk/types/inference_run_status.py +7 -0
- label_studio_sdk/types/key_indicator_value.py +30 -0
- label_studio_sdk/types/key_indicators.py +7 -0
- label_studio_sdk/types/key_indicators_item.py +51 -0
- label_studio_sdk/types/key_indicators_item_additional_kpis_item.py +37 -0
- label_studio_sdk/types/key_indicators_item_extra_kpis_item.py +37 -0
- label_studio_sdk/types/model_provider_connection.py +41 -0
- label_studio_sdk/types/model_provider_connection_created_by.py +5 -0
- label_studio_sdk/types/model_provider_connection_organization.py +5 -0
- label_studio_sdk/types/model_provider_connection_provider.py +5 -0
- label_studio_sdk/types/model_provider_connection_scope.py +5 -0
- label_studio_sdk/types/prompt.py +79 -0
- label_studio_sdk/types/prompt_created_by.py +5 -0
- label_studio_sdk/types/prompt_organization.py +5 -0
- label_studio_sdk/types/prompt_version.py +41 -0
- label_studio_sdk/types/prompt_version_created_by.py +5 -0
- label_studio_sdk/types/prompt_version_organization.py +5 -0
- label_studio_sdk/types/prompt_version_provider.py +5 -0
- label_studio_sdk/types/refined_prompt_response.py +64 -0
- label_studio_sdk/types/refined_prompt_response_refinement_status.py +7 -0
- label_studio_sdk/webhooks/client.py +245 -36
- label_studio_sdk/workspaces/client.py +20 -20
- label_studio_sdk-1.0.7.dist-info/LICENSE +201 -0
- {label_studio_sdk-1.0.5.dist-info → label_studio_sdk-1.0.7.dist-info}/METADATA +17 -3
- {label_studio_sdk-1.0.5.dist-info → label_studio_sdk-1.0.7.dist-info}/RECORD +68 -19
- {label_studio_sdk-1.0.5.dist-info → label_studio_sdk-1.0.7.dist-info}/WHEEL +1 -1
label_studio_sdk/__init__.py
CHANGED
|
@@ -14,6 +14,8 @@ from .types import (
|
|
|
14
14
|
BaseTaskFileUpload,
|
|
15
15
|
BaseTaskUpdatedBy,
|
|
16
16
|
BaseUser,
|
|
17
|
+
Comment,
|
|
18
|
+
CommentCreatedBy,
|
|
17
19
|
ConvertedFormat,
|
|
18
20
|
ConvertedFormatStatus,
|
|
19
21
|
DataManagerTaskSerializer,
|
|
@@ -32,6 +34,16 @@ from .types import (
|
|
|
32
34
|
GcsExportStorageStatus,
|
|
33
35
|
GcsImportStorage,
|
|
34
36
|
GcsImportStorageStatus,
|
|
37
|
+
InferenceRun,
|
|
38
|
+
InferenceRunCreatedBy,
|
|
39
|
+
InferenceRunOrganization,
|
|
40
|
+
InferenceRunProjectSubset,
|
|
41
|
+
InferenceRunStatus,
|
|
42
|
+
KeyIndicatorValue,
|
|
43
|
+
KeyIndicators,
|
|
44
|
+
KeyIndicatorsItem,
|
|
45
|
+
KeyIndicatorsItemAdditionalKpisItem,
|
|
46
|
+
KeyIndicatorsItemExtraKpisItem,
|
|
35
47
|
LocalFilesExportStorage,
|
|
36
48
|
LocalFilesExportStorageStatus,
|
|
37
49
|
LocalFilesImportStorage,
|
|
@@ -39,6 +51,11 @@ from .types import (
|
|
|
39
51
|
MlBackend,
|
|
40
52
|
MlBackendAuthMethod,
|
|
41
53
|
MlBackendState,
|
|
54
|
+
ModelProviderConnection,
|
|
55
|
+
ModelProviderConnectionCreatedBy,
|
|
56
|
+
ModelProviderConnectionOrganization,
|
|
57
|
+
ModelProviderConnectionProvider,
|
|
58
|
+
ModelProviderConnectionScope,
|
|
42
59
|
Prediction,
|
|
43
60
|
Project,
|
|
44
61
|
ProjectImport,
|
|
@@ -46,10 +63,19 @@ from .types import (
|
|
|
46
63
|
ProjectLabelConfig,
|
|
47
64
|
ProjectSampling,
|
|
48
65
|
ProjectSkipQueue,
|
|
66
|
+
Prompt,
|
|
67
|
+
PromptCreatedBy,
|
|
68
|
+
PromptOrganization,
|
|
69
|
+
PromptVersion,
|
|
70
|
+
PromptVersionCreatedBy,
|
|
71
|
+
PromptVersionOrganization,
|
|
72
|
+
PromptVersionProvider,
|
|
49
73
|
RedisExportStorage,
|
|
50
74
|
RedisExportStorageStatus,
|
|
51
75
|
RedisImportStorage,
|
|
52
76
|
RedisImportStorageStatus,
|
|
77
|
+
RefinedPromptResponse,
|
|
78
|
+
RefinedPromptResponseRefinementStatus,
|
|
53
79
|
S3ExportStorage,
|
|
54
80
|
S3ExportStorageStatus,
|
|
55
81
|
S3ImportStorage,
|
|
@@ -74,12 +100,15 @@ from .errors import BadRequestError, InternalServerError
|
|
|
74
100
|
from . import (
|
|
75
101
|
actions,
|
|
76
102
|
annotations,
|
|
103
|
+
comments,
|
|
77
104
|
export_storage,
|
|
78
105
|
files,
|
|
79
106
|
import_storage,
|
|
80
107
|
ml,
|
|
108
|
+
model_providers,
|
|
81
109
|
predictions,
|
|
82
110
|
projects,
|
|
111
|
+
prompts,
|
|
83
112
|
tasks,
|
|
84
113
|
users,
|
|
85
114
|
views,
|
|
@@ -100,6 +129,7 @@ from .actions import (
|
|
|
100
129
|
ActionsCreateRequestSelectedItemsExcluded,
|
|
101
130
|
ActionsCreateRequestSelectedItemsIncluded,
|
|
102
131
|
)
|
|
132
|
+
from .annotations import AnnotationsCreateBulkResponseItem
|
|
103
133
|
from .environment import LabelStudioEnvironment
|
|
104
134
|
from .export_storage import ExportStorageListTypesResponseItem
|
|
105
135
|
from .import_storage import ImportStorageListTypesResponseItem
|
|
@@ -112,6 +142,12 @@ from .ml import (
|
|
|
112
142
|
MlUpdateResponseAuthMethod,
|
|
113
143
|
)
|
|
114
144
|
from .projects import ProjectsCreateResponse, ProjectsImportTasksResponse, ProjectsListResponse, ProjectsUpdateResponse
|
|
145
|
+
from .prompts import (
|
|
146
|
+
PromptsBatchFailedPredictionsRequestFailedPredictionsItem,
|
|
147
|
+
PromptsBatchFailedPredictionsResponse,
|
|
148
|
+
PromptsBatchPredictionsRequestResultsItem,
|
|
149
|
+
PromptsBatchPredictionsResponse,
|
|
150
|
+
)
|
|
115
151
|
from .tasks import TasksListRequestFields, TasksListResponse
|
|
116
152
|
from .users import UsersGetTokenResponse, UsersResetTokenResponse
|
|
117
153
|
from .version import __version__
|
|
@@ -150,6 +186,7 @@ __all__ = [
|
|
|
150
186
|
"Annotation",
|
|
151
187
|
"AnnotationFilterOptions",
|
|
152
188
|
"AnnotationLastAction",
|
|
189
|
+
"AnnotationsCreateBulkResponseItem",
|
|
153
190
|
"AnnotationsDmField",
|
|
154
191
|
"AnnotationsDmFieldLastAction",
|
|
155
192
|
"AzureBlobExportStorage",
|
|
@@ -162,6 +199,8 @@ __all__ = [
|
|
|
162
199
|
"BaseTaskUpdatedBy",
|
|
163
200
|
"BaseUser",
|
|
164
201
|
"Client",
|
|
202
|
+
"Comment",
|
|
203
|
+
"CommentCreatedBy",
|
|
165
204
|
"ConvertedFormat",
|
|
166
205
|
"ConvertedFormatStatus",
|
|
167
206
|
"DataManagerTaskSerializer",
|
|
@@ -182,7 +221,17 @@ __all__ = [
|
|
|
182
221
|
"GcsImportStorage",
|
|
183
222
|
"GcsImportStorageStatus",
|
|
184
223
|
"ImportStorageListTypesResponseItem",
|
|
224
|
+
"InferenceRun",
|
|
225
|
+
"InferenceRunCreatedBy",
|
|
226
|
+
"InferenceRunOrganization",
|
|
227
|
+
"InferenceRunProjectSubset",
|
|
228
|
+
"InferenceRunStatus",
|
|
185
229
|
"InternalServerError",
|
|
230
|
+
"KeyIndicatorValue",
|
|
231
|
+
"KeyIndicators",
|
|
232
|
+
"KeyIndicatorsItem",
|
|
233
|
+
"KeyIndicatorsItemAdditionalKpisItem",
|
|
234
|
+
"KeyIndicatorsItemExtraKpisItem",
|
|
186
235
|
"LabelStudioEnvironment",
|
|
187
236
|
"LocalFilesExportStorage",
|
|
188
237
|
"LocalFilesExportStorageStatus",
|
|
@@ -197,6 +246,11 @@ __all__ = [
|
|
|
197
246
|
"MlUpdateRequestAuthMethod",
|
|
198
247
|
"MlUpdateResponse",
|
|
199
248
|
"MlUpdateResponseAuthMethod",
|
|
249
|
+
"ModelProviderConnection",
|
|
250
|
+
"ModelProviderConnectionCreatedBy",
|
|
251
|
+
"ModelProviderConnectionOrganization",
|
|
252
|
+
"ModelProviderConnectionProvider",
|
|
253
|
+
"ModelProviderConnectionScope",
|
|
200
254
|
"Prediction",
|
|
201
255
|
"Project",
|
|
202
256
|
"ProjectImport",
|
|
@@ -208,10 +262,23 @@ __all__ = [
|
|
|
208
262
|
"ProjectsImportTasksResponse",
|
|
209
263
|
"ProjectsListResponse",
|
|
210
264
|
"ProjectsUpdateResponse",
|
|
265
|
+
"Prompt",
|
|
266
|
+
"PromptCreatedBy",
|
|
267
|
+
"PromptOrganization",
|
|
268
|
+
"PromptVersion",
|
|
269
|
+
"PromptVersionCreatedBy",
|
|
270
|
+
"PromptVersionOrganization",
|
|
271
|
+
"PromptVersionProvider",
|
|
272
|
+
"PromptsBatchFailedPredictionsRequestFailedPredictionsItem",
|
|
273
|
+
"PromptsBatchFailedPredictionsResponse",
|
|
274
|
+
"PromptsBatchPredictionsRequestResultsItem",
|
|
275
|
+
"PromptsBatchPredictionsResponse",
|
|
211
276
|
"RedisExportStorage",
|
|
212
277
|
"RedisExportStorageStatus",
|
|
213
278
|
"RedisImportStorage",
|
|
214
279
|
"RedisImportStorageStatus",
|
|
280
|
+
"RefinedPromptResponse",
|
|
281
|
+
"RefinedPromptResponseRefinementStatus",
|
|
215
282
|
"S3ExportStorage",
|
|
216
283
|
"S3ExportStorageStatus",
|
|
217
284
|
"S3ImportStorage",
|
|
@@ -255,12 +322,15 @@ __all__ = [
|
|
|
255
322
|
"__version__",
|
|
256
323
|
"actions",
|
|
257
324
|
"annotations",
|
|
325
|
+
"comments",
|
|
258
326
|
"export_storage",
|
|
259
327
|
"files",
|
|
260
328
|
"import_storage",
|
|
261
329
|
"ml",
|
|
330
|
+
"model_providers",
|
|
262
331
|
"predictions",
|
|
263
332
|
"projects",
|
|
333
|
+
"prompts",
|
|
264
334
|
"tasks",
|
|
265
335
|
"users",
|
|
266
336
|
"views",
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import List, Dict, Iterable
|
|
3
|
+
|
|
4
|
+
logger = logging.getLogger(__name__)
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
# TODO: after python 3.8 support is dropped (Oct'24), remove try-except block
|
|
8
|
+
from sklearn.metrics import precision_recall_fscore_support
|
|
9
|
+
except ImportError:
|
|
10
|
+
logger.warning('scikit-learn is not installed. Please install scikit-learn to use this module.')
|
|
11
|
+
precision_recall_fscore_support = None
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _get_single_choice(annotation: Dict):
|
|
15
|
+
"""
|
|
16
|
+
Get the single choice from the annotation.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
annotation: Annotation dict
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
Single choice
|
|
23
|
+
"""
|
|
24
|
+
maybe_choice = next((r['value']['choices'][0] for r in annotation['result'] if r['type'] == 'choices'), None)
|
|
25
|
+
if maybe_choice:
|
|
26
|
+
return maybe_choice
|
|
27
|
+
raise NotImplementedError('Only single choice is supported')
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_precision_recall_f1_per_choice(annotations: Iterable[Dict], predictions: Iterable[Dict]) -> Dict:
|
|
31
|
+
"""
|
|
32
|
+
Given the iterator over annotations and predictions, calculate precision, recall, and F1 per choice.
|
|
33
|
+
Each annotation and prediction follows the format of the Label Studio output.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
annotations: Iterable of annotation dicts
|
|
37
|
+
predictions: Iterable of prediction dicts
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
Dict of the following format:
|
|
41
|
+
{
|
|
42
|
+
'precision': {
|
|
43
|
+
'choice1': 0.5,
|
|
44
|
+
'choice2': 0.7,
|
|
45
|
+
...
|
|
46
|
+
},
|
|
47
|
+
'recall': {
|
|
48
|
+
'choice1': 0.5,
|
|
49
|
+
'choice2': 0.7,
|
|
50
|
+
...
|
|
51
|
+
},
|
|
52
|
+
'f1': {
|
|
53
|
+
'choice1': 0.5,
|
|
54
|
+
'choice2': 0.7,
|
|
55
|
+
...
|
|
56
|
+
},
|
|
57
|
+
'support': {
|
|
58
|
+
'choice1': 10,
|
|
59
|
+
'choice2': 20,
|
|
60
|
+
...
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
if precision_recall_fscore_support is None:
|
|
66
|
+
raise ImportError('scikit-learn is not installed. Please install scikit-learn to use this module.')
|
|
67
|
+
|
|
68
|
+
annotation_choices = [_get_single_choice(annotation) for annotation in annotations]
|
|
69
|
+
prediction_choices = [_get_single_choice(prediction) for prediction in predictions]
|
|
70
|
+
# get unique choices names
|
|
71
|
+
unique_choices = sorted(set(annotation_choices + prediction_choices))
|
|
72
|
+
|
|
73
|
+
metrics_per_choice = precision_recall_fscore_support(
|
|
74
|
+
annotation_choices, prediction_choices,
|
|
75
|
+
average=None, labels=unique_choices)
|
|
76
|
+
|
|
77
|
+
results = {}
|
|
78
|
+
for metric_name, metric_per_choice in zip(['precision', 'recall', 'f1', 'support'], metrics_per_choice):
|
|
79
|
+
results[metric_name] = {}
|
|
80
|
+
for choice, metric in zip(unique_choices, metric_per_choice):
|
|
81
|
+
results[metric_name][choice] = metric
|
|
82
|
+
|
|
83
|
+
return results
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import io
|
|
3
|
-
import shutil
|
|
4
|
-
import urllib
|
|
5
1
|
import hashlib
|
|
6
|
-
import
|
|
2
|
+
import io
|
|
3
|
+
import logging
|
|
7
4
|
import os
|
|
8
|
-
|
|
9
|
-
from appdirs import user_cache_dir, user_data_dir
|
|
10
|
-
from urllib.parse import urlparse, urljoin
|
|
5
|
+
import shutil
|
|
11
6
|
from contextlib import contextmanager
|
|
12
7
|
from tempfile import mkdtemp
|
|
8
|
+
from urllib.parse import urlparse
|
|
9
|
+
|
|
10
|
+
import requests
|
|
11
|
+
from appdirs import user_cache_dir, user_data_dir
|
|
13
12
|
|
|
14
13
|
from label_studio_sdk._extensions.label_studio_tools.core.utils.params import get_env
|
|
15
14
|
|
|
@@ -17,6 +16,7 @@ _DIR_APP_NAME = "label-studio"
|
|
|
17
16
|
LOCAL_FILES_DOCUMENT_ROOT = get_env(
|
|
18
17
|
"LOCAL_FILES_DOCUMENT_ROOT", default=os.path.abspath(os.sep)
|
|
19
18
|
)
|
|
19
|
+
VERIFY_SSL = get_env("VERIFY_SSL", default=True, is_bool=True)
|
|
20
20
|
|
|
21
21
|
logger = logging.getLogger(__name__)
|
|
22
22
|
|
|
@@ -80,6 +80,13 @@ def get_local_path(
|
|
|
80
80
|
f"`localhost` is not accessible inside of docker containers. "
|
|
81
81
|
f"You can check your IP with utilities like `ifconfig` and set it as LABEL_STUDIO_URL."
|
|
82
82
|
)
|
|
83
|
+
if hostname and not (
|
|
84
|
+
hostname.startswith("http://") or hostname.startswith("https://")
|
|
85
|
+
):
|
|
86
|
+
raise ValueError(
|
|
87
|
+
f"Invalid hostname in LABEL_STUDIO_URL: {hostname}. "
|
|
88
|
+
"Please provide full URL starting with protocol (http:// or https://)."
|
|
89
|
+
)
|
|
83
90
|
|
|
84
91
|
# fix file upload url
|
|
85
92
|
if url.startswith("upload") or url.startswith("/upload"):
|
|
@@ -180,13 +187,17 @@ def download_and_cache(
|
|
|
180
187
|
# File specified by remote URL - download and cache it
|
|
181
188
|
cache_dir = cache_dir or get_cache_dir()
|
|
182
189
|
parsed_url = urlparse(url)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
|
|
191
|
+
# local storage: /data/local-files?d=dir/1.jpg => 1.jpg
|
|
192
|
+
if is_local_storage_file:
|
|
193
|
+
url_filename = os.path.basename(url.split('?d=')[1])
|
|
194
|
+
# cloud storage: s3://bucket/1.jpg => 1.jpg
|
|
195
|
+
elif is_cloud_storage_file:
|
|
196
|
+
url_filename = os.path.basename(url)
|
|
197
|
+
# all others: /some/url/1.jpg?expire=xxx => 1.jpg
|
|
198
|
+
else:
|
|
199
|
+
url_filename = os.path.basename(parsed_url.path)
|
|
200
|
+
|
|
190
201
|
url_hash = hashlib.md5(url.encode()).hexdigest()[:8]
|
|
191
202
|
filepath = os.path.join(cache_dir, url_hash + "__" + url_filename)
|
|
192
203
|
|
|
@@ -205,8 +216,15 @@ def download_and_cache(
|
|
|
205
216
|
):
|
|
206
217
|
headers["Authorization"] = "Token " + access_token
|
|
207
218
|
logger.debug("Authorization token is used for download_and_cache")
|
|
208
|
-
|
|
209
|
-
|
|
219
|
+
try:
|
|
220
|
+
r = requests.get(url, stream=True, headers=headers, verify=VERIFY_SSL)
|
|
221
|
+
r.raise_for_status()
|
|
222
|
+
except requests.exceptions.SSLError as e:
|
|
223
|
+
logger.error(
|
|
224
|
+
f"SSL error during requests.get('{url}'): {e}\n"
|
|
225
|
+
f"Try to set VERIFY_SSL=False in environment variables to bypass SSL verification."
|
|
226
|
+
)
|
|
227
|
+
raise e
|
|
210
228
|
with io.open(filepath, mode="wb") as fout:
|
|
211
229
|
fout.write(r.content)
|
|
212
230
|
return filepath
|
|
@@ -9,6 +9,7 @@ from ..core.jsonable_encoder import jsonable_encoder
|
|
|
9
9
|
from ..core.pydantic_utilities import pydantic_v1
|
|
10
10
|
from ..core.request_options import RequestOptions
|
|
11
11
|
from ..types.annotation import Annotation
|
|
12
|
+
from .types.annotations_create_bulk_response_item import AnnotationsCreateBulkResponseItem
|
|
12
13
|
|
|
13
14
|
# this is used as the default value for optional parameters
|
|
14
15
|
OMIT = typing.cast(typing.Any, ...)
|
|
@@ -380,6 +381,60 @@ class AnnotationsClient:
|
|
|
380
381
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
381
382
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
382
383
|
|
|
384
|
+
def create_bulk(
|
|
385
|
+
self,
|
|
386
|
+
*,
|
|
387
|
+
tasks: typing.Optional[typing.Sequence[int]] = OMIT,
|
|
388
|
+
lead_time: typing.Optional[float] = OMIT,
|
|
389
|
+
project: typing.Optional[int] = OMIT,
|
|
390
|
+
result: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
|
|
391
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
392
|
+
) -> typing.List[AnnotationsCreateBulkResponseItem]:
|
|
393
|
+
"""
|
|
394
|
+
Create multiple annotations for specific tasks in a bulk operation.
|
|
395
|
+
|
|
396
|
+
Parameters
|
|
397
|
+
----------
|
|
398
|
+
tasks : typing.Optional[typing.Sequence[int]]
|
|
399
|
+
|
|
400
|
+
lead_time : typing.Optional[float]
|
|
401
|
+
|
|
402
|
+
project : typing.Optional[int]
|
|
403
|
+
|
|
404
|
+
result : typing.Optional[typing.Dict[str, typing.Any]]
|
|
405
|
+
|
|
406
|
+
request_options : typing.Optional[RequestOptions]
|
|
407
|
+
Request-specific configuration.
|
|
408
|
+
|
|
409
|
+
Returns
|
|
410
|
+
-------
|
|
411
|
+
typing.List[AnnotationsCreateBulkResponseItem]
|
|
412
|
+
Annotations created successfully
|
|
413
|
+
|
|
414
|
+
Examples
|
|
415
|
+
--------
|
|
416
|
+
from label_studio_sdk.client import LabelStudio
|
|
417
|
+
|
|
418
|
+
client = LabelStudio(
|
|
419
|
+
api_key="YOUR_API_KEY",
|
|
420
|
+
)
|
|
421
|
+
client.annotations.create_bulk()
|
|
422
|
+
"""
|
|
423
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
424
|
+
"api/annotations/bulk",
|
|
425
|
+
method="POST",
|
|
426
|
+
json={"tasks": tasks, "lead_time": lead_time, "project": project, "result": result},
|
|
427
|
+
request_options=request_options,
|
|
428
|
+
omit=OMIT,
|
|
429
|
+
)
|
|
430
|
+
try:
|
|
431
|
+
if 200 <= _response.status_code < 300:
|
|
432
|
+
return pydantic_v1.parse_obj_as(typing.List[AnnotationsCreateBulkResponseItem], _response.json()) # type: ignore
|
|
433
|
+
_response_json = _response.json()
|
|
434
|
+
except JSONDecodeError:
|
|
435
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
436
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
437
|
+
|
|
383
438
|
|
|
384
439
|
class AsyncAnnotationsClient:
|
|
385
440
|
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
@@ -748,3 +803,57 @@ class AsyncAnnotationsClient:
|
|
|
748
803
|
except JSONDecodeError:
|
|
749
804
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
750
805
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
806
|
+
|
|
807
|
+
async def create_bulk(
|
|
808
|
+
self,
|
|
809
|
+
*,
|
|
810
|
+
tasks: typing.Optional[typing.Sequence[int]] = OMIT,
|
|
811
|
+
lead_time: typing.Optional[float] = OMIT,
|
|
812
|
+
project: typing.Optional[int] = OMIT,
|
|
813
|
+
result: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
|
|
814
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
815
|
+
) -> typing.List[AnnotationsCreateBulkResponseItem]:
|
|
816
|
+
"""
|
|
817
|
+
Create multiple annotations for specific tasks in a bulk operation.
|
|
818
|
+
|
|
819
|
+
Parameters
|
|
820
|
+
----------
|
|
821
|
+
tasks : typing.Optional[typing.Sequence[int]]
|
|
822
|
+
|
|
823
|
+
lead_time : typing.Optional[float]
|
|
824
|
+
|
|
825
|
+
project : typing.Optional[int]
|
|
826
|
+
|
|
827
|
+
result : typing.Optional[typing.Dict[str, typing.Any]]
|
|
828
|
+
|
|
829
|
+
request_options : typing.Optional[RequestOptions]
|
|
830
|
+
Request-specific configuration.
|
|
831
|
+
|
|
832
|
+
Returns
|
|
833
|
+
-------
|
|
834
|
+
typing.List[AnnotationsCreateBulkResponseItem]
|
|
835
|
+
Annotations created successfully
|
|
836
|
+
|
|
837
|
+
Examples
|
|
838
|
+
--------
|
|
839
|
+
from label_studio_sdk.client import AsyncLabelStudio
|
|
840
|
+
|
|
841
|
+
client = AsyncLabelStudio(
|
|
842
|
+
api_key="YOUR_API_KEY",
|
|
843
|
+
)
|
|
844
|
+
await client.annotations.create_bulk()
|
|
845
|
+
"""
|
|
846
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
847
|
+
"api/annotations/bulk",
|
|
848
|
+
method="POST",
|
|
849
|
+
json={"tasks": tasks, "lead_time": lead_time, "project": project, "result": result},
|
|
850
|
+
request_options=request_options,
|
|
851
|
+
omit=OMIT,
|
|
852
|
+
)
|
|
853
|
+
try:
|
|
854
|
+
if 200 <= _response.status_code < 300:
|
|
855
|
+
return pydantic_v1.parse_obj_as(typing.List[AnnotationsCreateBulkResponseItem], _response.json()) # type: ignore
|
|
856
|
+
_response_json = _response.json()
|
|
857
|
+
except JSONDecodeError:
|
|
858
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
859
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import datetime as dt
|
|
4
|
+
import typing
|
|
5
|
+
|
|
6
|
+
from ...core.datetime_utils import serialize_datetime
|
|
7
|
+
from ...core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AnnotationsCreateBulkResponseItem(pydantic_v1.BaseModel):
|
|
11
|
+
id: typing.Optional[int] = None
|
|
12
|
+
|
|
13
|
+
def json(self, **kwargs: typing.Any) -> str:
|
|
14
|
+
kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
|
|
15
|
+
return super().json(**kwargs_with_defaults)
|
|
16
|
+
|
|
17
|
+
def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
|
18
|
+
kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
|
|
19
|
+
kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs}
|
|
20
|
+
|
|
21
|
+
return deep_union_pydantic_dicts(
|
|
22
|
+
super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none)
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
class Config:
|
|
26
|
+
frozen = True
|
|
27
|
+
smart_union = True
|
|
28
|
+
extra = pydantic_v1.Extra.allow
|
|
29
|
+
json_encoders = {dt.datetime: serialize_datetime}
|
label_studio_sdk/base_client.py
CHANGED
|
@@ -7,6 +7,7 @@ import httpx
|
|
|
7
7
|
|
|
8
8
|
from .actions.client import ActionsClient, AsyncActionsClient
|
|
9
9
|
from .annotations.client import AnnotationsClient, AsyncAnnotationsClient
|
|
10
|
+
from .comments.client import AsyncCommentsClient, CommentsClient
|
|
10
11
|
from .core.api_error import ApiError
|
|
11
12
|
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
12
13
|
from .environment import LabelStudioEnvironment
|
|
@@ -14,8 +15,10 @@ from .export_storage.client import AsyncExportStorageClient, ExportStorageClient
|
|
|
14
15
|
from .files.client import AsyncFilesClient, FilesClient
|
|
15
16
|
from .import_storage.client import AsyncImportStorageClient, ImportStorageClient
|
|
16
17
|
from .ml.client import AsyncMlClient, MlClient
|
|
18
|
+
from .model_providers.client import AsyncModelProvidersClient, ModelProvidersClient
|
|
17
19
|
from .predictions.client import AsyncPredictionsClient, PredictionsClient
|
|
18
20
|
from .projects.client import AsyncProjectsClient, ProjectsClient
|
|
21
|
+
from .prompts.client import AsyncPromptsClient, PromptsClient
|
|
19
22
|
from .tasks.client import AsyncTasksClient, TasksClient
|
|
20
23
|
from .users.client import AsyncUsersClient, UsersClient
|
|
21
24
|
from .views.client import AsyncViewsClient, ViewsClient
|
|
@@ -97,6 +100,9 @@ class LabelStudioBase:
|
|
|
97
100
|
self.import_storage = ImportStorageClient(client_wrapper=self._client_wrapper)
|
|
98
101
|
self.export_storage = ExportStorageClient(client_wrapper=self._client_wrapper)
|
|
99
102
|
self.webhooks = WebhooksClient(client_wrapper=self._client_wrapper)
|
|
103
|
+
self.prompts = PromptsClient(client_wrapper=self._client_wrapper)
|
|
104
|
+
self.model_providers = ModelProvidersClient(client_wrapper=self._client_wrapper)
|
|
105
|
+
self.comments = CommentsClient(client_wrapper=self._client_wrapper)
|
|
100
106
|
self.workspaces = WorkspacesClient(client_wrapper=self._client_wrapper)
|
|
101
107
|
|
|
102
108
|
|
|
@@ -174,6 +180,9 @@ class AsyncLabelStudioBase:
|
|
|
174
180
|
self.import_storage = AsyncImportStorageClient(client_wrapper=self._client_wrapper)
|
|
175
181
|
self.export_storage = AsyncExportStorageClient(client_wrapper=self._client_wrapper)
|
|
176
182
|
self.webhooks = AsyncWebhooksClient(client_wrapper=self._client_wrapper)
|
|
183
|
+
self.prompts = AsyncPromptsClient(client_wrapper=self._client_wrapper)
|
|
184
|
+
self.model_providers = AsyncModelProvidersClient(client_wrapper=self._client_wrapper)
|
|
185
|
+
self.comments = AsyncCommentsClient(client_wrapper=self._client_wrapper)
|
|
177
186
|
self.workspaces = AsyncWorkspacesClient(client_wrapper=self._client_wrapper)
|
|
178
187
|
|
|
179
188
|
|