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

Uploaded Python 3

File details

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

File metadata

  • Download URL: rawa_bots-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 507c1eca0fed21a610ebbfeb2e0681c5d45db9a4e0de9543f2f7b5c71f57e992
MD5 7e4250599baf5e3e2b4c74427d151f47
BLAKE2b-256 94cc1098a2b4510f4426456661f962d8a363fec8e10f5d3a8a99b296cfe5040a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rawa_bots-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3fbf186b2e8e473ea73081625ebd1bd4515bb11c4a756b3a45fbf211d1251b61
MD5 4c64aae14d98cefe383d66531babc2fa
BLAKE2b-256 9bb5e4cd5f61bfc3ca53d2e9f218a793de5766fb72c9307240188bcd6e9ec5f0

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