Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/logankilpatrick/gemini-api-quickstart
Get up and running in under 5 minutes with the Google AI Gemini API (in Python)
https://github.com/logankilpatrick/gemini-api-quickstart
ai gemini gemini-api google python
Last synced: 5 days ago
JSON representation
Get up and running in under 5 minutes with the Google AI Gemini API (in Python)
- Host: GitHub
- URL: https://github.com/logankilpatrick/gemini-api-quickstart
- Owner: logankilpatrick
- License: mit
- Created: 2024-05-07T12:38:31.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-09-10T15:35:44.000Z (4 months ago)
- Last Synced: 2024-12-22T01:07:32.933Z (12 days ago)
- Topics: ai, gemini, gemini-api, google, python
- Language: CSS
- Homepage: https://ai.google.dev/gemini-api/docs
- Size: 131 KB
- Stars: 142
- Watchers: 2
- Forks: 26
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gemini API Quickstart - Python
This repository contains a simple Python Flask App running with the Google AI Gemini API, designed to get you started building with Gemini's multi-modal capabilities. The app comes with a basic UI and a Flask backend.
## Basic request
To send your first API request with the [Gemini API Python SDK](https://github.com/google-gemini/generative-ai-python), make sure you have the right dependencies installed (see installation steps below) and then run the following code:
```python
import os
import google.generativeai as genaiGOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=GOOGLE_API_KEY)
model = genai.GenerativeModel('gemini-pro')chat = model.start_chat(history=[])
response = chat.send_message("In one sentence, explain how AI works to a child.")
# Note that the chat object is temporarily stateful, as you send messages and get responses, you can
# see the history changing by doing `chat.history`.print(response.text)
```## Setup
1. If you don’t have Python installed, install it [from Python.org](https://www.python.org/downloads/).
2. [Clone](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) this repository.
3. Create a new virtual environment:
- macOS:
```bash
$ python -m venv venv
$ . venv/bin/activate
```- Windows:
```cmd
> python -m venv venv
> .\venv\Scripts\activate
```- Linux:
```bash
$ python -m venv venv
$ source venv/bin/activate
```4. Install the requirements:
```bash
$ pip install -r requirements.txt
```5. Make a copy of the example environment variables file:
```bash
$ cp .env.example .env
```6. Add your [API key](https://ai.google.dev/gemini-api/docs/api-key) to the newly created `.env` file.
7. Run the app:
```bash
$ flask run
```You should now be able to access the app from your browser at the following URL: [http://localhost:5000](http://localhost:5000)!
#### Attribution
This repo includes code that was forked from [another repo I made](https://github.com/openai/openai-quickstart-python), under an MIT license.