เมื่อพัฒนาโซลูชัน Generative AI ด้วย Gemini นักพัฒนาซอฟต์แวร์จะเลือกระหว่าง Gemini Developer API กับ Vertex AI Gemini API
Gemini Developer API ช่วยให้สร้าง ใช้งานจริง และปรับขนาดแอปพลิเคชัน Gemini ได้อย่างง่ายดาย Vertex AI มีระบบนิเวศที่ครอบคลุมของฟีเจอร์และบริการที่พร้อมใช้งานสำหรับองค์กรในการสร้างและทำให้แอปพลิเคชัน Generative AI ใช้งานได้จริง ซึ่งได้รับการสนับสนุนจากแพลตฟอร์ม Google Cloud
แม้ว่าตัวเลือกที่ดีที่สุดจะขึ้นอยู่กับความต้องการของคุณ แต่เราเพิ่งทำให้การเปลี่ยนระหว่างบริการเหล่านี้ง่ายขึ้น ตอนนี้ทั้ง Gemini Developer API และ Vertex AI Gemini API เข้าถึงได้ผ่าน Google Gen AI SDK แบบรวม ซึ่งให้ความยืดหยุ่นมากขึ้น
การเปรียบเทียบโค้ด
ด้านล่างนี้คือตัวอย่างการเปรียบเทียบโค้ดระหว่าง Gemini Developer API กับ การเริ่มต้นใช้งาน Vertex AI อย่างรวดเร็วสําหรับการสร้างข้อความ
Python
คุณสามารถเข้าถึงทั้ง Gemini Developer API และบริการ Vertex AI ผ่านไลบรารี google-genai
ดูวิธีการติดตั้งไลบรารีได้ที่หน้าไลบรารี
Gemini Developer API
from google import genai
client = genai.Client(api_key="YOUR_API_KEY")
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
ดูวิธีการติดตั้งไลบรารีได้ที่หน้าไลบรารี
Gemini Developer API
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: "YOUR_API_KEY" });
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
ดูวิธีการติดตั้งไลบรารีได้ที่หน้าไลบรารี
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, &genai.ClientConfig{
APIKey: apiKey,
Backend: genai.BackendGeminiAPI,
})
// 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)
}
กรณีการใช้งานและแพลตฟอร์มอื่นๆ
โปรดดูคำแนะนำเฉพาะ Use Case ในเอกสารประกอบ API สำหรับนักพัฒนาซอฟต์แวร์ของ Gemini และเอกสารประกอบ Vertex AI สำหรับแพลตฟอร์มและ Use Case อื่นๆ
ข้อควรพิจารณาในการย้ายข้อมูล
สิ่งที่จะเกิดขึ้นเมื่อคุณย้ายข้อมูล
คุณจะต้องตรวจสอบสิทธิ์โดยใช้บัญชีบริการ Google Cloud ดูข้อมูลเพิ่มเติมได้ที่เอกสารประกอบของ Vertex AI
คุณสามารถใช้โปรเจ็กต์ Google Cloud ที่มีอยู่ (โปรเจ็กต์เดียวกับที่ใช้สร้างคีย์ API) หรือสร้างโปรเจ็กต์ Google Cloud ใหม่ก็ได้
ภูมิภาคที่รองรับอาจแตกต่างกันระหว่าง Gemini Developer API กับ Vertex AI Gemini API ดูรายชื่อภูมิภาคที่รองรับ Generative AI ใน Google Cloud
โมเดลที่คุณสร้างใน Google AI Studio ต้องได้รับการฝึกใหม่ใน Vertex AI
หากไม่จําเป็นต้องใช้คีย์ Gemini API สําหรับ Gemini Developer API อีกต่อไป ให้ทําตามแนวทางปฏิบัติแนะนำด้านความปลอดภัยและลบคีย์
วิธีลบคีย์ API
ค้นหาคีย์ API ที่ต้องการลบ แล้วคลิกไอคอนการดําเนินการ
เลือกลบคีย์ API
ในโมดัลลบข้อมูลเข้าสู่ระบบ ให้เลือกลบ
การลบคีย์ API จะใช้เวลาสักครู่จึงจะมีผล หลังจากการนำไปใช้งานเสร็จสมบูรณ์แล้ว ระบบจะปฏิเสธการเข้าชมที่ใช้คีย์ API ที่ลบไปแล้ว
ขั้นตอนถัดไป
- ดูภาพรวม Generative AI ใน Vertex AI เพื่อดูข้อมูลเพิ่มเติมเกี่ยวกับโซลูชัน Generative AI ใน Vertex AI