用途:当任务需要借助 Hugging Face API 数据时,本技能用于创建可复用的命令行脚本与工具,便于链式调用、管道与中间处理,并可按需查询模型、数据集、Spaces、集合、每日论文等。
主要能力:可以直接访问 API,也可使用 hf 命令行工具;可从仓库直接读取模型与数据集卡片。高层端点包括 /api/datasets、/api/models、/api/spaces、/api/collections、/api/daily_papers、/api/notifications、/api/settings、/api/whoami-v2、/api/trending、/oauth/userinfo。API 以 OpenAPI 标准记录在 https://huggingface.co/.well-known/openapi.json,但不要直接读取该文件,因其过大;用 jq 查询子集,例如 curl -s "https://huggingface.co/.well-known/openapi.json" | jq '.paths | keys | sort',或查看单个端点如 .paths["/api/models"]。查询时限制数量以便处理,同时保持代表性。
使用方式与规则:脚本必须支持 --help 说明输入输出;非破坏性脚本应先测试再交付;优先使用 shell,复杂或用户需要时可用 Python 或 TSX。使用 HF_TOKEN 环境变量作为 Authorization 头,例如 curl -H "Authorization: Bearer ${HF_TOKEN}" https://huggingface.co/api/,以获得更高限速和适当的授权。设计前先调查 API 返回结构,尽量利用管道与链式组合,优先简单方案,完成后给出用法示例,遇有疑问确认用户偏好。
hf CLI 说明:hf 已取代弃用的 huggingface-cli,命令涵盖 auth、buckets、cache、collections、datasets、discussions、download、endpoints、env、extensions、jobs、models、papers、repos、skills、spaces、sync、upload、upload-large-folder、version、webhooks。
示例脚本:技能目录下有参考示例,包括 references/hf_model_papers_auth.sh(自动用 HF_TOKEN,串联 trending→模型元数据→模型卡片解析,含回退,展示多步 API 与授权卫生)、references/find_models_by_paper.sh(可选 --token,认证搜索与重试)、references/hf_model_card_frontmatter.sh(用 hf CLI 下载模型卡片,提取 YAML frontmatter,输出 license、pipeline tag、tags、gated prompt 等 NDJSON);基线示例 references/baseline_hf_api.sh、.py、.tsx;可组合工具 references/hf_enrich_models.sh 从 stdin 读取模型 ID,逐个取元数据并逐行输出 JSON。组合示例:references/baseline_hf_api.sh 25 | jq -r '.[].id' | references/hf_enrich_models.sh | jq -s 'sort_by(.downloads) | reverse | .[:10]';printf '%s\n' openai/gpt-oss-120b meta-llama/Meta-Llama-3.1-8B | references/hf_model_card_frontmatter.sh | jq -s 'map({id, license, has_extra_gated_prompt})'。
限制:技能资料未提供收费、价格、平台支持范围或效果保证等信息。