SDK do Google Gen AI

O novo SDK do Google Gen AI oferece uma interface unificada para o Gemini 2.0 pela API Gemini Developer e pela Vertex AI (API Enterprise do Gemini). Com poucas exceções, o código executado em uma plataforma é executado nas duas. O SDK de IA generativa também oferece suporte aos modelos Gemini 1.5.

Python

O SDK da IA generativa do Google para Python está disponível no PyPI e no GitHub.

Para saber mais, consulte a referência do SDK para Python.

Guia de início rápido

1. Instalar o SDK

pip install google-genai

2. Importar a biblioteca

from google import genai

3. Criar um cliente

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

4. Gerar conteúdo

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

Go

O SDK do Google Gen AI para Go está disponível em go.dev e GitHub.

Guia de início rápido

1. Importar a biblioteca

import "google.golang.org/genai"

2. Criar um cliente

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

3. Gerar conteúdo

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

Java

O SDK do Google Gen AI para Java está disponível no Maven e no GitHub.

Guia de início rápido

1. Importar a biblioteca

Se você estiver usando o Maven, adicione o seguinte às suas dependências:

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

2. Criar um cliente

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. Gerar conteúdo

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());
  }
}