A simple AI toolkit for text processing using OpenAI and Gemini APIs
Project description
AIWand 🪄
A simple and elegant Python package for AI-powered text processing using OpenAI and Google Gemini APIs.
Features
- Text Summarization: Create concise, detailed, or bullet-point summaries
- AI Chat: Have conversations with AI models
- Text Generation: Generate text from prompts
- Smart Provider Selection: Automatically uses available API (OpenAI or Gemini)
- Multiple AI Providers: Support for both OpenAI and Google Gemini
- CLI Interface: Use directly from command line
- Environment Variables: Secure API key management
Installation
Recommended: Using Virtual Environment
We strongly recommend using a virtual environment to avoid conflicts with other packages:
# Create a virtual environment
python -m venv .venv
# Activate it (Linux/Mac)
source .venv/bin/activate
# Activate it (Windows)
.venv\Scripts\activate
# Install aiwand
pip install aiwand
From PyPI (when published)
pip install aiwand
Development Installation
Quick Setup (Recommended)
Use our setup scripts for automatic environment configuration:
# Linux/Mac
chmod +x scripts/setup-dev.sh
./scripts/setup-dev.sh
# Windows
scripts\setup-dev.bat
Manual Setup
Step 1: Clone and setup virtual environment
git clone <your-repo-url>
cd aiwand
# Create virtual environment
python -m venv .venv
# Activate virtual environment
# Linux/Mac:
source .venv/bin/activate
# Windows:
.venv\Scripts\activate
# Upgrade pip
pip install --upgrade pip
Step 2: Install in development mode
# Install package in editable mode with dev dependencies
pip install -e ".[dev]"
# Or install requirements directly
pip install -r requirements.txt
Step 3: Verify installation
python test_install.py
Quick Start
1. Set up your API Key
AIWand is smart about API provider selection:
- If only OpenAI key is available → Uses OpenAI models
- If only Gemini key is available → Uses Gemini models
- If both keys are available → Uses
AI_DEFAULT_PROVIDERpreference (defaults to OpenAI)
Option A: OpenAI Only
export OPENAI_API_KEY="your-openai-api-key-here"
Option B: Google Gemini Only
export GEMINI_API_KEY="your-gemini-api-key-here"
Option C: Both with Preference
export OPENAI_API_KEY="your-openai-api-key-here"
export GEMINI_API_KEY="your-gemini-api-key-here"
export AI_DEFAULT_PROVIDER="gemini" # or "openai"
Using .env File
Create a .env file in your project:
OPENAI_API_KEY=your-openai-key-here
GEMINI_API_KEY=your-gemini-key-here
AI_DEFAULT_PROVIDER=openai
Programmatically
import aiwand
# For OpenAI
aiwand.configure_api_key("your-api-key-here", "openai")
# For Gemini
aiwand.configure_api_key("your-api-key-here", "gemini")
2. Basic Usage
import aiwand
# Summarize text (auto-selects best available AI)
text = """
Artificial Intelligence (AI) is intelligence demonstrated by machines,
in contrast to the natural intelligence displayed by humans and animals.
Leading AI textbooks define the field as the study of "intelligent agents":
any device that perceives its environment and takes actions that maximize
its chance of successfully achieving its goals.
"""
summary = aiwand.summarize(text)
print(summary)
# Chat with AI
response = aiwand.chat("What is the future of AI?")
print(response)
# Generate text
story = aiwand.generate_text("Write a short story about a robot learning to paint")
print(story)
Advanced Usage
Customized Summarization
import aiwand
# Different summary styles
summary = aiwand.summarize(
text="Your long text here...",
style="bullet-points", # 'concise', 'detailed', 'bullet-points'
max_length=50, # Maximum words
model="gemini-2.0-flash" # Specify model (optional)
)
Conversation History
import aiwand
# Maintain conversation context
conversation = []
response1 = aiwand.chat("Hello, how are you?", conversation_history=conversation)
conversation.append({"role": "user", "content": "Hello, how are you?"})
conversation.append({"role": "assistant", "content": response1})
response2 = aiwand.chat("What did I just ask you?", conversation_history=conversation)
Custom Parameters
import aiwand
# Fine-tune generation
text = aiwand.generate_text(
prompt="Write a poem about coding",
max_tokens=200,
temperature=0.8, # Higher = more creative
model="gpt-4" # Specify model (optional)
)
Command Line Interface
AIWand provides a CLI for quick tasks:
# Summarize text (auto-selects AI provider)
aiwand summarize "Your text here" --style concise --max-length 30
# Chat
aiwand chat "What is machine learning?"
# Generate text
aiwand generate "Write a haiku about programming" --temperature 0.9
API Reference
summarize(text, max_length=None, style="concise", model=None)
Summarize text with customizable options.
Parameters:
text(str): Text to summarizemax_length(int, optional): Maximum words in summarystyle(str): Summary style - "concise", "detailed", or "bullet-points"model(str, optional): Specific model to use (auto-selected if not provided)
Returns: Summarized text (str)
chat(message, conversation_history=None, model=None, temperature=0.7)
Have a conversation with AI.
Parameters:
message(str): Your messageconversation_history(list, optional): Previous conversation messagesmodel(str, optional): Specific model to use (auto-selected if not provided)temperature(float): Response creativity (0.0-1.0)
Returns: AI response (str)
generate_text(prompt, max_tokens=500, temperature=0.7, model=None)
Generate text from a prompt.
Parameters:
prompt(str): Text promptmax_tokens(int): Maximum tokens to generatetemperature(float): Response creativity (0.0-1.0)model(str, optional): Specific model to use (auto-selected if not provided)
Returns: Generated text (str)
configure_api_key(api_key, provider="openai")
Set API key programmatically.
Parameters:
api_key(str): Your API keyprovider(str): Provider type ("openai" or "gemini")
Smart Model Selection
AIWand automatically selects the best available model:
| Available APIs | Default Model | Provider |
|---|---|---|
| OpenAI only | gpt-3.5-turbo |
OpenAI |
| Gemini only | gemini-2.0-flash |
Gemini |
| Both available | Based on AI_DEFAULT_PROVIDER |
Configurable |
Supported models:
- OpenAI:
gpt-3.5-turbo,gpt-4,gpt-4-turbo, etc. - Gemini:
gemini-2.0-flash,gemini-2.5-flash,gemini-2.5-pro, etc.
Error Handling
import aiwand
try:
summary = aiwand.summarize("Some text")
except ValueError as e:
print(f"Input error: {e}")
except Exception as e:
print(f"API error: {e}")
Requirements
- Python 3.8+
- At least one API key (OpenAI or Gemini)
- Internet connection
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
v0.0.1
- Initial release
- OpenAI and Gemini API support
- Smart provider selection
- Text summarization, chat, and generation
- CLI support
- Environment-based configuration
Project details
Release history Release notifications | RSS feed
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 aiwand-0.0.1.tar.gz.
File metadata
- Download URL: aiwand-0.0.1.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d850847043be5c65b4f85172924731f94376fdcf18b9f0dcdf292020e21169bd
|
|
| MD5 |
9f99620a12c71a207feca30b6d081f4a
|
|
| BLAKE2b-256 |
76d1ce1d165f47bf8b892a651c31ad9460ea7f3e63e839c6a265b7d9c5d0d9ac
|
File details
Details for the file aiwand-0.0.1-py3-none-any.whl.
File metadata
- Download URL: aiwand-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5b48543b709c56ea9f1464461735a64e304f97e8c229a370292decbcea74cda
|
|
| MD5 |
52566c1cf3645bfac3bc21e52d486b18
|
|
| BLAKE2b-256 |
60d19257226e9a493f571264e6e5a42a4297e3501b92df47cd555bb36726810c
|