Skip to content

slice tag API support #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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