Skip to content

[HfApi] Collections in collections#3120

Merged
hanouticelina merged 2 commits intomainfrom
collections-in-collections
May 27, 2025
Merged

[HfApi] Collections in collections#3120
hanouticelina merged 2 commits intomainfrom
collections-in-collections

Conversation

@hanouticelina
Copy link
Copy Markdown
Contributor

Originally reported by @xeophon in this gist, it wasn't possible to access the collection slug when a collection item was itself a collection, and this was flagged internally by @Vaibhavs10 in this Slack message.

This PR enables proper client-side handling of collections that include collections as items. When the item type is "collection", we now set item_id to the collection’s slug, ensuring consistency with how other item types (model, dataset, space, paper) are handled.

from huggingface_hub import get_collection

# a collection with only collection items
collection_slug = "celinah/inference-providers-function-calling-6826023e8ae9b24b3039ee5f"

print(f"Fetching collection: {collection_slug}")
collection = get_collection(collection_slug)
for i, item in enumerate(collection.items):
    print(f"Item {i + 1}:")
    print(f"  Collection Slug: {item.item_id}")
    print(f"  Object ID: {item.item_object_id}")
    print(f"  Type: {item.item_type}")

for reference, server-side PR here (private link).

@hanouticelina hanouticelina requested a review from Wauplin May 26, 2025 15:25
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2025

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 53.80%. Comparing base (1ebdbf9) to head (af1eaa5).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/huggingface_hub/hf_api.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3120       +/-   ##
===========================================
- Coverage   76.33%   53.80%   -22.53%     
===========================================
  Files         130      133        +3     
  Lines       12952    13286      +334     
===========================================
- Hits         9887     7149     -2738     
- Misses       3065     6137     +3072     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@ghost
Copy link
Copy Markdown

ghost commented May 26, 2025

Just ran my scripts, and it does work as expected with this PR. Thank you so, so much!!

Copy link
Copy Markdown
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@hanouticelina hanouticelina merged commit 0ef2d68 into main May 27, 2025
27 checks passed
@hanouticelina hanouticelina deleted the collections-in-collections branch May 27, 2025 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants