Ce face hf (CLI-ul Hugging Face)
hf este interfața de linie de comandă inclusă în pachetul Python huggingface_hub. Cu ea te autentifici, creezi repository-uri, descarci și încarci fișiere, administrezi cache-ul local și lucrezi cu Spaces, Jobs, buckets, Inference Endpoints, discuții și webhooks. A fost introdusă în v0.34 și înlocuiește vechiul huggingface-cli, eliminat între timp.
Instalarea recomandată de documentație este scriptul standalone (curl -LsSf https://hf.co/cli/install.sh | bash pe macOS și Linux, sau varianta PowerShell pe Windows). Alternativ: pip install -U huggingface_hub, brew install hf sau uvx hf ... (pachetul PyPI hf, rulat izolat). Scriptul standalone instalează global și skill-ul hf-cli pentru agenți AI; --exclude-skill îl sare. hf update actualizează CLI-ul.
Majoritatea comenzilor acceptă aceleași opțiuni de formatare: --format (auto, human, agent, json, quiet), --json, -q / --quiet și --no-truncate. auto alege human într-un terminal interactiv și agent (valori separate prin tab, fără trunchiere) când CLI-ul este rulat de un agent AI. Pentru detalii despre orice comandă, rulează hf COMANDĂ --help.
Sintaxă și opțiuni
| Opțiune / Parametru | Descriere |
|---|---|
--skills |
Afișează SKILL.md-ul hf-cli (alias pentru hf skills preview). |
--install-completion |
Instalează autocompletarea pentru shell-ul curent. |
--show-completion |
Afișează scriptul de autocompletare, ca să-l copiezi sau să-l modifici. |
-h, --help |
Ajutorul comenzii. |
--format [auto|human|agent|json|quiet] |
Formatul ieșirii. Implicit auto. |
--json |
Echivalent cu --format json: JSON pentru scripturi și jq. |
-q, --quiet |
Echivalent cu --format quiet: doar ID-uri, câte unul pe rând. |
--no-truncate |
Afișează valorile complete în tabelele pentru oameni, fără .... |
Grupuri de comenzi |
auth, buckets, cache, collections, datasets, discussions, endpoints, extensions, jobs, models, papers, repos, sandbox, skills, spaces, webhooks. |
Comenzi directe |
cp, download, upload, sync, env, version, update, lfs-enable-largefiles, lfs-multipart-upload (intern). |
HF_HUB_DISABLE_UPDATE_CHECK=1 |
Variabilă de mediu: oprește verificarea versiunii noi (avertismentul galben de la pornire). |
Exemple practice
Exemplul 1: Instalare cu scriptul standalone (macOS / Linux)
curl -LsSf https://hf.co/cli/install.sh | bash
Exemplul 2: Instalare cu pip
pip install -U "huggingface_hub"
Exemplul 3: Verificarea instalării
hf --help
Rezultat
Usage: hf [OPTIONS] COMMAND [ARGS]...
Hugging Face Hub CLI
Options:
--skills Print the `hf-cli` SKILL.md to stdout (alias for `hf skills preview`).
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to copy it or customize the installation.
-h, --help Show this message and exit.
Main commands:
auth Manage authentication (login, logout, etc.).
buckets Commands to interact with buckets.
cache Manage local cache directory.
collections Interact with collections on the Hub.
datasets Interact with datasets on the Hub.
download Download files from the Hub.
endpoints Manage Hugging Face Inference Endpoints.
extensions Manage hf CLI extensions.
jobs Run and manage Jobs on the Hub.
models Interact with models on the Hub.
papers Interact with papers on the Hub.
repos Manage repos on the Hub.
skills Manage skills for AI assistants.
spaces Interact with spaces on the Hub.
sync Sync files between local directory and a bucket.
upload Upload a file or a folder to the Hub.
Help commands:
env Print information about the environment.
version Print information about the hf version.
Exemplul 4: Ieșire JSON pentru scripturi
hf models ls --search bert --limit 2 --json | jq '.[].id'
Greșeli frecvente și bune practici
- Folosești încă
huggingface-clidin tutoriale vechi. Comanda a fost eliminată; echivalentele sunt înhf(de exempluhf auth login,hf download,hf cache ls). - Combini două opțiuni de mod de ieșire, de exemplu
--jsoncu--format human. CLI-ul răspunde cu eroare de utilizare. - Parsezi tabelele pentru oameni în scripturi. Folosește
--format jsonsau-q, care au formă stabilă.