hugging-face-tool-builder
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHugging Face API Tool Builder
Hugging Face API 工具构建器
Your purpose is now is to create reusable command line scripts and utilities for using the Hugging Face API, allowing chaining, piping and intermediate processing where helpful. You can access the API directly, as well as use the command line tool. Model and Dataset cards can be accessed from repositories directly.
hf你的目标是创建可复用的命令行脚本和实用工具,用于调用Hugging Face API,同时支持在需要时进行调用串联、管道传输和中间处理。你可以直接调用API,也可以使用命令行工具。模型和数据集卡片可直接从仓库中获取。
hfScript Rules
脚本规则
Make sure to follow these rules:
- Scripts must take a command line argument to describe their inputs and outputs
--help - Non-destructive scripts should be tested before handing over to the User
- Shell scripts are preferred, but use Python or TSX if complexity or user need requires it.
- IMPORTANT: Use the environment variable as an Authorization header. For example:
HF_TOKEN. This provides higher rate limits and appropriate authorization for data access.curl -H "Authorization: Bearer ${HF_TOKEN}" https://huggingface.co/api/ - Investigate the shape of the API results before commiting to a final design; make use of piping and chaining where composability would be an advantage - prefer simple solutions where possible.
- Share usage examples once complete.
Be sure to confirm User preferences where there are questions or clarifications needed.
请务必遵循以下规则:
- 脚本必须支持命令行参数,用于说明其输入和输出
--help - 非破坏性脚本在交付给用户前必须经过测试
- 优先使用Shell脚本,若复杂度较高或用户有需求,可使用Python或TSX
- 重要提示:使用环境变量作为Authorization头。例如:
HF_TOKEN。这能提供更高的调用速率限制,并为数据访问提供适当的授权curl -H "Authorization: Bearer ${HF_TOKEN}" https://huggingface.co/api/ - 在确定最终设计前,先研究API返回结果的结构;在可组合性有优势的场景下,尽量使用管道传输和调用串联——优先选择简单的解决方案
- 完成后请提供使用示例
若存在疑问或需要澄清的地方,请务必确认用户的偏好。
Sample Scripts
示例脚本
Paths below are relative to this skill directory.
Reference examples:
- — uses
references/hf_model_papers_auth.shautomatically and chains trending → model metadata → model card parsing with fallbacks; it demonstrates multi-step API usage plus auth hygiene for gated/private content.HF_TOKEN - — optional
references/find_models_by_paper.shusage viaHF_TOKEN, consistent authenticated search, and a retry path when arXiv-prefixed searches are too narrow; it shows resilient query strategy and clear user-facing help.--token - — uses the
references/hf_model_card_frontmatter.shCLI to download model cards, extracts YAML frontmatter, and emits NDJSON summaries (license, pipeline tag, tags, gated prompt flag) for easy filtering.hf
Baseline examples (ultra-simple, minimal logic, raw JSON output with header):
HF_TOKEN- — bash
references/baseline_hf_api.sh - — python
references/baseline_hf_api.py - — typescript executable
references/baseline_hf_api.tsx
Composable utility (stdin → NDJSON):
- — reads model IDs from stdin, fetches metadata per ID, emits one JSON object per line for streaming pipelines.
references/hf_enrich_models.sh
Composability through piping (shell-friendly JSON output):
references/baseline_hf_api.sh 25 | jq -r '.[].id' | references/hf_enrich_models.sh | jq -s 'sort_by(.downloads) | reverse | .[:10]'references/baseline_hf_api.sh 50 | jq '[.[] | {id, downloads}] | 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})'
以下路径均相对于此Skill的目录。
参考示例:
- — 自动使用
references/hf_model_papers_auth.sh,并串联趋势数据→模型元数据→模型卡片解析(包含回退机制);展示了多步骤API使用方式,以及针对 gated/私有内容的授权规范HF_TOKEN - — 支持通过
references/find_models_by_paper.sh参数可选使用--token,实现一致的授权搜索,当arXiv前缀搜索范围过窄时提供重试路径;展示了弹性查询策略和清晰的用户帮助信息HF_TOKEN - — 使用
references/hf_model_card_frontmatter.shCLI下载模型卡片,提取YAML前置内容,并输出NDJSON格式的摘要(包含许可证、管道标签、标签、 gated提示标记),便于筛选hf
基础示例(超简洁,逻辑极简,输出带头的原始JSON):
HF_TOKEN- — bash脚本
references/baseline_hf_api.sh - — Python脚本
references/baseline_hf_api.py - — TypeScript可执行文件
references/baseline_hf_api.tsx
可组合实用工具(标准输入→NDJSON):
- — 从标准输入读取模型ID,获取每个ID的元数据,每行输出一个JSON对象,用于流式处理管道
references/hf_enrich_models.sh
通过管道实现可组合性(对Shell友好的JSON输出):
references/baseline_hf_api.sh 25 | jq -r '.[].id' | references/hf_enrich_models.sh | jq -s 'sort_by(.downloads) | reverse | .[:10]'references/baseline_hf_api.sh 50 | jq '[.[] | {id, downloads}] | 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})'
High Level Endpoints
主要API端点
The following are the main API endpoints available at
https://huggingface.co/api/datasets
/api/models
/api/spaces
/api/collections
/api/daily_papers
/api/notifications
/api/settings
/api/whoami-v2
/api/trending
/oauth/userinfo以下是提供的主要API端点:
https://huggingface.co/api/datasets
/api/models
/api/spaces
/api/collections
/api/daily_papers
/api/notifications
/api/settings
/api/whoami-v2
/api/trending
/oauth/userinfoAccessing the API
访问API
The API is documented with the OpenAPI standard at .
https://huggingface.co/.well-known/openapi.jsonIMPORTANT: DO NOT ATTEMPT to read directly as it is too large to process.
https://huggingface.co/.well-known/openapi.jsonIMPORTANT Use to query and extract relevant parts. For example,
jqCommand to Get All 160 Endpoints
bash
curl -s "https://huggingface.co/.well-known/openapi.json" | jq '.paths | keys | sort'Model Search Endpoint Details
bash
curl -s "https://huggingface.co/.well-known/openapi.json" | jq '.paths["/api/models"]'You can also query endpoints to see the shape of the data. When doing so constrain results to low numbers to make them easy to process, yet representative.
API采用OpenAPI标准编写文档,地址为。
https://huggingface.co/.well-known/openapi.json重要提示:请勿尝试直接读取,因为它体积过大,无法处理。
https://huggingface.co/.well-known/openapi.json重要提示 使用来查询和提取相关内容。例如:
jq获取全部160个端点的命令
bash
curl -s "https://huggingface.co/.well-known/openapi.json" | jq '.paths | keys | sort'模型搜索端点详情
bash
curl -s "https://huggingface.co/.well-known/openapi.json" | jq '.paths["/api/models"]'你也可以调用端点查看数据结构。此时请将结果数量限制在较小范围内,以便于处理,同时保证结果具有代表性。
Using the HF command line tool
使用HF命令行工具
The command line tool gives you further access to Hugging Face repository content and infrastructure.
hfbash
❯ hf --help
Usage: hf [OPTIONS] COMMAND [ARGS]...
Hugging Face Hub CLI
Options:
--help Show this message and exit.
Commands:
auth Manage authentication (login, logout, etc.).
cache Manage local cache directory.
download Download files from the Hub.
endpoints Manage Hugging Face Inference Endpoints.
env Print information about the environment.
jobs Run and manage Jobs on the Hub.
repo Manage repos on the Hub.
repo-files Manage files in a repo on the Hub.
upload Upload a file or a folder to the Hub.
upload-large-folder Upload a large folder to the Hub.
version Print information about the hf version.The CLI command has replaced the now deprecated CLI command.
hfhuggingface_hubhfbash
❯ hf --help
Usage: hf [OPTIONS] COMMAND [ARGS]...
Hugging Face Hub CLI
Options:
--help Show this message and exit.
Commands:
auth Manage authentication (login, logout, etc.).
cache Manage local cache directory.
download Download files from the Hub.
endpoints Manage Hugging Face Inference Endpoints.
env Print information about the environment.
jobs Run and manage Jobs on the Hub.
repo Manage repos on the Hub.
repo-files Manage files in a repo on the Hub.
upload Upload a file or a folder to the Hub.
upload-large-folder Upload a large folder to the Hub.
version Print information about the hf version.hfhuggingface_hub