HuggingFace ↗ 帮助用户构建、部署和训练机器学习模型。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/huggingface
在向 HuggingFace 推理 API 发出请求时,将您当前使用的 URL 中的 https://api-inference.huggingface.co/models/
替换为 https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/huggingface
。请注意,您要访问的模型应该紧跟其后,例如 https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/huggingface/bigcode/starcoder
。
在向 HuggingFace 发出请求时,确保您具有以下内容:
- 您的 AI 网关账户 ID。
- 您的 AI 网关网关名称。
- 一个有效的 HuggingFace API 令牌。
- 您要使用的 HuggingFace 模型的名称。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/huggingface/bigcode/starcoder \ --header 'Authorization: Bearer {hf_api_token}' \ --header 'Content-Type: application/json' \ --data '{ "inputs": "console.log"}'
如果您使用 HuggingFace.js 库,您可以这样设置您的推理端点:
import { HfInferenceEndpoint } from "@huggingface/inference";
const accountId = "{account_id}";const gatewayId = "{gateway_id}";const model = "gpt2";const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/huggingface/${model}`;const apiToken = env.HF_API_TOKEN;
const hf = new HfInferenceEndpoint(baseURL, apiToken);
- @2025 Cloudflare Ubitools
- Cf Repo