在Google Cloud上运行Gemini
迁移到云端
为什么要迁移到 Cloud
特性 | Google AI Gemini API | Google Cloud Vertex AI Gemini API |
---|---|---|
最新的 Gemini 模型 | Gemini Pro 和 Gemini Ultra | Gemini Pro 和 Gemini Ultra |
注册 | Google 账号 | Google Cloud 账号(含条款协议和结算) |
身份验证 | API 密钥 | Google Cloud 服务帐号 |
界面园地 | Google AI Studio | Vertex AI Studio |
API 和 SDK | Python、Node.js、Android (Kotlin/Java)、Swift、Go | SDK 支持 Python、Node.js、Java、Go |
免费层级 | 是 | 面向新用户的 $300 Google Cloud 赠金 |
配额(每分钟请求数) | 60(可以申请增加) | 应要求增加(默认值:60) |
企业支持服务 | 否 | 数据隐私权承诺 客户加密密钥 虚拟私有云 数据驻留 访问权限透明度 |
MLOps | 否 | Vertex AI 上的完整 MLOps(例如:模型评估、模型监控、模型注册表) |
从 Google AI 上的 Gemini 迁移到 Vertex AI
开始使用 Vertex AI Studio
1.
2.
3.
4.
5.
Python:从 Google AI Gemini API 迁移到 Vertex AI Gemini API
Vertex AI Python SDK 设置
安装客户端的代码示例
Google AI | Vertex AI |
---|---|
pip install google-generativeaifrom google.generativeai import GenerativeModelfrom google.colab import userdatagenai.configure(userdata.get('API_KEY')) | pip install google-cloud-aiplatformimport vertexaifrom google.cloud.aiplatform.private_preview.generative_models i mport GenerativeModel, ImagePROJECT_ID = ""REGION = "" # e.g. us-central1vertexai.init(project=PROJECT_ID, location=REGION) |
根据文本提示生成文本的代码示例
Google AI | Vertex AI |
---|---|
model = GenerativeModel('gemini-pro')response = model.generate_content('The opposite of hot is')print(response.text) # The opposite of hot is cold. | model = GenerativeModel('gemini-pro')response = model.generate_content('The opposite of hot is')print(response.text) # The opposite of hot is cold. |
基于文本和图片生成文本的代码示例
Google AI | Vertex AI |
---|---|
import PIL.Imagemultimodal_model = GenerativeModel('gemini-pro-vision')image = PIL.Image.open('image.jpg')response = multimodal_model.generate_content(['What is this picture?', image])print(response.text) # A cat is shown in this picture. | multimodal_model = GenerativeModel("gemini-pro-vision")image = Image.load_from_file("image.jpg")response = multimodal_model.generate_content(["What is shown in this image?", image])print(response.text) # A cat is shown in this picture. |
生成多轮聊天的代码示例
Google AI | Vertex AI |
---|---|
model = GenerativeModel('gemini-pro')chat = model.start_chat()print(chat.send_message("How are you?").text)print(chat.send_message("What can you do?").text) | model = GenerativeModel("gemini-pro")chat = model.start_chat()print(chat.send_message("How are you?").text)print(chat.send_message("What can you do?").text) |
删除未使用的 API 密钥
后续步骤
修改于 2023-12-25 06:35:41