Skip to content

Commit 1ae4335

Browse files
authored
Merge pull request #26 from scaleapi/jihan-slice-api
Adds function to slice instance that lets users append new images to the slice. Tested locally, working with conjunction with scaleapi/scaleapi#21392.
2 parents 81c5f2d + 74ae5b1 commit 1ae4335

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

nucleus/slice.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from .constants import DATASET_ITEM_ID_KEY
1+
from typing import List, Dict, Any
2+
from .constants import DATASET_ITEM_ID_KEY, REFERENCE_IDS_KEY
23

34

45
class Slice:
@@ -15,7 +16,6 @@ def info(self, id_type: str = DATASET_ITEM_ID_KEY) -> dict:
1516
This endpoint provides information about specified slice.
1617
1718
:param
18-
slice_id: id of the slice
1919
id_type: the type of IDs you want in response (either "reference_id" or "dataset_item_id")
2020
to identify the DatasetItems
2121
@@ -27,3 +27,38 @@ def info(self, id_type: str = DATASET_ITEM_ID_KEY) -> dict:
2727
}
2828
"""
2929
return self._client.slice_info(self.slice_id, id_type)
30+
31+
def append(
32+
self,
33+
dataset_item_ids: List[str] = None,
34+
reference_ids: List[str] = None
35+
) -> dict:
36+
"""
37+
Appends to a slice from items already present in a dataset.
38+
The caller must exclusively use either datasetItemIds or reference_ids
39+
as a means of identifying items in the dataset.
40+
41+
:param
42+
dataset_item_ids: List[str],
43+
reference_ids: List[str],
44+
45+
:return:
46+
{
47+
"slice_id": str,
48+
}
49+
"""
50+
if dataset_item_ids and reference_ids:
51+
raise Exception(
52+
"You cannot specify both dataset_item_ids and reference_ids"
53+
)
54+
55+
payload: Dict[str, Any] = {}
56+
if dataset_item_ids:
57+
payload[DATASET_ITEM_IDS_KEY] = dataset_item_ids
58+
if reference_ids:
59+
payload[REFERENCE_IDS_KEY] = reference_ids
60+
61+
response = self._client._make_request(
62+
payload, f"slice/{self.slice_id}/append"
63+
)
64+
return response

0 commit comments

Comments
 (0)