This guide shows how to migrate from Gemini 1.0 and Gemini 1.5 models (both Flash and Pro) to Gemini 2.0 models.
Differences between Gemini 1.5 and Gemini 2.0
The following are some differences between Gemini 2.0 and our 1.0 and 1.5 models:
- Only Gemini 1.5 and 2.0 are supported in our new Gen AI SDK. Gemini 1.0 is not supported. This is important because your response structure varies based on what SDK you're using.
- Gemini 2.0 supports Multimodal Live API and multimodal generation.
- Their safety categories are different. To learn about the differences, visit Key differences between Gemini and other model families.
Setup
Vertex AI SDK
If you reuse the Vertex AI SDK , the setup process is the same for our 1.5 and 2.0 models. For more information, see Introduction to the Vertex AI SDK for Python.
The following is a short code sample that installs the Vertex AI SDK for Python:
# pip install --upgrade --quiet google-cloud-aiplatform
import vertexai
vertexai.init(project="PROJECT_ID", location="LOCATION")
Replace PROJECT_ID
with your Google Cloud project ID, and replace
LOCATION
with the location of your Google Cloud project (for example,
us-central1
).
Gen AI SDK
If you choose to use the Gen AI SDK, the setup process is different between the 1.0 and 1.5/2.0 models. For more information, visit Google Gen AI SDKs.
The following is a short code sample that installs the Gen AI SDK for Python:
# pip install --upgrade --quiet google-genai
from google import genai
client = genai.Client(vertexai=True, project="PROJECT_ID", location="LOCATION")
Replace PROJECT_ID
with your Google Cloud project ID, and replace
LOCATION
with the location of your Google Cloud project (for example,
us-central1
).
Migrate to 2.0
The following sections include instructions on how to migrate to Gemini 2.0 from both the Vertex AI SDK and our new Gen AI SDK.
Vertex AI SDK
Each of the following pairs of code samples includes Gemini 1.5 code and Gemini 2.0 code that's been migrated from 1.5 code.
Simple text generation
The following code samples show the differences between the Gemini 1.5 API and Gemini 2.0 API for creating a text generation model:
Gemini 1.5 | Gemini 2.0 |
---|---|
|
|
Text generation with parameters
The following code samples show the differences between the Gemini 1.5 API and Gemini 2.0 API for creating a text generation model, with optional parameters:
Gemini 1.5 | Gemini 2.0 |
---|---|
|
|
Gen AI SDK
Each of the following pairs of code samples includes Gemini 1.5 code and Gemini 2.0 code that's been migrated from 1.5 code:
Gemini 1.5 | Gemini 2.0 |
---|---|
|
|