Vertex AI Gemini API

عند تطوير حلول الذكاء الاصطناعي التوليدي باستخدام Gemini، يختار المطوّرون بين Gemini Developer API وVertex AI Gemini API.

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

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

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

في ما يلي بعض المقارنات بين الرموز البرمجية جنبًا إلى جنب بين Gemini Developer API و عمليات التشغيل السريع لواجهة برمجة تطبيقات Vertex AI لإنشاء النصوص.

Python

يمكنك الوصول إلى كلّ من Gemini Developer API وخدمات Vertex AI من خلال مكتبة google-genai. يُرجى الاطّلاع على صفحة المكتبات للحصول على تعليمات حول كيفية تثبيت المكتبة.

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)
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. يُرجى الاطّلاع على صفحة المكتبات للحصول على تعليمات حول كيفية تثبيت المكتبة.

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();
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. يُرجى الاطّلاع على صفحة المكتبات للحصول على تعليمات حول كيفية تثبيت المكتبة.

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)

}
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. في النافذة المنبثقة حذف بيانات الاعتماد، انقر على حذف.

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

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