مقارنة بين Gemini Developer API وVertex AI

عند تطوير حلول الذكاء الاصطناعي التوليدي باستخدام Gemini، تقدّم Google منتجَي واجهة برمجة تطبيقات: Gemini Developer API وVertex AI Gemini API.

توفّر Gemini Developer API أسرع مسار لإنشاء تطبيقات مستندة إلى Gemini وطرحها و توسيع نطاقها. على معظم المطوّرين استخدام واجهة برمجة التطبيقات المخصّصة للمطوّرين في Gemini ما لم تكن هناك حاجة إلى عناصر تحكّم محدّدة في المؤسسة.

توفّر Vertex AI منظومة متكاملة من الميزات والخدمات المتوافقة مع المؤسسات لإنشاء تطبيقات الذكاء الاصطناعي التوليدي ونشرها، وهي مدعومة بمنصّة Google Cloud.

لقد سهّلنا مؤخرًا نقل البيانات بين هاتين الخدمتَين. يمكن الآن الوصول إلى كلّ من واجهة برمجة التطبيقات Gemini Developer API وواجهة برمجة التطبيقات Vertex AI Gemini API من خلال حزمة تطوير البرامج (SDK) الموحدة لتكنولوجيات الذكاء الاصطناعي التوليدي من Google.

مقارنة الرموز

تتضمّن هذه الصفحة مقارنات بين الرموز البرمجية جنبًا إلى جنب بين 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 library. اطّلِع على صفحة المكتبات للحصول على تعليمات حول كيفية تثبيت @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();

انتقال

يمكنك الوصول إلى كلّ من Gemini Developer API وخدمات Vertex AI من خلال google.golang.org/genai library. اطّلِع على صفحة المكتبات للحصول على تعليمات حول كيفية تثبيت 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 للمنصات وحالات الاستخدام الأخرى.

اعتبارات متعلقة بنقل البيانات

عند نقل البيانات:

إذا لم تعُد بحاجة إلى استخدام مفتاح Gemini API لواجهة Gemini Developer API، اتّبِع أفضل الممارسات المتعلقة بالأمان واحذِف المفتاح.

لحذف مفتاح واجهة برمجة التطبيقات، اتّبِع الخطوات التالية:

  1. افتح صفحة بيانات اعتماد Google Cloud API.

  2. ابحث عن مفتاح واجهة برمجة التطبيقات الذي تريد حذفه وانقر على رمز الإجراءات.

  3. انقر على حذف مفتاح واجهة برمجة التطبيقات.

  4. في النافذة المنبثقة حذف بيانات الاعتماد، انقر على حذف.

    يستغرق حذف مفتاح واجهة برمجة التطبيقات بضع دقائق ليتم نشره. بعد اكتمال عملية النشر، يتم رفض أيّ زيارات تستخدم مفتاح واجهة برمجة التطبيقات المحذوف.

الخطوات التالية