Google AI Studio
ベータGoogle AI Studio ↗は、Google Geminiモデルを使用して迅速に構築するのに役立ちます。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio
Google AI Studioにリクエストを送信する際に必要なものは次のとおりです:
- AI GatewayアカウントID
- AI Gatewayゲートウェイ名
- Google AI Studio APIキー
- Google AI Studioモデル名
新しいベースURLは、上記のデータを使用してこの構造になります:https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio/。
次に、アクセスしたいエンドポイントを追加できます。例えば:v1/models/{model}:{generative_ai_rest_resource}
したがって、最終的なURLは次のようになります:https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio/v1/models/{model}:{generative_ai_rest_resource}。
curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai-studio/v1/models/gemini-1.0-pro:generateContent" \ --header 'content-type: application/json' \ --header 'x-goog-api-key: {google_studio_api_key}' \ --data '{ "contents": [ { "role":"user", "parts": [ {"text":"Cloudflareとは何ですか?"} ] } ] }'@google/generative-aiパッケージを使用している場合、エンドポイントを次のように設定できます:
import { GoogleGenerativeAI } from "@google/generative-ai";
const api_token = env.GOOGLE_AI_STUDIO_TOKEN;const account_id = "";const gateway_name = "";
const genAI = new GoogleGenerativeAI(api_token);const model = genAI.getGenerativeModel( { model: "gemini-1.5-flash" }, { baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`, },);
await model.generateContent(["Cloudflareとは何ですか?"]);