서비스형 모델 (MaaS)을 사용하여 개방형 모델 사용

이 문서에서는 Vertex AI의 Model as a Service(MaaS)를 통해 개방형 모델을 사용하는 방법을 설명합니다. MaaS는 선택된 파트너 및 오픈소스 모델에 대한 서버리스 액세스를 제공하므로 인프라를 프로비저닝하거나 관리할 필요가 없습니다.

Model Garden은 MaaS 모델을 비롯해 Google, Google 파트너, 오픈 모델 (오픈 웨이트 및 오픈소스)의 AI 및 ML 모델을 중앙 집중식으로 제공하는 라이브러리입니다. Model Garden은 Hugging Face의 모델을 비롯해 Vertex AI에서 사용 가능한 모델을 배포하는 여러 방법을 제공합니다.

MaaS에 관한 자세한 내용은 파트너 모델 문서를 참고하세요.

시작하기 전에

MaaS 모델을 사용하려면Google Cloud 프로젝트에서 Vertex AI API를 사용 설정해야 합니다.

gcloud services enable aiplatform.googleapis.com

모델의 API 사용 설정

MaaS 모델을 사용하려면 먼저 API를 사용 설정해야 합니다. 이렇게 하려면 Model Garden의 모델 페이지로 이동합니다. MaaS를 통해 제공되는 일부 모델은 자체 배포도 가능합니다. 두 제품의 Model Garden 모델 카드는 서로 다릅니다. MaaS 모델 카드에는 이름에 API 서비스가 포함됩니다.

Python용 Google Gen AI SDK를 사용하여 모델 호출

다음 예에서는 Python용 Google 생성형 AI SDK를 사용하여 Llama 3.3 모델을 호출합니다.

from google import genai
from google.genai import types

PROJECT_ID="PROJECT_ID"
LOCATION="LOCATION"
MODEL="meta/llama-3.3-70b-instruct-maas"  # The model ID from Model Garden with "API Service"

# Define the prompt to send to the model.
prompt = "What is the distance between earth and moon?"

# Initialize the Google Gen AI SDK client.
client = genai.Client(
    vertexai=True,
    project=PROJECT_ID,
    location=LOCATION,
)

# Prepare the content for the chat.
contents: types.ContentListUnion = [
    types.Content(
        role="user",
        parts=[
            types.Part.from_text(text=prompt)
        ]
    )
]

# Configure generation parameters.
generate_content_config = types.GenerateContentConfig(
    temperature = 0,
    top_p = 0,
    max_output_tokens = 4096,
)

try:
    # Create a chat instance with the specified model.
    chat = client.chats.create(model=MODEL)
    # Send the message and print the response.
    response = chat.send_message(contents)
    print(response.text)
except Exception as e:
    print(f"{MODEL} call failed due to {e}")

다음 단계