Menggunakan model terbuka menggunakan Model as a Service (MaaS)

Dokumen ini menjelaskan cara menggunakan model terbuka melalui Model sebagai Layanan (MaaS) di Vertex AI. MaaS menyediakan akses tanpa server ke model partner dan open source tertentu, sehingga Anda tidak perlu menyediakan atau mengelola infrastruktur.

Model Garden adalah library terpusat model AI dan ML dari Google, Partner Google, dan model terbuka (open-weight dan open-source), termasuk model MaaS. Model Garden menyediakan beberapa cara untuk men-deploy model yang tersedia di Vertex AI, termasuk model dari Hugging Face.

Untuk mengetahui informasi selengkapnya tentang MaaS, lihat dokumentasi model partner.

Sebelum memulai

Untuk menggunakan model MaaS, Anda harus mengaktifkan Vertex AI API di Google Cloud project Anda.

gcloud services enable aiplatform.googleapis.com

Mengaktifkan API model

Sebelum dapat menggunakan model MaaS, Anda harus mengaktifkan API-nya. Untuk melakukannya, buka halaman model di Model Garden. Beberapa model yang tersedia melalui MaaS juga tersedia untuk deployment mandiri. Kartu model Model Garden untuk kedua penawaran ini berbeda. Kartu model MaaS menyertakan API Service dalam namanya.

Memanggil model menggunakan Google Gen AI SDK for Python

Contoh berikut memanggil model Llama 3.3 menggunakan Google Gen AI SDK for Python.

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}")

Langkah berikutnya