Skip to content

Commit

Permalink
slice tag API support (#414)
Browse files Browse the repository at this point in the history
* retrieve tags through API

* add tags support
  • Loading branch information
pfmark authored Nov 29, 2023
1 parent 1babbf2 commit 3072b35
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions nucleus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
PREDICTIONS_PROCESSED_KEY,
REFERENCE_IDS_KEY,
SLICE_ID_KEY,
SLICE_TAGS_KEY,
STATUS_CODE_KEY,
UPDATE_KEY,
)
Expand Down
1 change: 1 addition & 0 deletions nucleus/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 30 additions & 1 deletion nucleus/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -330,6 +339,7 @@ def info(self) -> dict:
"pending_job_count": int
"created_at": datetime
"description": Union[str, None]
"tags":
}
"""
info = KeyErrorDict(
Expand All @@ -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,
Expand Down

0 comments on commit 3072b35

Please sign in to comment.