vertex-ai-gemini

在 Google Cloud 上的 Vertex AI 企业级 Gemini 部署与 MLOps。适用于在 GCP 原生环境中部署 Gemini、运行微调任务、需要企业级 IAM 控制、VPC 隔离、大规模批量预测或构建生产级机器学习流水线的场景。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "vertex-ai-gemini":https://skillpi.com/zh/skills/deepskill-e6166404268d89ae3c7f7fa2d9b84d1389f358166447a4ac29778c113a484ccb。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

在 Google Cloud 上的 Vertex AI 企业级 Gemini 部署与 MLOps。适用于在 GCP 原生环境中部署 Gemini、运行微调任务、需要企业级 IAM 控制、VPC 隔离、大规模批量预测或构建生产级机器学习流水线的场景。

0 下载

介绍来源: third_party · TerminalSkills · 1.1.0 参考来源

SkillPi 解读

软件、账号及付费要求
贝什
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: vertex-ai-gemini
description: >-
  Google Cloud Vertex AI for enterprise Gemini deployments — production scaling,
  fine-tuning, and MLOps. Use when deploying Gemini in GCP-native environments,
  running fine-tuning jobs, needing enterprise IAM controls, VPC isolation,
  batch prediction at scale, or production ML pipelines on Google Cloud.
license: Apache-2.0
compatibility: "Python 3.9+ with google-cloud-aiplatform SDK and GCP credentials"
metadata:
  author: terminal-skills
  version: "1.1.0"
  category: data-ai
  tags: ["vertex-ai", "google-cloud", "gemini", "enterprise", "mlops"]
  use-cases:
    - "Deploy Gemini with enterprise IAM, VPC controls, and compliance requirements"
    - "Fine-tune Gemini on proprietary data for domain-specific use cases"
    - "Run batch predictions on millions of records with managed infrastructure"
  agents: [claude-code, openai-codex, gemini-cli, cursor]

Vertex AI — Gemini on Google Cloud

Overview

Vertex AI is Google Cloud's enterprise ML platform. It provides access to the same Gemini models as Google AI Studio, but with enterprise-grade features: IAM-based auth (no API keys), VPC Service Controls for data isolation, audit logging, fine-tuning capabilities, batch prediction jobs, and integration with GCP data services like BigQuery and Cloud Storage.

Vertex AI vs Google AI Studio

Feature Google AI Studio Vertex AI
Auth API Key Service Account / IAM
Data residency Limited GCP regions
VPC isolation ❌ ✅
Audit logging ❌ ✅ Cloud Audit Logs
Fine-tuning ❌ ✅
Batch prediction ❌ ✅
Pricing Per token Per token (different rates)
Quotas Shared Project-level quotas

Naming note: "Vertex AI" is being rebranded to Agent Platform (full name: Gemini Enterprise Agent Platform). The endpoints, IAM roles, and SDKs are the same product — most documentation still uses the legacy "Vertex AI" name.

SDK Choice — Use the Unified Gen AI SDK

Google now ships a single google-genai SDK that targets both Agent Platform (Vertex) and Google AI Studio with the same code. Use this for all new code. The legacy google-cloud-aiplatform and vertexai modules are deprecated.

New (use this) Legacy (deprecated)
google-genai (Python) google-cloud-aiplatform, google-generativeai
@google/genai (JS/TS) @google-cloud/vertexai
google.golang.org/genai (Go) cloud.google.com/go/vertexai
com.google.genai:google-genai (Java) —
Google.GenAI (.NET) —
# Recommended: unified Gen AI SDK
pip install google-genai
import os
from google import genai

os.environ["GOOGLE_CLOUD_PROJECT"] = "my-project-id"
os.environ["GOOGLE_CLOUD_LOCATION"] = "global"  # routes to nearest region
os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = "true"

client = genai.Client()  # picks up env vars

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="Explain containerization in simple terms.",
)
print(response.text)

Use location="global" by default — routes to the region with available capacity. Pin to a specific region (us-central1, europe-west4) only when data residency requires it.

Setup (Legacy SDK — only for existing code)

pip install google-cloud-aiplatform
# Authenticate
gcloud auth application-default login

# Or use service account
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
# Set project and location
export GOOGLE_CLOUD_PROJECT=my-project-id
export GOOGLE_CLOUD_LOCATION=us-central1

Instructions

The examples below use the legacy google-cloud-aiplatform SDK. For new code, prefer the unified google-genai SDK shown above — same capabilities, cross-platform, current best practice.

