Skip to content
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

Manage access requests programmatically #1905

Merged
merged 7 commits into from
Dec 15, 2023
Merged

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Dec 14, 2023

Solves #1535.

Let's add official support to programmatically manage access requests for gated repos.

The API defines a AccessRequest dataclass with username, email, status, timestamp and fields + 7 endpoints. I reused as much as possible the vocabulary used in the UI. We have:

  • list_pending_access_requests => returns "pending" list
  • list_accepted_access_requests => returns "accepted" list
  • list_rejected_access_requests => returns "rejected" list
  • cancel_access_request => moves request to "pending" list
  • accept_access_request => moves request to "accepted" list
  • reject_access_request => moves request to "rejected" list
  • grant_access => add a user to "accepted" list (the user doesn't have to request access first)

Methods docstrings are documented with examples. I don't think it's worth creating a guide dedicated to it in huggingface_hub as it would be quite redundant with the Hub docs already. I suggest to update the Hub docs instead to mention the huggingface_hub implementation but that's it.

TODO:

@HuggingFaceDocBuilderDev

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.

Copy link
Contributor

@osanseviero osanseviero left a comment

Choose a reason for hiding this comment

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

Nice!

src/huggingface_hub/hf_api.py Outdated Show resolved Hide resolved
src/huggingface_hub/hf_api.py Outdated Show resolved Hide resolved
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

That's awesome! Very cool API.

Is it worth mentioning what kind of permissions they'll need on the repo to have access to the accepted/pending/rejected requests (is it read/write/admin?)? Especially given the example is Llama-2-7b.

src/huggingface_hub/hf_api.py Outdated Show resolved Hide resolved
tests/test_hf_api.py Show resolved Hide resolved
@Wauplin
Copy link
Contributor Author

Wauplin commented Dec 15, 2023

Thanks both for the review!

I have addressed your comments. @LysandreJik regarding roles in organization, the user must have "write" or "admin" role. I have updated the docstrings accordingly. (fyi, role contributor also have access to these settings on repos for which they have write access. It's a corner case so I haven't documented it).

I'll wait for the CI to pass and then merge this!

Copy link

codecov bot commented Dec 15, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (2b95d2b) 82.25% compared to head (ceed72a) 82.31%.
Report is 1 commits behind head on main.

Files Patch % Lines
src/huggingface_hub/hf_api.py 94.82% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1905      +/-   ##
==========================================
+ Coverage   82.25%   82.31%   +0.06%     
==========================================
  Files          65       65              
  Lines        8029     8087      +58     
==========================================
+ Hits         6604     6657      +53     
- Misses       1425     1430       +5     

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

@Wauplin Wauplin merged commit bf78eaa into main Dec 15, 2023
16 checks passed
@Wauplin Wauplin deleted the 1535-manage-access-requests branch December 15, 2023 09:48
@lappemic lappemic mentioned this pull request Apr 9, 2024
@RonanKMcGovern
Copy link

@lappemic @Wauplin has something changed here in the last days? After April 18th, my automations querying access seem to have stopped working. Curl requests like this:

curl -X GET \             
  'https://huggingface.co/api/repos/Trelis/Mistral-7B-Instruct-v0.1-Summarize-64k/user-access-request/pending' \
  -H 'Authorization: Bearer TOKEN'

seem not to be working any more

@Wauplin
Copy link
Contributor Author

Wauplin commented Apr 23, 2024

has something changed here in the last days?

@RonanKMcGovern shouldn't be the case no.

If you are getting errors, could you open a new ticket and provide more context (requests/script + error message + stacktrace if applicable). Thanks in advance!

@RonanKMcGovern
Copy link

Ah very sorry @Wauplin , I just realised I rolled my HF token after a live stream last week without realising it was being used in some automations. Thanks for the quick reply.

@Wauplin
Copy link
Contributor Author

Wauplin commented Apr 23, 2024

Glad your issue's solved then!

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.

6 participants