כשמפתחים פתרונות AI גנרטיבי באמצעות Gemini, Google מציעה שני מוצרי API: Gemini Developer API ו-Vertex AI Gemini API.
Gemini Developer API הוא הדרך המהירה ביותר לבנות אפליקציות מבוססות-Gemini, להעביר אותן לייצור ולהרחיב אותן. רוב המפתחים צריכים להשתמש ב-Gemini Developer API, אלא אם יש צורך באמצעי בקרה ספציפיים לארגונים.
Vertex AI מציע מערכת אקולוגית מקיפה של תכונות ושירותים שמוכנים לשימוש בארגונים, לבנייה ולפריסה של אפליקציות AI גנרטיבי שמגובות על ידי Google Cloud Platform.
לאחרונה פישטנו את תהליך המעבר בין השירותים האלה. אפשר לגשת עכשיו גם ל-Gemini Developer API וגם ל-Vertex AI Gemini API דרך Google Gen AI SDK המאוחד.
השוואת קוד
בדף הזה מוצגות השוואות קוד זו לצד זו בין Gemini Developer API לבין מדריכי התחלה מהירה של Vertex AI ליצירת טקסט.
Python
אפשר לגשת גם ל-Gemini Developer API וגם לשירותי Vertex AI דרך ספריית google-genai
. הוראות להתקנת google-genai
מופיעות בדף ספריות.
Gemini Developer API
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.0-flash", contents="Explain how AI works in a few words"
)
print(response.text)
Vertex AI Gemini API
from google import genai
client = genai.Client(
vertexai=True, project='your-project-id', location='us-central1'
)
response = client.models.generate_content(
model="gemini-2.0-flash", contents="Explain how AI works in a few words"
)
print(response.text)
JavaScript ו-TypeScript
אפשר לגשת גם ל-Gemini Developer API וגם לשירותי Vertex AI דרך @google/genai
ספרייה. הוראות להתקנת @google/genai
זמינות בדף ספריות.
Gemini Developer API
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const response = await ai.models.generateContent({
model: "gemini-2.0-flash",
contents: "Explain how AI works in a few words",
});
console.log(response.text);
}
main();
Vertex AI Gemini API
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({
vertexai: true,
project: 'your_project',
location: 'your_location',
});
async function main() {
const response = await ai.models.generateContent({
model: "gemini-2.0-flash",
contents: "Explain how AI works in a few words",
});
console.log(response.text);
}
main();
Go
אפשר לגשת גם ל-Gemini Developer API וגם לשירותי Vertex AI דרך google.golang.org/genai
ספרייה. הוראות להתקנת google.golang.org/genai
זמינות בדף ספריות.
Gemini Developer API
import (
"context"
"encoding/json"
"fmt"
"log"
"google.golang.org/genai"
)
// Your Google API key
const apiKey = "your-api-key"
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
// Call the GenerateContent method.
result, err := client.Models.GenerateContent(ctx, "gemini-2.0-flash", genai.Text("Tell me about New York?"), nil)
}
Vertex AI Gemini API
import (
"context"
"encoding/json"
"fmt"
"log"
"google.golang.org/genai"
)
// Your GCP project
const project = "your-project"
// A GCP location like "us-central1"
const location = "some-gcp-location"
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig
{
Project: project,
Location: location,
Backend: genai.BackendVertexAI,
})
// Call the GenerateContent method.
result, err := client.Models.GenerateContent(ctx, "gemini-2.0-flash", genai.Text("Tell me about New York?"), nil)
}
תרחישי שימוש ופלטפורמות אחרים
במסמכי התיעוד של Gemini Developer API ובמסמכי התיעוד של Vertex AI אפשר למצוא מדריכים ספציפיים לתרחישי שימוש בפלטפורמות אחרות.
שיקולים לגבי העברה
כשמבצעים העברה:
תצטרכו להשתמש בחשבונות שירות של Google Cloud כדי לבצע אימות. מידע נוסף זמין במאמרי העזרה בנושא Vertex AI.
אפשר להשתמש בפרויקט קיים ב-Google Cloud (אותו פרויקט שבו השתמשתם כדי ליצור את מפתח ה-API) או ליצור פרויקט חדש ב-Google Cloud.
יכול להיות שיש הבדלים בין האזורים הנתמכים ב-Gemini Developer API לבין האזורים הנתמכים ב-Vertex AI Gemini API. רשימת האזורים הנתמכים ל-AI גנרטיבי ב-Google Cloud
צריך לאמן מחדש ב-Vertex AI את כל המודלים שיצרתם ב-Google AI Studio.
אם אתם לא צריכים יותר להשתמש במפתח Gemini API עבור Gemini Developer API, מומלץ למחוק אותו בהתאם לשיטות המומלצות לאבטחה.
כדי למחוק מפתח API:
פותחים את הדף Google Cloud API Credentials.
מאתרים את מפתח ה-API שרוצים למחוק ולוחצים על סמל הפעולות.
בוחרים באפשרות מחיקת מפתח API.
בחלון מחיקת פרטי הכניסה, לוחצים על מחיקה.
תהליך המחיקה של מפתח API נמשך כמה דקות. אחרי שההפצה מסתיימת, כל תנועת גולשים שמשתמשת במפתח ה-API שנמחק נדחית.
השלבים הבאים
- בסקירה הכללית על AI גנרטיבי ב-Vertex AI אפשר לקרוא מידע נוסף על פתרונות AI גנרטיבי ב-Vertex AI.