跳转到内容
搜索文档

HuggingFace

最后更新 查看 MarkdownAgent 设置

HuggingFace 帮助用户构建、部署和训练机器学习模型。

端点

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/huggingface

URL 结构

向 HuggingFace Inference 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 Gateway Account ID。
  • 你的 AI Gateway gateway 名称。
  • 有效的 HuggingFace API 令牌。
  • 要使用的 HuggingFace 模型名称。

示例

cURL

Requestbash
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 库与 JavaScript

如果你使用 HuggingFace.js 库,可以这样设置推理端点:

JavaScriptjs
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);

这篇文档对您有帮助吗?