원클릭으로
vertexai-gemini-batch
Generate batch input and run Vertex AI Batch Prediction for Gemini via google-genai SDK.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Generate batch input and run Vertex AI Batch Prediction for Gemini via google-genai SDK.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Ask OpenAI Codex CLI for an autonomous second AI opinion. "ask codex", "codex と相談" などで起動。
Request GitHub Copilot review on a Pull Request. "PR レビュー依頼", "copilot review" などで起動。
Extract VTT transcript from a Zoom recording share page. "zoom transcript", "zoom 文字起こし" などで起動。
Download the video (MP4) from a Zoom recording share page. "zoom video download", "zoom 録画 ダウンロード", "zoom 動画 ダウンロード" などで起動。
Round-trip code review through difit. Use when the user mentions "difit", "diff review", "open the diff", "let me look at this", or "review this PR locally". Launch mode arg — "open" (default, no comments at launch), "explain" (AI annotates its own change), "review" (AI posts findings on human code).
Stop tool execution before exhausting your Claude usage — set a 5h/7d usage-% or per-session cost threshold.
| name | vertexai-gemini-batch |
| description | Generate batch input and run Vertex AI Batch Prediction for Gemini via google-genai SDK. |
| allowed-tools | Bash, Read, Edit, Write, Glob, Grep, AskUserQuestion |
| user-invocable | true |
google-genai SDK を使用して Vertex AI 経由で Gemini のバッチ処理を実行するための支援を行います。
| 項目 | 内容 |
|---|---|
| SDK | google-genai (vertexai=True) |
| 認証 | Google Cloud ADC / サービスアカウント |
| 入力ソース | GCS / BigQuery |
| 出力先 | GCS / BigQuery (指定可) |
| コスト | 標準 API の 50% OFF |
| 処理時間 | 最大 24 時間 (通常はそれより早い) |
ユーザに以下の情報を確認する:
必須情報:
gs://bucket-name/batch-workspace/)推論内容:
その他の設定 (モデル、リージョン、generation_config) はスクリプトの引数やコード内で指定する
各行が 1 リクエスト。request フィールドに GenerateContentRequest 相当の構造を記述:
{"key": "req-1", "request": {"contents": [{"role": "user", "parts": [{"text": "質問1"}]}]}}
{"key": "req-2", "request": {"contents": [{"role": "user", "parts": [{"text": "質問2"}]}], "generation_config": {"temperature": 0.7}}}
key フィールド (推奨): 各リクエストに一意の識別子を付与できる。出力にも同じ key が含まれるため、入出力の対応付けが容易になる。バッチ処理では出力順序が入力順序と異なる場合があるため、key の使用を推奨。
{
"key": "summarize-001",
"request": {
"contents": [
{
"role": "user",
"parts": [{"text": "この文章を要約してください: ..."}]
}
],
"generation_config": {
"temperature": 0.7,
"max_output_tokens": 1024,
"top_p": 0.95,
"top_k": 40,
"response_mime_type": "application/json",
"response_schema": {
"type": "object",
"properties": {
"summary": {"type": "string"},
"key_points": {
"type": "array",
"items": {"type": "string"}
}
},
"required": ["summary", "key_points"]
}
},
"safety_settings": [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
}
],
"system_instruction": {
"parts": [{"text": "あなたは要約の専門家です。"}]
}
}
}
| フィールド | 型 | 説明 |
|---|---|---|
contents | array | 必須。会話履歴。各要素は role と parts を持つ |
contents[].role | string | "user" または "model" |
contents[].parts | array | メッセージのパーツ。text, inline_data など |
generation_config | object | 生成パラメータ |
system_instruction | object | システムプロンプト |
safety_settings | array | 安全性設定 |
| フィールド | 型 | デフォルト | 説明 |
|---|---|---|---|
temperature | number | 1.0 | 生成のランダム性 (0.0-2.0) |
max_output_tokens | integer | モデル依存 | 最大出力トークン数 |
top_p | number | 0.95 | nucleus sampling |
top_k | integer | 40 | top-k sampling |
response_mime_type | string | "text/plain" | "application/json" で JSON 出力を強制 |
response_schema | object | - | JSON Schema 形式で出力構造を定義 |
stop_sequences | array | - | 生成を停止する文字列のリスト |
ユーザの要件に基づいて、JSONL 形式の入力ファイルを生成する Python スクリプトを作成する。
google.genai.types の型を使って構造を保証する:
import json
from google.genai import types
def create_batch_request(key: str, prompt: str, config: types.GenerateContentConfig | None = None) -> dict:
"""バッチリクエスト用の dict を作成"""
content = types.Content(
role="user",
parts=[types.Part(text=prompt)],
)
request: dict = {
"key": key,
"request": {
"contents": [content.to_json_dict()],
},
}
if config:
request["request"]["generation_config"] = config.to_json_dict()
return request
# 使用例
config = types.GenerateContentConfig(
temperature=0.7,
max_output_tokens=1024,
response_mime_type="application/json",
response_schema={
"type": "object",
"properties": {"answer": {"type": "string"}},
"required": ["answer"],
},
)
requests = [
create_batch_request("req-1", "Tell me a joke", config),
create_batch_request("req-2", "Why is the sky blue?", config),
]
# JSONL ファイルに書き出し
with open("batch_input.jsonl", "w") as f:
for req in requests:
f.write(json.dumps(req, ensure_ascii=False) + "\n")
ポイント:
types.Content, types.Part, types.GenerateContentConfig を使って型安全に構築.to_json_dict() で API が期待する形式に変換 (null フィールドを除外)プラグインに同梱の ./scripts/batch.py を使用する。PEP 723 形式で依存関係が記述されており、uv run で直接実行できる。
# 入力ファイルを GCS にアップロード
gcloud storage cp input.jsonl gs://BUCKET/batch-input/
# バッチジョブ作成
uv run ./scripts/batch.py --project PROJECT_ID create \
--input-uri gs://BUCKET/batch-input/input.jsonl \
--output-uri gs://BUCKET/batch-output/ \
--model MODEL_NAME
# ジョブ完了を待機する場合
uv run ./scripts/batch.py --project PROJECT_ID wait --job-name JOB_NAME
# 結果ダウンロード
gcloud storage cp -r gs://BUCKET/batch-output/ ./results/
詳細な使い方は uv run ./scripts/batch.py usage を参照。
注意: gcloud CLI には Batch Prediction ジョブを操作するサブコマンドは存在しない。ジョブの作成・状態確認は Python SDK を使用する
成功時:
{
"key": "req-1",
"status": "",
"processed_time": "2024-01-15T10:30:00Z",
"request": {"contents": [...]},
"response": {
"candidates": [{
"content": {
"parts": [{"text": "生成されたテキスト"}]
},
"finishReason": "STOP"
}],
"usageMetadata": {
"promptTokenCount": 10,
"candidatesTokenCount": 50,
"totalTokenCount": 60
}
}
}
エラー時:
{
"key": "req-2",
"status": "ERROR",
"processed_time": "2024-01-15T10:30:00Z",
"request": {"contents": [...]},
"error": {"code": 400, "message": "Error message"}
}
注意: 出力順序は入力順序と異なる場合がある。key フィールドで入出力を対応付けること。
gcloud auth application-default login または サービスアカウントキーが必要gcloud services enable aiplatform.googleapis.com)global リージョンのみ対応の場合がある| エラーメッセージ | 原因 | 対処法 |
|---|---|---|
The PublisherModel XXX does not exist | モデル名が間違っている、またはリージョンが対応していない | モデル名のスペルを確認し、リージョンを変更する (global など) |
Do not support publisher model XXX | そのリージョンでモデルがサポートされていない | リージョンを global に変更する (新しいモデルの場合) |
Permission denied | GCS バケットへのアクセス権限がない | サービスアカウントに storage.objects.create 権限を付与 |
API not enabled | Vertex AI API が有効化されていない | gcloud services enable aiplatform.googleapis.com を実行 |
global が必要か)# 認証
gcloud auth application-default login
# API 有効化
gcloud services enable aiplatform.googleapis.com --project=PROJECT_ID
注意: スクリプトは PEP 723 形式で依存関係が記述されており、uv run で実行すると自動的にパッケージがインストールされる
不明点がある場合は以下のドキュメントを参照すること: