-
Notifications
You must be signed in to change notification settings - Fork 388
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
[FEATURE] update token retrieval logic #5541
[FEATURE] update token retrieval logic #5541
Conversation
for more information, see https://pre-commit.ci
…argilla into update-token-retrieval
here's a minimalistic colab code to try this PR before merging:
restart session then try this : from argilla._api._token import get_token
get_token() |
cc @frascuchon for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. This looks really handy. I added some small comments. Two general things:
- On naming: Currently, we're referring to our server api credentials as 'credentials' and 'api_key', rather than 'token'. I think this code should use the same naming. There's been confusion between argilla api_key and hf token before.
- The logic at the moment is to get both or no values (key and url) from
userdata
and fall back toenviron
. Do you think there's a use case where the user just wants the key from the userdata?
Thanks @not-lain for the contribution. Yesterday I was thinking about this. Since |
@frascuchon If you want to try it, I used this colab: https://colab.research.google.com/drive/1Qh1DFo7rZD_qR-FqCXYSRyv4m2_Z8qIG?usp=sharing. |
Co-authored-by: burtenshaw <ben.burtenshaw@gmail.com>
Co-authored-by: burtenshaw <ben.burtenshaw@gmail.com>
for more information, see https://pre-commit.ci
thanks a lot for the review
thanks for letting me know, will fix this in the next commit.
I can adapt my implementation to handle this case, I was a bit too skeptical because of the collab thread hanging forever issue (see huggingface/huggingface_hub#1952 ) and I wanted to make something that is robust instead of flexible. |
@not-lain Understood. I think it's a nice to have anyway, so if it compromises the functionality feel free to ignore the suggestion. |
@not-lain @frascuchon We should put this is 2.3.0! |
argilla/src/argilla/_api/_token.py
Outdated
return {"ARGILLA_API_URL": ARGILLA_API_URL, "ARGILLA_API_KEY": ARGILLA_API_KEY} | ||
|
||
|
||
def _get_token_from_google_colab() -> Optional[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can generalize this function to retrieve a secret from colab, an use it multiple times, instead of hardcoding the expected variables:
_get_secret_from_google_colab("ARGILLA_AP_KEY")
_get_secret_from_google_colab("ARGILLA_API_URL")
We could do something similar to the get_token
and the _get_token_from_environment
functions:
ARGILLA_API_KEY = get_secret("ARGILLA_API_KEY")
ARGILLA_API_URL = get_secret("ARGILLA_API_URL")
hi @frascuchon I have tried your changes which can be tested via the following code (different branch from this one)
which produced some weird behavior when running the following code from argilla._api._token import get_secret
key = get_secret("ARGILLA_API_KEY")
url = get_secret("ARGILLA_API_URL") initialize your secrets and turn them off global _IS_GOOGLE_COLAB_CHECKED not entirely sure of this but this is what I have discovered so far and I wanted to report my findings |
Apologies I have been looking at this from a different angle, colab turns out to handle things a slightly bit differently fromthe the normal way I was looking at this. from argilla._api._token import get_secret
ARGILLA_API_URL = get_secret("ARGILLA_API_URL")
ARGILLA_API_KEY = get_secret("ARGILLA_API_KEY") is DIFFERENT from import argilla as rg
rg.client._api.APIClient() I have no clue how and why this happened, but I will report my findings to colab and let them figure this out. I will now proceed to merge the changes that @frascuchon has recommended |
Co-authored-by: Paco Aranda <francisco.aranda@huggingface.co>
Co-authored-by: Paco Aranda <francisco.aranda@huggingface.co>
Co-authored-by: Paco Aranda <francisco.aranda@huggingface.co>
Co-authored-by: Paco Aranda <francisco.aranda@huggingface.co>
Co-authored-by: Paco Aranda <francisco.aranda@huggingface.co>
for more information, see https://pre-commit.ci
Co-authored-by: Paco Aranda <francisco.aranda@huggingface.co>
Co-authored-by: Paco Aranda <francisco.aranda@huggingface.co>
Co-authored-by: Paco Aranda <francisco.aranda@huggingface.co>
for more information, see https://pre-commit.ci
This PR should be ready for review, you can test this out by using the following code
import argilla as rg
rg.client._api.APIClient() |
Thanks @not-lain for taking into account my comments, and apologize for the inconvenience. So, finally, did you manage the errors applying my changes? Does the env loading work as expected? The current code looks nice! |
Hi @frascuchon, yes I can indeed confirm that everything is working perfectly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @not-lain !
@burtenshaw Does it make sense to add it somewhere in the docs? |
@frascuchon Yeah. I would just add a section to client API reference that mentions support for colab userdata. But let's merge this to develop, and I can open a docs PR. |
Description
support token retrieval from colab secrets
this PR is inspired by huggingface_hub's get_token function
if token exists in secrets it will prompt the user if they want to access it or not
#Fixes : #5543
Type of change
How Has This Been Tested
Checklist