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 모델에서 동일합니다. 자세한 내용은 Python용 Vertex AI SDK 소개를 참고하세요.

다음은 Python용 Vertex AI SDK를 설치하는 짧은 코드 샘플입니다.

# 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)로 바꿉니다.

생성형 AI SDK

Gen AI SDK를 사용하는 경우 설정 프로세스는 1.0 모델과 1.5/2.0 모델 간에 다릅니다. 자세한 내용은 Google Gen AI SDK를 참고하세요.

다음은 Python용 Gen AI SDK를 설치하는 짧은 코드 샘플입니다.

# 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 코드와 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)

생성형 AI SDK

다음 각 코드 샘플 쌍에는 Gemini 1.5 코드와 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)