Login to huggingface with a token asks for username and password
I would like to use a model from huggingface. Since the model is hidden behind authentication, I follow examples section of Documentation for ramalama login and run:
$ ramalama login --token="${TOKEN}" huggingface
but instead of logging me in, I'm being asked for Username: .
I have found a trivial typo on this line:
if registry in ["ollama", "hf" "huggingface"]:
which python interprets as:
>>> repr(["ollama", "hf" "huggingface"])
"['ollama', 'hfhuggingface']"
so I assume it should be:
if registry in ["ollama", "hf", "huggingface"]:
This is not enough though, because the registry from the command line (huggingface) is not one of the expected prefixes in factory function New(). I'm not sure how to fix this properly, but temporary workaround with:
if model.startswith("huggingface") or model.startswith("huggingface://") or model.startswith("hf://") or model.startswith("hf.co/"):
led me to an error:
Error: huggingface-cli not available, skipping login.
I haven't seen a requirement of this CLI to be installed on the system anywhere in the documentation. I guess best place would be in the examples section of ramalama-login, either using the command (pip install -U "huggingface_hub[cli]") or linking to https://huggingface.co/docs/huggingface_hub/en/guides/cli where I found it.
After all of this I was able to login.
I think the best fix is to implement ramalama login in python3 from scratch it shouldn't be too bad, I've seen at least 3 implementations of it.
But yes a documentation addition to install huggingface would be enough to close this issue for now. It's deliberately not a strong dependancy because it can be hard to install it on some platforms.
Would you like to open a PR @pbabinca with a documentation update?
If you are really interested in solving this, a PR with the python code is the longer term fix.
Would you like to open a PR @pbabinca with a documentation update?
Opened #645 which should solve the last issue.
The other two issues, though, are not resolved yet. I'm not sure if test of the prefix huggingface on the top/instead of the "scheme" of URL is the correct way. I'm not sure which parts of code use that factory function.
I received the mail "Opportunities to Contribute to RamaLama AI Project", and saw these "good first issues", let me fix one minor bug before going deeper
Fix bug in login_cli and update huggingface or hf registry behavior #1232
@melodyliu1986 any progress on this?
I tested using the latest version of ramalama, here are the details:
1. login with token
$ env RAMALAMA_TRANSPORT=huggingface ramalama login --token=hf_$mytoken
⚠️ Warning: 'huggingface-cli login' is deprecated. Use 'hf auth login' instead.
The token has not been saved to the git credentials helper. Pass add_to_git_credential=True in this function directly or --add-to-git-credential if using via hfCLI if you want to set the git credential as well.
Token is valid (permission: write).
The token soliu-read-write has been saved to /home/songliu/.cache/huggingface/stored_tokens
Your token has been saved to /home/songliu/.cache/huggingface/token
Login successful.
The current active token is: soliu-read-write
$ env RAMALAMA_TRANSPORT=huggingface ramalama logout
⚠️ Warning: 'huggingface-cli logout' is deprecated. Use 'hf auth logout' instead.
Successfully logged out from all access tokens.
2. login without token $ env RAMALAMA_TRANSPORT=huggingface ramalama login ⚠️ Warning: 'huggingface-cli login' is deprecated. Use 'hf auth login' instead.
_| _| _| _| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_|_| _|_| _|_|_| _|_|_|_|
_| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
_|_|_|_| _| _| _| _|_| _| _|_| _| _| _| _| _| _|_| _|_|_| _|_|_|_| _| _|_|_|
_| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|
_| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|
To log in, `huggingface_hub` requires a token generated from https://huggingface.co/settings/tokens .
Enter your token (input will not be visible):
Add token as git credential? (Y/n) n
Token is valid (permission: write).
The token soliu-read-write has been saved to /home/songliu/.cache/huggingface/stored_tokens
Your token has been saved to /home/songliu/.cache/huggingface/token
Login successful.
The current active token is: soliu-read-write
$ env RAMALAMA_TRANSPORT=huggingface ramalama logout
⚠️ Warning: 'huggingface-cli logout' is deprecated. Use 'hf auth logout' instead.
Successfully logged out from all access tokens.
3. login without huggingface_cli installed $ pip uninstall huggingface_hub Found existing installation: huggingface-hub 0.34.2 Uninstalling huggingface-hub-0.34.2: Would remove: /home/songliu/.local/bin/hf /home/songliu/.local/bin/huggingface-cli /home/songliu/.local/bin/tiny-agents /home/songliu/.local/lib/python3.12/site-packages/huggingface_hub-0.34.2.dist-info/* /home/songliu/.local/lib/python3.12/site-packages/huggingface_hub/* Proceed (Y/n)? y Successfully uninstalled huggingface-hub-0.34.2 $ env RAMALAMA_TRANSPORT=huggingface ramalama login Error: Optional: Huggingface models require the huggingface-cli module. This module can be installed via PyPI tools like uv, pip, pip3, pipx, or via distribution package managers like dnf or apt. Example: uv pip install huggingface_hub
From the above test, I found that there is no "Username" required when logging in with a token, and the message guiding us to install huggingface_cli is also clear. If we need to improve something, that might be the warning of "huggingface-cli login" and "hugging-cli logout" are deprecated. WDYT? @rhatdan @pbabinca
From the above test, I found that there is no "Username" required when logging in with a token,
👍 it indeed no longer requires username. Which resolves my original issue and I believe this issue could be marked as resolved.
Now for the rest:
and the message guiding us to install huggingface_cli is also clear.
👍 I wouldn't say it is clear. When I try to log in I get a message that starts with:
Error: Optional: Huggingface models require the huggingface-cli module.
It seems to me that the error message is missing. I think it would be clearer to me if the message is:
Error: "huggingface-cli" module is missing.
And then, follow with an empty line since the rest if the guidance how to fix that.
In the guidance I wouldn't introduce that with "Optional: " since I asked ramalama to use "huggingface" and missing CLI tool is not optional in this case.
And regarding wording:
This module can be installed via PyPI tools like uv, pip, pip3, pipx, or via distribution package managers like dnf or apt. Example: uv pip install huggingface_hub
I do like uv but I think it would make more sense to be consistent in the example. Readme suggests lists - dnf, PyPI and install script as ways to install the ramalama. So I'd suggest to give a hint:
On Fedora: sudo dnf install huggingface-cli On other systems, e.g.: pip install -U "huggingface_hub[cli]"
instead of the uv approach.
If you plan to switch guides to uv elsewhere (e.g. the README) then you could update the examples command in the man page to:
env RAMALAMA_TRANSPORT=huggingface uv tool run --with "huggingface_hub[cli]" ramalama login --token="${TOKEN}"
to log in.
If we need to improve something, that might be the warning of "huggingface-cli login" and "hugging-cli logout" are deprecated. WDYT?
Sure, it would be nice as well. 👍
If you think my suggestions (above) make sense feel free to create new, follow-up issue(s).
@pbabinca interested in opening a PR with your suggested fixes?
The original issue has been resolved. Thanks all who helped! Closing as resolved.
Follow-up ideas for improvements in #1766.
From the above test, I found that there is no "Username" required when logging in with a token,
👍 it indeed no longer requires username. Which resolves my original issue and I believe this issue could be marked as resolved.
Thanks for the confirmation.
Now for the rest:
and the message guiding us to install huggingface_cli is also clear.
👍 I wouldn't say it is clear. When I try to log in I get a message that starts with:
Error: Optional: Huggingface models require the huggingface-cli module.
It seems to me that the error message is missing. I think it would be clearer to me if the message is:
Error: "huggingface-cli" module is missing.
And then, follow with an empty line since the rest if the guidance how to fix that.
In the guidance I wouldn't introduce that with "Optional: " since I asked ramalama to use "huggingface" and missing CLI tool is not optional in this case.
And regarding wording:
This module can be installed via PyPI tools like uv, pip, pip3, pipx, or via distribution package managers like dnf or apt. Example: uv pip install huggingface_hub
I do like
uvbut I think it would make more sense to be consistent in the example. Readme suggests lists - dnf, PyPI and install script as ways to install theramalama. So I'd suggest to give a hint:On Fedora: sudo dnf install huggingface-cli On other systems, e.g.: pip install -U "huggingface_hub[cli]"
instead of the
uvapproach.
I agree.
If you plan to switch guides to
uvelsewhere (e.g. the README) then you could update the examples command in the man page to:env RAMALAMA_TRANSPORT=huggingface uv tool run --with "huggingface_hub[cli]" ramalama login --token="${TOKEN}"to log in.
If we need to improve something, that might be the warning of "huggingface-cli login" and "hugging-cli logout" are deprecated. WDYT?
Sure, it would be nice as well. 👍
sure, I will submit a PR.
If you think my suggestions (above) make sense feel free to create new, follow-up issue(s).