El nuevo SDK de IA generativa de Google proporciona una interfaz unificada a Gemini 2.0 a través de la API para desarrolladores de Gemini y Vertex AI (la API de Gemini Enterprise). Con algunas excepciones, el código que se ejecuta en una plataforma se ejecutará en ambas. El SDK de Gen AI también admite los modelos Gemini 1.5.
Python
El SDK de Google Gen AI para Python está disponible en PyPI y GitHub.
Para obtener más información, consulta la referencia del SDK de Python.
Guía de inicio rápido
1. Instala el SDK
pip install google-genai
2. Importa la biblioteca
from google import genai
3. Crea un cliente
client = genai.Client(api_key='GEMINI_API_KEY')
4. Genera contenido
response = client.models.generate_content(
model='gemini-2.0-flash', contents='How does RLHF work?'
)
print(response.text)
Go
El SDK de IA generativa de Google para Go está disponible en go.dev y GitHub.
Guía de inicio rápido
1. Importa la biblioteca
import "google.golang.org/genai"
2. Crea un cliente
client, err := genai.NewClient(ctx, &genai.ClientConfig{
APIKey: apiKey,
Backend: genai.BackendGeminiAPI,
})
3. Genera contenido
// Call the GenerateContent method
result, err := client.Models.GenerateContent(ctx, "gemini-2.0-flash", genai.Text("How does RLHF work?"), nil)
Java
El SDK de Google Gen AI para Java está disponible a través de Maven y GitHub.
Guía de inicio rápido
1. Importa la biblioteca
Si usas Maven, agrega lo siguiente a tus dependencias:
<dependencies>
<dependency>
<groupId>com.google.genai</groupId>
<artifactId>google-genai</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
2. Crea un 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. Genera contenido
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());
}
}