Google AI Python SDK for the Gemini API
The Google AI Python SDK offers a straightforward solution for Python developers wanting to utilize the powerful capabilities of the Gemini API. This API grants access to a variety of Gemini models crafted by Google DeepMind. Notably, these models are designed to be multimodal, allowing for seamless integration and analysis across diverse media such as text, images, and code.
Getting Started with the Gemini API
To dive into using the Gemini API, here's a step-by-step guide:
- Head over to the Google AI Studio.
- Log in using your Google account.
- Generate an API key by following the instructions here.
- Explore a Python SDK quickstart in the Gemini API Cookbook.
- For detailed guidance, refer to the Python SDK tutorial available on ai.google.dev.
Usage Example
For complete code samples, the Gemini API Cookbook or ai.google.dev are excellent resources. Here’s a basic usage example to kickstart your project:
-
Installation: Start by installing the SDK from PyPI.
pip install -U google-generativeai
-
Import and Configure: Import the SDK and set up your API key.
import google.generativeai as genai import os genai.configure(api_key=os.environ["GEMINI_API_KEY"])
-
Create a Model and Generate a Prompt: Initialize a model and generate content using prompts.
model = genai.GenerativeModel('gemini-1.5-flash') response = model.generate_content("The opposite of hot is") print(response.text)
Documentation
For comprehensive documentation, refer to the Gemini API Cookbook or visit ai.google.dev.
Contributing
Interested in contributing? Check out the detailed Contributing guide for the Google AI Python SDK.
License
This project's resources are licensed under the Apache License, version 2.0.
This introduction encapsulates an overview of how developers can seamlessly integrate Google's advanced AI models into their projects through the powerful capabilities of the Gemini API.