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
2
3
3
4
4
5
class Slice :
@@ -27,25 +28,37 @@ def info(self, id_type: str = DATASET_ITEM_ID_KEY) -> dict:
27
28
"""
28
29
return self ._client .slice_info (self .slice_id , id_type )
29
30
30
- def append (self , payload : dict ) -> dict :
31
+ def append (
32
+ self ,
33
+ dataset_item_ids : List [str ] = None ,
34
+ reference_ids : List [str ] = None
35
+ ) -> dict :
31
36
"""
32
37
Appends to a slice from items already present in a dataset.
33
38
The caller must exclusively use either datasetItemIds or reference_ids
34
39
as a means of identifying items in the dataset.
35
40
36
41
:param
37
- payload:
38
- {
39
- "dataset_item_ids": List[str],
40
- "reference_ids": List[str],
41
- }
42
-
42
+ dataset_item_ids: List[str],
43
+ reference_ids: List[str],
44
+
43
45
:return:
44
46
{
45
47
"slice_id": str,
46
48
}
47
49
"""
48
- response = self .client ._make_request (
50
+ if dataset_item_ids and reference_ids :
51
+ raise Exception (
52
+ "You cannot 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 (
49
62
payload , f"slice/{ self .slice_id } /append"
50
63
)
51
64
return response
0 commit comments