Basic Gemini Inference

import vertexai
from vertexai.generative_models import GenerativeModel

vertexai.init(project="my-project-id", location="us-central1")

model = GenerativeModel("gemini-2.0-flash-001")
response = model.generate_content("Explain containerization in simple terms.")
print(response.text)

Multi-Modal Inference

import vertexai
from vertexai.generative_models import GenerativeModel, Part
import base64

vertexai.init(project="my-project-id", location="us-central1")
model = GenerativeModel("gemini-2.0-flash-001")

# Analyze image from Cloud Storage
gcs_image = Part.from_uri(
    uri="gs://my-bucket/product-photo.jpg",
    mime_type="image/jpeg",
)
response = model.generate_content(["Describe this product:", gcs_image])
print(response.text)

# Analyze local image
with open("chart.png", "rb") as f:
    image_data = f.read()

local_image = Part.from_data(data=image_data, mime_type="image/png")
response = model.generate_content(["What trends does this chart show?", local_image])
print(response.text)

Streaming Responses

import vertexai
from vertexai.generative_models import GenerativeModel

vertexai.init(project="my-project-id", location="us-central1")
model = GenerativeModel("gemini-2.0-flash-001")

for chunk in model.generate_content("Write a product description for a smartwatch.", stream=True):
    print(chunk.text, end="", flush=True)
print()

Chat Session

import vertexai
from vertexai.generative_models import GenerativeModel, ChatSession

vertexai.init(project="my-project-id", location="us-central1")

model = GenerativeModel(
    model_name="gemini-2.0-flash-001",
    system_instruction="You are a GCP expert. Provide concise, actionable answers.",
)

chat = model.start_chat()
print(chat.send_message("How do I set up Cloud Run?").text)
print(chat.send_message("What about environment variables?").text)

Function Calling

import vertexai
from vertexai.generative_models import (
    FunctionDeclaration,
    GenerativeModel,
    Tool,
)

vertexai.init(project="my-project-id", location="us-central1")

get_bq_query = FunctionDeclaration(
    name="run_bigquery_query",
    description="Run a SQL query on BigQuery and return results",
    parameters={
        "type": "object",
        "properties": {
            "query": {"type": "string", "description": "SQL query to execute"},
            "dataset": {"type": "string", "description": "BigQuery dataset name"},
        },
        "required": ["query"],
    },
)

tool = Tool(function_declarations=[get_bq_query])
model = GenerativeModel("gemini-2.0-flash-001", tools=[tool])

response = model.generate_content("How many users signed up last week?")

if response.candidates[0].function_calls:
    fc = response.candidates[0].function_calls[0]
    print(f"Function: {fc.name}, Args: {dict(fc.args)}")

Fine-Tuning Gemini

import vertexai
from vertexai.tuning import sft

vertexai.init(project="my-project-id", location="us-central1")

# Prepare training data in JSONL format in GCS:
# {"messages": [{"role": "user", "content": "..."}, {"role": "model", "content": "..."}]}

tuning_job = sft.train(
    source_model="gemini-2.0-flash-001",
    train_dataset="gs://my-bucket/training-data.jsonl",
    validation_dataset="gs://my-bucket/validation-data.jsonl",
    tuned_model_display_name="my-fine-tuned-gemini",
    epochs=3,
    learning_rate_multiplier=1.0,
)

print(f"Tuning job: {tuning_job.resource_name}")
print(f"State: {tuning_job.state}")

# Wait for completion
tuning_job.wait()
print(f"Tuned model: {tuning_job.tuned_model_name}")

Batch Prediction

import vertexai
from vertexai.generative_models import GenerativeModel
from vertexai.preview.batch_prediction import BatchPredictionJob

vertexai.init(project="my-project-id", location="us-central1")

# Input JSONL format in GCS:
# {"request": {"contents": [{"role": "user", "parts": [{"text": "Translate: Hello"}]}]}}

job = BatchPredictionJob.submit(
    source_model="gemini-2.0-flash-001",
    input_dataset="gs://my-bucket/batch-inputs.jsonl",
    output_uri_prefix="gs://my-bucket/batch-outputs/",
)

print(f"Batch job: {job.resource_name}")
job.wait()
print(f"Output: {job.output_location}")

IAM Setup for Service Account

# Create a service account for your app
gcloud iam service-accounts create gemini-app-sa \
    --display-name="Gemini App Service Account"

