Google Cloud에서 Gemini로 빌드

Gemini를 처음 사용하는 경우 빠른 시작을 사용하는 것이 가장 빠른 시작 방법입니다.

그렇지만 생성형 AI 솔루션이 발전함에 따라 생성형 AI 애플리케이션과 솔루션을 엔드 투 엔드로 빌드하고 배포하는 플랫폼이 필요할 수 있습니다. Google Cloud는 앱 개발 초기 단계에서 앱 배포, 앱 호스팅, 복잡한 데이터 관리에 이르기까지 개발자가 생성형 AI의 강력한 기능을 활용할 수 있도록 포괄적인 도구 생태계를 제공합니다.

Google Cloud의 Vertex AI 플랫폼은 효율성과 안정성을 위해 AI 모델의 사용, 배포, 모니터링을 간소화하는 MLOps 도구 모음을 제공합니다. 또한 데이터베이스, DevOps 도구, 로깅, 모니터링, IAM과 통합하는 경우 생성형 AI 전체 수명 주기 관리에 대한 종합적인 접근이 가능합니다.

다음 표에는 사용 사례에 적합한 옵션을 결정하는 데 도움이 되도록 Google AI와 Vertex AI의 주요 차이점이 요약되어 있습니다.

기능 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를 지원합니다.
무료 등급 신규 사용자의 경우 Google Cloud 크레딧 $300
할당량(분당 요청) 60(증가를 요청할 수 있음) 요청 시 증가(기본값: 60)
엔터프라이즈 지원 아니요 고객 암호화 키
Virtual Private Cloud
데이터 상주
액세스 투명성
애플리케이션 호스팅을 위한 확장 가능한 인프라
데이터베이스 및 데이터 스토리지
MLOps 아니요 완전한 Vertex AI 기반 MLOps(예: 모델 평가, 모델 모니터링, Model Registry)

Google Cloud에서 생성형 AI 애플리케이션을 빌드하는 데 가장 적합한 제품, 프레임워크, 도구를 알아보려면 Google Cloud에서 생성형 AI 애플리케이션 빌드를 참조하세요.

Google AI 기반 Gemini에서 Vertex AI로 이전

애플리케이션에서 Google AI Gemini API를 사용하는 경우 Google Cloud의 Vertex AI Gemini API로 마이그레이션해야 합니다.

이전하는 경우:

Python: Google AI Gemini API에서 Vertex AI Gemini API로 마이그레이션

다음 섹션에서는 Vertex AI Gemini API를 사용하도록 Python 코드를 마이그레이션하는 데 도움이 되는 코드 스니펫을 보여줍니다.

Vertex AI Python SDK 설정

Vertex AI에서는 API 키가 필요하지 않습니다. 대신 Vertex AI의 Gemini는 사용자, 그룹 또는 서비스 계정이 Vertex AI SDK를 통해 Gemini API를 호출할 수 있는 권한을 제어하는 IAM 액세스를 사용하여 관리합니다.

인증하는 방법에는 여러 가지가 있지만 개발 환경에서 인증하는 가장 쉬운 방법은 Google Cloud CLI를 설치한 후 사용자 인증 정보를 사용하여 CLI에 로그인하는 것입니다.

Vertex AI에 추론 호출을 실행하려면 사용자 또는 서비스 계정에 Vertex AI 사용자 역할도 있어야 합니다.

클라이언트를 설치하는 코드 예시

Google AI Vertex AI
# To install the Python SDK, use this CLI command:
# pip install google-generativeai

from google.generativeai import GenerativeModel
from google.colab import userdata

genai.configure(userdata.get('API_KEY'))
        
# To install the Python SDK, use this CLI command:
# pip install google-cloud-aiplatform

import vertexai
from vertexai.generative_models
          import GenerativeModel, Image

PROJECT_ID = ""
REGION = ""  # e.g. us-central1
vertexai.init(project=PROJECT_ID, location=REGION)
        

텍스트 프롬프트에서 텍스트를 생성하는 코드 예시

Google AI Vertex AI
model = GenerativeModel('gemini-1.0-pro')

response = model.generate_content('The opposite of hot is')
print(response.text) #  The opposite of hot is cold.
        
model = GenerativeModel('gemini-1.0-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.Image

multimodal_model = GenerativeModel('gemini-1.0-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-1.0-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-1.0-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-1.0-pro")

chat = model.start_chat()

print(chat.send_message("How are you?").text)
print(chat.send_message("What can you do?").text)
        

사용하지 않는 API 키 삭제

Google AI Gemini API 키를 더 이상 사용할 필요가 없으면 보안 권장사항에 따라 삭제합니다.

다음 단계