Skip to content

feat(hub): create and delete a collection #1584

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

Conversation

quanghuynt14
Copy link
Contributor

@quanghuynt14 quanghuynt14 commented Jul 2, 2025

@quanghuynt14 quanghuynt14 requested a review from coyotte508 as a code owner July 2, 2025 08:17
* Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
*/
fetch?: typeof fetch;
} & ApiCreateCollectionPayload &
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we put the payload to a variable params.payload? That way, if we decide to add new prop to ApiCreateCollectionPayload in the future, we will not need to remap the entire body as we foward all the props from params.payload.

Copy link
Member

Choose a reason for hiding this comment

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

yes, but name the parameter collection

Comment on lines 19 to 26
/**
* First item to add to the collection upon creation.
*/
item?: {
type: "paper" | "collection" | "space" | "model" | "dataset";
id: string;
};
}
Copy link
Member

Choose a reason for hiding this comment

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

TBH not sure it's worth it to add this param to the API for the hub library, since the user will most of the time want to add other items.

(It'd be nice if we had a way to init collection with multiple items, cc @Kakulukian)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I think so too. I just removed it for this PR (and it's in line with what we do in the Python client)

@quanghuynt14 quanghuynt14 requested a review from coyotte508 July 7, 2025 17:00
/**
* The slug of the collection to delete.
*/
collectionSlug: string;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
collectionSlug: string;
slug: string;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I also change it in create-collection.ts. WDYT?

@quanghuynt14
Copy link
Contributor Author

I was a bit confused when I saw the endpoint: GET /api/collections/{namespace}/{slug}-{id} (https://huggingface.co/spaces/huggingface/openapi#tag/collections/get/api/collections/{namespace}/{slug}-{id})

But in fact, slug = {namespace}/{slug}-{id}

We also have collectionSlug in collection-info.ts (https://github.com/quanghuynt14/huggingface.js/blob/312da8611297a32231cef1652e060e0b6731298d/packages/hub/src/lib/collection-info.ts#L12). Should I create a PR refactor to rename collectionSlug to slug?

@quanghuynt14 quanghuynt14 requested a review from coyotte508 July 7, 2025 20:37
@coyotte508
Copy link
Member

We also have collectionSlug in collection-info.ts (quanghuynt14/huggingface.js@312da86/packages/hub/src/lib/collection-info.ts#L12). Should I create a PR refactor to rename collectionSlug to slug?

You can add it to this PR

And yes it's confusing

@quanghuynt14
Copy link
Contributor Author

Hey @coyotte508, there are failed tests but they are unrelated. We merge this PR?

@coyotte508 coyotte508 merged commit 6ec4906 into huggingface:main Jul 8, 2025
3 of 4 checks passed
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.

2 participants