o
    ~ri+                     @   s  d Z ddlZddlZddlmZmZmZ ddlZddlm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZ ee	Zejddd	 eD ed
Zee
Zejddd	 eD ed
ZeddZejdg ddddddejddfdeee ejddf deee ejddf deee ejddf dededededdfdd Zejd!d"gd	d`d#eeej d$df deddfd%d&Z!ejd'g d(d					dad)eeej d*df d+eee ejd,df d-eee ejd.df d/ee"ejd0df d1ee"ejd2df deddfd3d4Z#ejd5g d6d						dbd#eeej d$df d)eee ejd7df d-eee ejd8df d9eee$ ejd:df d/eee" ejd;df d<eee ejd=df deddfd>d?Z%ejd@dAdBgd		dcd#eeej d$df dCee"ejdDdf deddfdEdFZ&ejdGg dHd			ddd#eeej d$df dIeeej dJdf dKeeej dLdf dMeee ejdNdf d1ee"ejdOdf deddfdPdQZ'ejdRdSdTgd			ded#eeej d$df dUeeej dVdf dMeee ejdWdf d9eee$ ejdXdf deddfdYdZZ(ed[		dcd#eeej d$df dUeeej d\df dCee"ejd]df deddf
d^d_Z)dS )fa_  Contains commands to interact with collections on the Hugging Face Hub.

Usage:
    # list collections on the Hub
    hf collections ls

    # list collections for a specific user
    hf collections ls --owner username

    # get info about a collection
    hf collections info username/collection-slug

    # create a new collection
    hf collections create "My Collection" --description "A collection of models"

    # add an item to a collection
    hf collections add-item username/collection-slug username/model-name model

    # delete a collection
    hf collections delete username/collection-slug
    N)	AnnotatedOptionalget_args)CollectionItemType_TCollectionSort_T   )		FormatOptLimitOptOutputFormatQuietOptTokenOptapi_object_to_dict
get_hf_apiprint_list_outputtyper_factoryCollectionItemTypec                 C      i | ]}||qS  r   ).0tr   r   m/lsinfo/ai/hellotax_ai/llm_service/venv_embed/lib/python3.10/site-packages/huggingface_hub/cli/collections.py
<dictcomp>;       r   )typeCollectionSortc                 C   r   r   r   )r   sr   r   r   r   >   r   z%Interact with collections on the Hub.)helpz	list | ls)zhf collections lsz hf collections ls --owner nvidiazLhf collections ls --item models/teknium/OpenHermes-2.5-Mistral-7B --limit 10)examples
   Fownerz)Filter by owner username or organization.itemzkFilter collections containing a specific item (e.g., "models/gpt2", "datasets/squad", "papers/2311.12983").sortz4Sort results by last modified, trending, or upvotes.limitformatquiettokenreturnc           
      C   sF   t |d}|r
|jnd}dd |j| |||dD }	t|	||d dS )zList collections on the Hub.r%   Nc                 S   s   g | ]}t |qS r   )r   )r   
collectionr   r   r   
<listcomp>c   s    z"collections_ls.<locals>.<listcomp>)r   r    r!   r"   )r#   r$   )r   valuelist_collectionsr   )
r   r    r!   r"   r#   r$   r%   apisort_keyresultsr   r   r   collections_lsD   s   
	r/   infoz/hf collections info username/my-collection-slugcollection_slugz7The collection slug (e.g., 'username/collection-slug').c                 C   s.   t |d}|| }ttjt|dd dS )zAGet info about a collection on the Hub. Output is in JSON format.r'      indentN)r   get_collectionprintjsondumpsr   )r1   r%   r,   r(   r   r   r   collections_infoo   s   

r9   create)z!hf collections create "My Models"z^hf collections create "My Models" --description "A collection of my favorite models" --privatez9hf collections create "Org Collection" --namespace my-orgtitlezThe title of the collection.	namespacezMThe namespace (username or organization). Defaults to the authenticated user.descriptionz!A description for the collection.privatezCreate a private collection.	exists_okz7Do not raise an error if the collection already exists.c                 C   sH   t |d}|j| ||||d}td|j  ttjt|dd dS )z#Create a new collection on the Hub.r'   )r;   r<   r=   r>   r?   zCollection created: r2   r3   N)r   create_collectionr6   urlr7   r8   r   )r;   r<   r=   r>   r?   r%   r,   r(   r   r   r   collections_create   s   
rB   update)z@hf collections update username/my-collection --title "New Title"zPhf collections update username/my-collection --description "Updated description"zDhf collections update username/my-collection --private --theme greenz!The new title for the collection.z'The new description for the collection.positionz7The new position of the collection in the owner's list.z)Whether the collection should be private.themez;The theme color for the collection (e.g., 'green', 'blue').c           	      C   sJ   t |d}|j| |||||d}td|j  ttjt|dd dS )z*Update a collection's metadata on the Hub.r'   )r1   r;   r=   rD   r>   rE   zCollection updated: r2   r3   N)r   update_collection_metadatar6   rA   r7   r8   r   )	r1   r;   r=   rD   r>   rE   r%   r,   r(   r   r   r   collections_update   s   
!rG   deletez,hf collections delete username/my-collectionz9hf collections delete username/my-collection --missing-ok
missing_okz6Do not raise an error if the collection doesn't exist.c                 C   s*   t |d}|j| |d td|   dS )z!Delete a collection from the Hub.r'   )rI   zCollection deleted: N)r   delete_collectionr6   )r1   rI   r%   r,   r   r   r   collections_delete   s   
rK   zadd-item)zGhf collections add-item username/my-collection moonshotai/kimi-k2 modelz`hf collections add-item username/my-collection Qwen/DeepPlanning dataset --note "Useful dataset"zGhf collections add-item username/my-collection Tongyi-MAI/Z-Image spaceitem_idzCThe ID of the item to add (repo_id for repos, paper ID for papers).	item_typez?The type of item (model, dataset, space, paper, or collection).notez2A note to attach to the item (max 500 characters).z?Do not raise an error if the item is already in the collection.c                 C   sH   t |d}|j| ||j||d}td|   ttjt|dd dS )zAdd an item to a collection.r'   )r1   rL   rM   rN   r?   zItem added to collection: r2   r3   N)r   add_collection_itemr*   r6   r7   r8   r   )r1   rL   rM   rN   r?   r%   r,   r(   r   r   r   collections_add_item   s   
rP   zupdate-itemzVhf collections update-item username/my-collection ITEM_OBJECT_ID --note "Updated note"zMhf collections update-item username/my-collection ITEM_OBJECT_ID --position 0item_object_idzTThe ID of the item in the collection (from 'item_object_id' field, not the repo_id).z-A new note for the item (max 500 characters).z/The new position of the item in the collection.c                 C   s.   t |d}|j| |||d td|   dS )zUpdate an item in a collection.r'   )r1   rQ   rN   rD   zItem updated in collection: N)r   update_collection_itemr6   )r1   rQ   rN   rD   r%   r,   r   r   r   collections_update_item  s   
rS   zdelete-itemznThe ID of the item in the collection (retrieved from `item_object_id` field returned by 'hf collections info'.z0Do not raise an error if the item doesn't exist.c                 C   s,   t |d}|j| ||d td|   dS )z!Delete an item from a collection.r'   )r1   rQ   rI   zItem deleted from collection: N)r   delete_collection_itemr6   )r1   rQ   rI   r%   r,   r   r   r   collections_delete_item5  s   
rU   )N)NNFFN)NNNNNN)FN)NFN)NNN)*__doc__enumr7   typingr   r   r   typerhuggingface_hub.hf_apir   r   
_cli_utilsr   r	   r
   r   r   r   r   r   r   _COLLECTION_ITEM_TYPESEnumstrr   _COLLECTION_SORT_OPTIONSr   collections_clicommandtableOptionr/   Argumentr9   boolrB   intrG   rK   rP   rS   rU   r   r   r   r   <module>   s  ,


#





!





&

	

 




