A Python library to easily build Gemini-powered chatbots and generate images.
Project description
rawa_bots
A Python library to easily build Gemini-powered chatbots and generate images with minimal code.
Features
- Easy Gemini API integration
- Conversational and single-turn modes
- Automatic conversation history
- Custom generation parameters (temperature, top_p, etc.)
- Graceful error handling with custom exceptions
- Image generation support (with save and preview options)
- Ready for PyPI packaging
Installation
pip install rawa_bots
Note: Requires Python 3.8+ and a valid Gemini API key. The
google-genaipackage will be installed automatically.
Usage Example
from rawa_bots import GeminiBot
bot = GeminiBot(
api_key="YOUR_API_KEY",
# model_name is optional; defaults to 'gemini-2.0-flash' for text, 'gemini-2.0-flash-preview-image-generation' for images
system_prompt="You are helpful.",
conversational=True,
allow_image_gen=True # Enable image generation
)
# Text chat
print(bot.ask("Hello!"))
# Image generation (returns URL or file path)
img_path = bot.generate_image(
"A dragon flying over a castle at night",
output_path="dragon.png", # Save to file (optional)
show=True # Open image after saving (optional)
)
print("Image saved to:", img_path)
Image Generation API
allow_image_gen: Set toTrueto enable image generation.generate_image(prompt, n=1, output_path=None, show=False)prompt: The image prompt.n: Number of images to generate.output_path: If set, saves the image(s) to this path (if a directory, images are saved inside it; if a filename, image is saved at that path; if not set, images are saved in the current working directory as 'gemini_image.png', 'gemini_image_1.png', etc.).show: If True, opens the image(s) after saving.- Returns: file path(s) or URL(s) if available.
By default, images are saved in the current working directory as gemini_image.png (or gemini_image_1.png, etc. for multiple images), unless you specify a different path or directory.
Versioning
This library uses a single version number for all files and features. There is no need to specify or manage multiple versions.
Listing Available Models
You can list all available Gemini models with:
from google import genai
client = genai.Client(api_key="YOUR_API_KEY")
print([m.name for m in client.models.list()])
Error Handling
GeminiError: Base exception for all GeminiBot errorsAuthenticationError: Raised for authentication issuesInvalidModelError: Raised if the model name is invalidImageGenNotAllowedError: Raised if image generation is not enabledImageGenAPIError: Raised for image generation API errors
Testing
Run tests with:
python -m unittest discover tests
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rawa_bots-0.2.4.tar.gz.
File metadata
- Download URL: rawa_bots-0.2.4.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b4266ba8886ae9d6d395cacba5a5170aa552962739d4fc2309dbdabddbe88e2
|
|
| MD5 |
d32eb3b46281c9b9d827bb80eb7a1c99
|
|
| BLAKE2b-256 |
941b2d6ca38fae53ff676e99cac56554b8a2e4d812e4cfa3e62258cd1d957f15
|
File details
Details for the file rawa_bots-0.2.4-py3-none-any.whl.
File metadata
- Download URL: rawa_bots-0.2.4-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fba6e7fceb9471e6a2c3a617ef39999df6c9e0f61006d640da575958dd6d45c0
|
|
| MD5 |
36fa12850563a58b80184ae6594cfeb5
|
|
| BLAKE2b-256 |
dd7d1107dbebcafbf9cf386840101389f9598c4ad7898fb796925f157a2f3c3a
|