Google Gen AI SDK

ערכת ה-SDK החדשה של Google Gen AI מספקת ממשק מאוחד ל-Gemini 2.0 דרך Gemini Developer API ו-Vertex AI (Gemini Enterprise API). למעט כמה יוצאים מן הכלל, קוד שפועל בפלטפורמה אחת יפעל בשתיהן. ערכת Gen AI SDK תומכת גם במודלים של Gemini 1.5.

Python

‏Google Gen AI SDK ל-Python זמין ב-PyPI וב-GitHub.

מידע נוסף זמין במסמכי העזרה של Python SDK.

מדריך למתחילים

1. התקנת ה-SDK

pip install google-genai

2. מייבאים את הספרייה

from google import genai

3. יצירת לקוח

client = genai.Client(api_key='GEMINI_API_KEY')

4. יצירת תוכן

response = client.models.generate_content(
    model='gemini-2.0-flash', contents='How does RLHF work?'
)
print(response.text)

Go

ערכת ה-SDK של Google Gen AI ל-Go זמינה ב-go.dev וב-GitHub.

מדריך למתחילים

1. מייבאים את הספרייה

import "google.golang.org/genai"

2. יצירת לקוח

client, err := genai.NewClient(ctx, &genai.ClientConfig{
    APIKey:   apiKey,
    Backend:  genai.BackendGeminiAPI,
})

3. יצירת תוכן

// Call the GenerateContent method
  result, err := client.Models.GenerateContent(ctx, "gemini-2.0-flash", genai.Text("How does RLHF work?"), nil)

Java

ערכת ה-SDK של Google Gen AI ל-Java זמינה דרך Maven ו-GitHub.

מדריך למתחילים

1. מייבאים את הספרייה

אם משתמשים ב-Maven, צריך להוסיף את הקוד הבא ליחסי התלות:

<dependencies>
  <dependency>
    <groupId>com.google.genai</groupId>
    <artifactId>google-genai</artifactId>
    <version>0.1.0</version>
  </dependency>
</dependencies>

2. יצירת לקוח

import com.google.genai.Client;

// The client gets the API key from the environment variable `GOOGLE_API_KEY`
Client client = new Client();

// Use the builder class for instantiation.
Client client = Client.builder().apiKey("your-api-key").build();

3. יצירת תוכן

package <your.pack.name>;

import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;
import java.io.IOException;
import org.apache.http.HttpException;

public class GenerateContentWithTextInput {
  public static void main(String[] args) throws IOException, HttpException {
    Client client = new Client();

    GenerateContentResponse response =
        client.models.generateContent("gemini-2.0-flash-001", "How does RLHF work?", null);
    System.out.println("Unary response: " + response.text());
  }
}