Skip to content

Commit 4ce8082

Browse files
Narek MkhitaryanNarek Mkhitaryan
authored andcommitted
added include categories option in list_items
1 parent d342cd9 commit 4ce8082

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2903,7 +2903,7 @@ def list_items(
29032903
project: Union[NotEmptyStr, int],
29042904
folder: Optional[Union[NotEmptyStr, int]] = None,
29052905
*,
2906-
include: List[Literal["custom_metadata", "category"]] = None,
2906+
include: List[Literal["custom_metadata", "categories"]] = None,
29072907
**filters,
29082908
):
29092909
"""
@@ -2923,6 +2923,7 @@ def list_items(
29232923
Possible values are
29242924
29252925
- "custom_metadata": Includes custom metadata attached to the item.
2926+
- "categories": Includes categories attached to the item.
29262927
:type include: list of str, optional
29272928
29282929
:param filters: Specifies filtering criteria (e.g., name, ID, annotation status),
@@ -2993,6 +2994,40 @@ def list_items(
29932994
}
29942995
]
29952996
2997+
Request Example with include categories:
2998+
::
2999+
3000+
client.list_items(
3001+
project="My Multimodal",
3002+
folder="folder1",
3003+
include=["categories"]
3004+
)
3005+
3006+
Response Example:
3007+
::
3008+
3009+
[
3010+
{
3011+
"id": 48909383,
3012+
"name": "scan_123.jpeg",
3013+
"path": "Medical Annotations/folder1",
3014+
"url": "https://sa-public-files.s3.../scan_123.jpeg",
3015+
"annotation_status": "InProgress",
3016+
"createdAt": "2022-02-10T14:32:21.000Z",
3017+
"updatedAt": "2022-02-15T20:46:44.000Z",
3018+
"entropy_value": None,
3019+
"assignments": [],
3020+
"categories": [
3021+
{
3022+
"createdAt": "2025-01-29T13:51:39.000Z",
3023+
"updatedAt": "2025-01-29T13:51:39.000Z",
3024+
"id": 328577,
3025+
"name": "my_category",
3026+
},
3027+
],
3028+
}
3029+
]
3030+
29963031
Additional Filter Examples:
29973032
::
29983033
@@ -3014,6 +3049,14 @@ def list_items(
30143049
if isinstance(project, int)
30153050
else self.controller.get_project(project)
30163051
)
3052+
if (
3053+
include
3054+
and "categories" in include
3055+
and project.type != ProjectType.MULTIMODAL.value
3056+
):
3057+
raise AppException(
3058+
"The 'categories' option in the 'include' field is only supported for Multimodal projects."
3059+
)
30173060
if folder is None:
30183061
folder = self.controller.get_folder(project, "root")
30193062
else:

src/superannotate/lib/core/entities/items.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from lib.core.entities.base import BaseItemEntity
4+
from lib.core.entities.base import TimedBaseModel
45
from lib.core.enums import ApprovalStatus
56
from lib.core.enums import ProjectType
67
from lib.core.pydantic_v1 import Extra
@@ -16,6 +17,21 @@ class Config:
1617
extra = Extra.ignore
1718

1819

20+
class MultiModalItemCategoryEntity(TimedBaseModel):
21+
id: int = Field(None, alias="category_id")
22+
name: str = Field(None, alias="category_name")
23+
24+
class Config:
25+
extra = Extra.ignore
26+
27+
28+
class MultiModalItemEntity(BaseItemEntity):
29+
categories: Optional[list[MultiModalItemCategoryEntity]]
30+
31+
class Config:
32+
extra = Extra.ignore
33+
34+
1935
class VideoEntity(BaseItemEntity):
2036
approval_status: Optional[ApprovalStatus] = Field(None)
2137

@@ -51,4 +67,5 @@ class Config:
5167
ProjectType.TILED: ImageEntity,
5268
ProjectType.VIDEO: VideoEntity,
5369
ProjectType.DOCUMENT: DocumentEntity,
70+
ProjectType.MULTIMODAL: MultiModalItemEntity,
5471
}

src/superannotate/lib/core/usecases/items.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from lib.core.entities import ImageEntity
1818
from lib.core.entities import ProjectEntity
1919
from lib.core.entities import VideoEntity
20+
from lib.core.entities.items import MultiModalItemEntity
2021
from lib.core.exceptions import AppException
2122
from lib.core.exceptions import AppValidationException
2223
from lib.core.exceptions import BackendError
@@ -60,6 +61,8 @@ def serialize_item_entity(
6061
return VideoEntity(**entity.dict(by_alias=True))
6162
elif project.type == constants.ProjectType.DOCUMENT.value:
6263
return DocumentEntity(**entity.dict(by_alias=True))
64+
elif project.type == constants.ProjectType.MULTIMODAL.value:
65+
return MultiModalItemEntity(**entity.dict(by_alias=True))
6366
return entity
6467

6568

0 commit comments

Comments
 (0)