שימוש במודלים פתוחים באמצעות Model as a Service‏ (MaaS)

במסמך הזה מוסבר איך להשתמש במודלים פתוחים באמצעות Model as a Service‏ (MaaS) ב-Gemini Enterprise Agent Platform. ‏MaaS מספק גישה בלי שרתים למודלים נבחרים של שותפים וקוד פתוח, כך שאין צורך להקצות או לנהל תשתית.

Model Garden היא ספרייה מרכזית של מודלים של AI ו-ML מבית Google, משותפי Google וממודלים פתוחים (קוד פתוח ומשקלים פתוחים), כולל מודלים של MaaS. בספרייה Model Garden יש כמה דרכים לפרוס מודלים זמינים ב-Gemini Enterprise Agent Platform, כולל מודלים מ-Hugging Face.

מידע נוסף על MaaS זמין במסמכי התיעוד בנושא מודלים של שותפים.

לפני שמתחילים

כדי להשתמש במודלים של MaaS, צריך להפעיל את Agent Platform API בGoogle Cloud פרויקט.

gcloud services enable aiplatform.googleapis.com

הפעלת ה-API של המודל

כדי להשתמש במודל MaaS, צריך להפעיל את ה-API שלו. כדי לעשות את זה, עוברים לדף של המודל ב-Model Garden. חלק מהמודלים שזמינים דרך MaaS זמינים גם לפריסה עצמית. כרטיסי המודל ב-Model Garden שונים בשני המקרים. כרטיס המודל של MaaS כולל את API Service בשם שלו.

הפעלת המודל באמצעות Google Gen AI SDK ל-Python

בדוגמה הבאה מבוצעת קריאה למודל Llama 3.3 באמצעות Google Gen AI SDK ל-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}")

המאמרים הבאים