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

Add utility to get repo name #364

Merged
merged 1 commit into from Sep 22, 2021
Merged

Add utility to get repo name #364

merged 1 commit into from Sep 22, 2021

Conversation

sgugger
Copy link
Contributor

@sgugger sgugger commented Sep 22, 2021

This PR adds a small utility function to get the full repo name from a model ID which:

  • extracts the username if no organization is passed and returns username/model_id
  • just returns organization/model_id otherwise

This function is used in all examples of Transformers.

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.

LGTM!

Comment on lines +321 to +331
def whoami(self, token: Optional[str] = None) -> Dict:
"""
Call HF API to know "whoami".

Args:
token (``str``): Hugging Face token.
token (``str``, `optional`):
Hugging Face token. Will default to the locally saved token if not provided.
"""
if token is None:
token = HfFolder.get_token()

Copy link
Member

Choose a reason for hiding this comment

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

WDYT @osanseviero? I think this is a great improvement in terms of user experience and should also be used to reopen conversations about:

  • having the HfApi.login saving the token
  • having the token default to the locally saved token when not passed through the HfApi

Copy link
Member

Choose a reason for hiding this comment

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

Agree it's a great improvement! Thanks @sgugger! (related issue: #154)

self,
model_id: str,
organization: Optional[str] = None,
token: Optional[str] = None,
Copy link
Member

Choose a reason for hiding this comment

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

In a similar fashion to what is done here

@LysandreJik LysandreJik merged commit 8e2b37c into main Sep 22, 2021
@LysandreJik LysandreJik deleted the get_full_repo_name branch September 22, 2021 22:19
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.

None yet

3 participants