Use Google Gemini from Python — Brand New SDK (Code example included!)
Google’s Gemini API introduces a powerful and versatile tool for data scientists and developers to tap into the capabilities of large language models. In this blog post, we’ll explore the Python SDK for the Gemini API and demonstrate its usage through various scenarios, ranging from text-only prompts to multi-turn conversations and multimodal inputs.
Colab Notebook Here: Google Gemini Starter
Prerequisites
Before diving into the exciting world of Gemini, ensure your development environment meets the following requirements:
- Python 3.9+
- Jupyter installed for running notebooks
Setup
Install the Python SDK
Begin by installing the Python SDK for the Gemini API using pip:
pip install -q -U google-generativeai
Import Packages
Import the necessary packages for working with the Gemini API:
import pathlib
import textwrap
import google.generativeai as genai
# Used to securely store your API key
from google.colab import userdata
from IPython.display import display
from IPython.display import Markdown