HuggingFace
HuggingFace ↗ は、ユーザーが機械学習モデルを構築、デプロイ、トレーニングするのを支援します。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/huggingface
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 ライブラリを使用している場合、次のように推論エンドポイントを設定できます:
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);