Vertex AI의 Gemini API를 사용하여 Gemini 1.5에서 Gemini 2.0으로 마이그레이션

이 가이드에서는 Gemini 1.0 및 Gemini 1.5 모델(Flash 및 Pro 모두)에서 Gemini 2.0 모델로 마이그레이션하는 방법을 보여줍니다.

Gemini 1.5 및 Gemini 2.0의 차이점

Gemini 2.0, 1.0, 1.5 모델에는 다음과 같은 몇 가지 차이점이 있습니다.

설정 및 마이그레이션

Gen AI SDK

Gemini 2.0으로 업그레이드할 때 Gen AI SDK로 마이그레이션하는 것이 좋습니다.

행성형 AI SDK를 사용하는 경우 설정 프로세스가 Vertex AI SDK와 다릅니다.

자세한 내용은 Google Gen AI SDK를 참조하세요.

설치

pip install --upgrade google-genai
자세한 내용은 SDK 참고 문서를 참조하세요.

Vertex AI에서 Gen AI SDK를 사용하도록 환경 변수를 설정합니다.

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=us-central1
export GOOGLE_GENAI_USE_VERTEXAI=True

from google import genai
from google.genai.types import HttpOptions

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
    model="gemini-2.0-flash-001",
    contents="How does AI work?",
)
print(response.text)
# Example response:
# Okay, let's break down how AI works. It's a broad field, so I'll focus on the ...
#
# Here's a simplified overview:
# ...

GOOGLE_CLOUD_PROJECT를 Google Cloud 프로젝트 ID로, GOOGLE_CLOUD_LOCATION을 Google Cloud 프로젝트 위치(예: us-central1)로 바꿉니다.

Vertex AI SDK

Vertex AI SDK를 재사용하는 경우 설정 프로세스는 1.0, 1.5, 2.0 모델에서 동일합니다. 자세한 내용은 Python용 Vertex AI SDK 소개를 참조하세요.

SDK를 설치합니다.

pip install --upgrade --quiet google-cloud-aiplatform

다음 샘플은 Vertex AI SDK for Python을 사용하는 쇼트 코드 샘플입니다.

import vertexai
from vertexai.generative_models import GenerativeModel

# TODO(developer): Update and un-comment below line
# PROJECT_ID = "your-project-id"
vertexai.init(project=PROJECT_ID, location="us-central1")

model = GenerativeModel("gemini-1.5-flash-002")

response = model.generate_content(
    "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?"
)

print(response.text)
# Example response:
# **Emphasizing the Dried Aspect:**
# * Everlasting Blooms
# * Dried & Delightful
# * The Petal Preserve
# ...

PROJECT_ID를 Google Cloud 프로젝트 ID로, LOCATION을 Google Cloud 프로젝트 위치(예: us-central1)로 바꿉니다. 그런 다음 모델 ID를 gemini-1.5-flash-002에서 gemini-2.0-flash로 변경합니다.