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, resolution="1024x1024", n=1, output_path=None, show=False)
    • prompt: The image prompt.
    • resolution: Image resolution (default: 1024x1024).
    • n: Number of images to generate.
    • output_path: If set, saves the image(s) to this path (adds _1, _2, ... if n > 1).
    • show: If True, opens the image(s) after saving.
    • Returns: URL(s) or file path(s).

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.2.tar.gz (7.3 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.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rawa_bots-0.2.2.tar.gz
  • Upload date:
  • Size: 7.3 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.2.tar.gz
Algorithm Hash digest
SHA256 9c95e2258ccfa03e097c7a6d95f346c4696eedbdc2a9d421d0ee4128e2fe1fe0
MD5 4417f8f829ae4dd4dd164b7f1d07d037
BLAKE2b-256 3677e4924467c9e964efeae225f6b2a7b782e80f4a1cca585c73c9172b05bffd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rawa_bots-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 36acab8c2a893e52becd9020ab1d9ade44a144a78bd9a68f2fa474e6dd4e8668
MD5 99edf4bdc0799995271667b0cd4965ba
BLAKE2b-256 960ce6799dfe565cb39aff96fb972bde2e95b2bef499faedde052ef0f1c75471

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