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.0.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.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rawa_bots-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 f39255ea0aa17b413d5a3bac75e3c1d5068ac850e667f5aecdae7b81b6fc4ccf
MD5 f4365380284bb648f46ad1031e7c3685
BLAKE2b-256 7bbc5d4821fab686a78f9e145db601b9c81ac6829f7fe56a1ce434a8e759860c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rawa_bots-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ee8dbdbe36c4a7fde491eaf816272e11559f4a7e33bd23b14937f763177860a
MD5 4ae1d9d9e925f046ec6b18d880337537
BLAKE2b-256 43b8ee1b5ce716b15bdc4dd1dd059eb7f5c8ef5c574605fd081da2cf6fab6967

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