HuggingFace ↗ は、機械学習モデルの構築、デプロイ、学習を支援します。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/huggingfaceHuggingFace 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 のアカウント ID
- AI Gateway のゲートウェイ名
- 有効な 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);