コンテンツにスキップ

HuggingFace

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 のようになります。

リクエスト
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
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);