# Grant Vertex AI User role
gcloud projects add-iam-policy-binding my-project-id \
    --member="serviceAccount:gemini-app-sa@my-project-id.iam.gserviceaccount.com" \
    --role="roles/aiplatform.user"

# Download key (for non-GCP environments)
gcloud iam service-accounts keys create key.json \
    --iam-account=gemini-app-sa@my-project-id.iam.gserviceaccount.com

VPC Service Controls (Enterprise Isolation)

# When VPC SC is enabled, all API calls must originate from within the perimeter
# Configure the SDK to use private endpoints:

import vertexai

vertexai.init(
    project="my-project-id",
    location="us-central1",
    api_endpoint="us-central1-aiplatform.googleapis.com",  # Regional endpoint
)

Available Gemini Models on Vertex AI

Model ID Notes
gemini-2.0-flash-001 Latest Flash, fast + capable
gemini-1.5-pro-002 2M context, most capable
gemini-1.5-flash-002 1M context, balanced
text-embedding-005 Latest embeddings (768 dims)

Use gemini-2.0-flash-001 (version pinned) in production to avoid unexpected model changes.

Examples

Example 1 — Migrate a Python service from google-cloud-aiplatform to google-genai

User has a recommendation service running on Cloud Run that uses the legacy google-cloud-aiplatform SDK. Replace pip install google-cloud-aiplatform with pip install google-genai, swap vertexai.init(...) + GenerativeModel(...) for genai.Client() (with GOOGLE_GENAI_USE_VERTEXAI=true), update model.generate_content(...) to client.models.generate_content(model=..., contents=...). Keep the existing service account and IAM bindings — same auth, new SDK. Pin to gemini-2.5-flash for cost, validate parity in staging before cutover.

Example 2 — Run nightly batch translation of 5M product titles

User has 5M product titles in BigQuery to translate into 4 languages. Streaming inference would be slow and expensive. Format input as JSONL in GCS ({"request": {"contents": [...]}}) per row × language, submit a BatchPredictionJob against gemini-2.5-flash, and let it run unattended. Output JSONL lands in GCS, load it back into BigQuery via bq load. Cost is roughly half of streaming, runtime is hours not days.

Guidelines

  • Use google-genai for all new code — google-cloud-aiplatform and google-generativeai are deprecated.
  • Always pin model versions in production for stability — gemini-2.5-flash is fine for non-prod, but production should target a specific build.
  • Use Application Default Credentials (gcloud auth application-default login) during development.
  • In GKE or Cloud Run, use Workload Identity — no service account keys needed.
  • Default location="global" for the Gen AI SDK; pin to a region only for data residency.
  • Fine-tuning requires a training JSONL with messages format and at least 100 examples.
  • Batch prediction is cost-effective for offline bulk inference (no streaming).
  • Enable Cloud Audit Logs on the aiplatform.googleapis.com service for compliance.

当前收录版本

1.1.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值95/100

亮点

  • 针对企业级GCP生产环境部署Gemini模型,解决IAM控制、VPC隔离、批量预测等核心痛点
  • 提供从开发到生产的完整MLOps流水线指导,具有明确的高频刚需场景
触发精准90/100

亮点

  • 触发词覆盖全面,包含'vertex-ai'、'google-cloud'、'gemini'、'enterprise'、'mlops'等关键词
  • description清晰界定适用边界,避免与其他AI工具混淆
结构规范90/100

亮点

  • 文档结构完整,包含Overview、SDK选择、Setup、Instructions、Examples、Guidelines等标准章节
  • 提供端到端示例,涵盖基础推理、多模态、流式响应、聊天会话、函数调用、微调、批量预测等完整场景
执行可靠90/100

亮点

  • 工具来源明确,推荐使用统一的google-genai SDK,避免依赖冲突
  • 代码示例参数正确,覆盖主要异常处理,提供IAM和VPC配置指导
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 读取本地文件

    限定到你选择的文件或项目目录;避免读取无关的个人资料、密钥和配置文件。

    主文档提及 · 第 135 行
  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 57, 82, 308 行
  • 账号、密钥或授权

    使用专用、最小权限账号,不把密钥粘贴到公开内容或命令日志;核对接收数据的服务与租户。

    主文档提及 · 第 9, 32, 318 行
  • 云资源与可能的费用

    先预览变更,核对账号、区域、资源权限与费用;创建、部署或删除前单独确认。

    主文档提及 · 第 265, 274 行

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

贝什

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。