Skip to main content

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-genai package 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 to True to 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 errors
  • AuthenticationError: Raised for authentication issues
  • InvalidModelError: Raised if the model name is invalid
  • ImageGenNotAllowedError: Raised if image generation is not enabled
  • ImageGenAPIError: 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

rawa_bots-0.2.3.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rawa_bots-0.2.3-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file rawa_bots-0.2.3.tar.gz.

File metadata

  • Download URL: rawa_bots-0.2.3.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for rawa_bots-0.2.3.tar.gz
Algorithm Hash digest
SHA256 9d07c6c5fe3902aa42c760e0d127bb5714fc0f56d85efdc85481bb3f87aa9b55
MD5 5c2b7533289a788f027845e4b52a04e5
BLAKE2b-256 081fda06a33a32349955793d62d9ae7b25b5df7a23b2f5a6b4cec49cfe08de24

See more details on using hashes here.

File details

Details for the file rawa_bots-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: rawa_bots-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for rawa_bots-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bb99b86a517f0b26bd0f5668eca1027e05b081f622c29a8ac6e0124ba61e1253
MD5 4b7b86d5bc4b63703e8b6df2c9ae4bf6
BLAKE2b-256 dad0e6b76d26f38e77ef5eb1c4d6c8302ff4b5261b88143eec41933d08215d5e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page