במאמר הזה מוסבר איך להשתמש במודלים פתוחים באמצעות מודל כשירות (MaaS) ב-Gemini Enterprise Agent Platform. MaaS מספק גישה ללא שרת למודלים נבחרים של שותפים ושל קוד פתוח, בלי צורך להקצות או לנהל תשתית.
Gemini Enterprise Agent Platform Model Garden היא ספרייה מרכזית של מודלים של AI ו-ML מ-Google, מ-Google Partners ומודלים פתוחים (משקלים פתוחים וקוד פתוח), כולל מודלים של 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}")
המאמרים הבאים
- בחירת אפשרות לפרסום מודל פתוח
- פריסת מודלים פתוחים מ-Model Garden
- פריסת מודלים פתוחים באמצעות קונטיינרים מוגדרים מראש
- פריסת מודלים פתוחים באמצעות קונטיינר vLLM בהתאמה אישית