フィードバックを送信
Vertex AI で Gemini 1.5 API から Gemini 2.0 API に移行する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このガイドでは、Gemini 1.0 モデルと Gemini 1.5 モデル(Flash と Pro の両方)から Gemini 2.0 モデルに移行する方法について説明します。
Gemini 1.5 と Gemini 2.0 の違い
Gemini 2.0、1.0、1.5 モデルの違いは次のとおりです。
設定
Vertex AI SDK Vertex AI SDK を再利用する場合、設定プロセスは 1.5 モデルと 2.0 モデルで同じです。詳細については、Vertex AI SDK for Python の概要 をご覧ください。
Vertex AI SDK for Python をインストールする簡単なコードサンプルを次に示します。
# pip install --upgrade --quiet google-cloud-aiplatform
import vertexai
vertexai . init ( project = "PROJECT_ID" , location = "LOCATION" )
PROJECT_ID
は Google Cloud プロジェクト ID に置き換え、LOCATION
は Google Cloud プロジェクトのロケーション(us-central1
など)に置き換えます。
Gen AI SDK Gen AI SDK を使用する場合、設定プロセスは 1.0 モデルと 1.5 および 2.0 モデルで異なります。詳細については、Google Gen AI SDK をご覧ください。
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" )
PROJECT_ID
は Google Cloud プロジェクト ID に置き換え、LOCATION
は Google Cloud プロジェクトのロケーション(us-central1
など)に置き換えます。
2.0 への移行
以降のセクションでは、Vertex AI SDK と新しい Gen AI SDK の両方から Gemini 2.0 に移行する方法について説明します。
Vertex AI SDK
次のコードサンプルの各ペアには、Gemini 1.5 コードと、Gemini 1.5 コードから移行された Gemini 2.0 コードが含まれています。
シンプルなテキスト生成
次のコードサンプルでは、テキスト生成モデルの作成における Gemini 1.5 API と Gemini 2.0 API の違いを示しています。
Gemini 1.5
Gemini 2.0
from vertexai.generative_models import GenerativeModel
model = GenerativeModel ( "gemini-1.5-flash-002" )
response = model . generate_content ( "The opposite of hot is" )
print ( response . text )
from vertexai.generative_models import GenerativeModel
model = GenerativeModel ( "gemini-2.0-flash-001" )
response = model . generate_content ( "The opposite of hot is" )
print ( response . text )
パラメータを使用したテキスト生成
次のコードサンプルでは、テキスト生成モデルの作成における Gemini 1.5 API と Gemini 2.0 API の違いを、オプションのパラメータ とともに示しています。
Gemini 1.5
Gemini 2.0
from vertexai.generative_models import GenerativeModel
model = GenerativeModel ( "gemini-1.5-flash-002" )
prompt = """ You are an expert at solving word problems.Solve the following problem: I have three houses, each with three cats.each cat owns 4 mittens, and a hat. Each mitten was knit from 7m of yarn, each hat from 4m.How much yarn was needed to make all the items? Think about it step by step, and show your work."""
response = model . generate_content ( prompt , generation_config = { "temperature" : 0.1 , "top_p" : 1.0 , "top_k" : 40 , "max_output_tokens" : 800 ,} )
print ( response . text )
from vertexai.generative_models import GenerativeModel
model = GenerativeModel ( "gemini-2.0-flash-001" )
prompt = """ You are an expert at solving word problems.Solve the following problem: I have three houses, each with three cats.each cat owns 4 mittens, and a hat. Each mitten was knit from 7m of yarn, each hat from 4m.How much yarn was needed to make all the items? Think about it step by step, and show your work."""
response = model . generate_content ( prompt , generation_config = { "temperature" : 0.1 , "top_p" : 1.0 , "top_k" : 40 , "max_output_tokens" : 800 ,} )
print ( response . text )
Gen AI SDK
次のコードサンプルの各ペアには、Gemini 1.5 コードと、Gemini 1.5 コードから移行された Gemini 2.0 コードが含まれています。
Gemini 1.5
Gemini 2.0
import vertexai
from vertexai.generative_models import GenerativeModel
vertexai . init ( project = "PROJECT_ID" ,
location = "LOCATION" )
model = GenerativeModel ( "gemini-1.5-flash-002" )
response = model . generate_content ( "The opposite of hot is" )
print ( response . text )
from google import genai
client = genai . Client ( vertexai = True ,
project = 'YOUR_CLOUD_PROJECT' ,
location = 'us-central1' ,
http_options = { 'api_version' : 'v1' })
response = client . models . generate_content (
model = 'gemini-2.0-flash-001' ,
contents = 'The opposite of hot is' )
print ( response . text )
フィードバックを送信
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンス により使用許諾されます。コードサンプルは Apache 2.0 ライセンス により使用許諾されます。詳しくは、Google Developers サイトのポリシー をご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-04-02 UTC。
ご意見をお聞かせください
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-04-02 UTC。"],[],[]]