135135
136136
137137R = TypeVar ("R" ) # Return type
138- CollectionItemType_T = Literal ["model" , "dataset" , "space" , "paper" ]
138+ CollectionItemType_T = Literal ["model" , "dataset" , "space" , "paper" , "collection" ]
139139
140140ExpandModelProperty_T = Literal [
141141 "author" ,
@@ -1169,16 +1169,16 @@ def __init__(self, **kwargs):
11691169@dataclass
11701170class CollectionItem :
11711171 """
1172- Contains information about an item of a Collection (model, dataset, Space or paper ).
1172+ Contains information about an item of a Collection (model, dataset, Space, paper or collection ).
11731173
11741174 Attributes:
11751175 item_object_id (`str`):
11761176 Unique ID of the item in the collection.
11771177 item_id (`str`):
1178- ID of the underlying object on the Hub. Can be either a repo_id or a paper id
1179- e.g. `"jbilcke-hf/ai-comic-factory"`, `"2307.09288"`.
1178+ ID of the underlying object on the Hub. Can be either a repo_id, a paper id or a collection slug.
1179+ e.g. `"jbilcke-hf/ai-comic-factory"`, `"2307.09288"`, `"celinah/cerebras-function-calling-682607169c35fbfa98b30b9a"` .
11801180 item_type (`str`):
1181- Type of the underlying object. Can be one of `"model"`, `"dataset"`, `"space"` or `"paper "`.
1181+ Type of the underlying object. Can be one of `"model"`, `"dataset"`, `"space"`, `"paper"` or `"collection "`.
11821182 position (`int`):
11831183 Position of the item in the collection.
11841184 note (`str`, *optional*):
@@ -1192,10 +1192,20 @@ class CollectionItem:
11921192 note : Optional [str ] = None
11931193
11941194 def __init__ (
1195- self , _id : str , id : str , type : CollectionItemType_T , position : int , note : Optional [Dict ] = None , ** kwargs
1195+ self ,
1196+ _id : str ,
1197+ id : str ,
1198+ type : CollectionItemType_T ,
1199+ position : int ,
1200+ note : Optional [Dict ] = None ,
1201+ ** kwargs ,
11961202 ) -> None :
11971203 self .item_object_id : str = _id # id in database
11981204 self .item_id : str = id # repo_id or paper id
1205+ # if the item is a collection, override item_id with the slug
1206+ slug = kwargs .get ("slug" )
1207+ if slug is not None :
1208+ self .item_id = slug # collection slug
11991209 self .item_type : CollectionItemType_T = type
12001210 self .position : int = position
12011211 self .note : str = note ["text" ] if note is not None else None
0 commit comments