diff --git a/nucleus/__init__.py b/nucleus/__init__.py index ad0fa320..8ebfd836 100644 --- a/nucleus/__init__.py +++ b/nucleus/__init__.py @@ -109,6 +109,7 @@ PREDICTIONS_PROCESSED_KEY, REFERENCE_IDS_KEY, SLICE_ID_KEY, + SLICE_TAGS_KEY, STATUS_CODE_KEY, UPDATE_KEY, ) diff --git a/nucleus/constants.py b/nucleus/constants.py index 9d5a0e9a..32c2b704 100644 --- a/nucleus/constants.py +++ b/nucleus/constants.py @@ -144,6 +144,7 @@ STATUS_CODE_KEY = "status_code" STATUS_KEY = "status" SUCCESS_STATUS_CODES = [200, 201, 202] +SLICE_TAGS_KEY = "slice_tags" TAXONOMY_NAME_KEY = "taxonomy_name" TRACK_REFERENCE_ID_KEY = "track_reference_id" TRACK_REFERENCE_IDS_KEY = "track_reference_ids" diff --git a/nucleus/slice.py b/nucleus/slice.py index 6c5a7056..0f57e625 100644 --- a/nucleus/slice.py +++ b/nucleus/slice.py @@ -8,7 +8,12 @@ from nucleus.annotation import Annotation from nucleus.async_job import AsyncJob, EmbeddingsExportJob -from nucleus.constants import EXPORT_FOR_TRAINING_KEY, EXPORTED_ROWS, ITEMS_KEY +from nucleus.constants import ( + EXPORT_FOR_TRAINING_KEY, + EXPORTED_ROWS, + ITEMS_KEY, + SLICE_TAGS_KEY, +) from nucleus.dataset_item import DatasetItem from nucleus.errors import NucleusAPIError from nucleus.prediction import Prediction @@ -216,6 +221,10 @@ def dataset_id(self): self._dataset_id = self.info()["dataset_id"] return self._dataset_id + @property + def tags(self): + return self.info()["tags"] + @property def type(self): """The type of the Slice.""" @@ -330,6 +339,7 @@ def info(self) -> dict: "pending_job_count": int "created_at": datetime "description": Union[str, None] + "tags": } """ info = KeyErrorDict( @@ -347,6 +357,25 @@ def info(self) -> dict: self._description = info["description"] return info + def add_tags(self, tags: List[str]) -> dict: + """Tag a slice with custom tag names. :: + + import nucleus + client = nucleus.NucleusClient("YOUR_SCALE_API_KEY") + slc = client.get_slice("YOUR_SLICE_ID") + + slc.add_tags(["tag_1", "tag_1"]) + + Args: + tags: list of tag names + """ + response = self._client.make_request( + payload={SLICE_TAGS_KEY: tags}, + route=f"slice/{self.id}/tag", + requests_command=requests.post, + ) + return response + def append( self, reference_ids: Optional[List[str]] = None,