Simple CLI tool for AI text rewriting with Ollama
Project description
๐ฅ Redukon
Reduce Your Tokens. Keep Your Intent.
๐ Table of Contents
- โจ What is Redukon?
- ๐ Quick Start
- ๐ CLI Usage
- ๐ API Usage
- ๐ณ Docker
- ๐ฆ Batch Mode
- ๐๏ธ Architecture
- โก Example
- ๐ง Options
- ๐ ๏ธ Requirements
- ๐ License
โจ What is Redukon?
Redukon is a token-saving prompt rewriter that uses local small AI models to optimize your prompts โ reducing token count while keeping the core intent intact.
No API keys needed. Runs entirely offline with Ollama.
๐ก Perfect for:
- Saving money on API calls
- Fitting more context into LLM windows
- Making prompts more efficient
- Building into your own apps via API
๐ Quick Start
# Install from PyPI
pip install redukon
# Or install latest from GitHub
pip install -e https://github.com/CharlesArea/Redukon.git
# One-time setup (installs Ollama + picks a model)
redukon onboard
๐ CLI Usage
redukon onboard
Interactive setup wizard:
- Checks if Ollama is installed
- Installs Ollama if needed
- Choose your model:
Model Size Best For qwen2.5:0.5b397MB Speed & minimal resources llama3.2:1b1.9GB Balanced phi3:3.8b2.3GB Better quality
redukon rewrite
Rewrite your prompts from command line:
# Basic
redukon rewrite -i "Please write a comprehensive Python function..."
# From file
redukon rewrite -i @long-prompt.txt -o optimized.txt
# Custom temperature (lower = more focused)
redukon rewrite -i "prompt" --temp 0.3
redukon serve
Start the API server:
# Default port 8000
redukon serve
# Custom port
redukon serve --port 9000
redukon serve --host 127.0.0.1 --port 8080
๐ API Usage
Start Server
redukon serve
Endpoints
| Endpoint | Method | Description |
|---|---|---|
/rewrite |
POST | Rewrite a prompt (non-streaming) |
/rewrite/stream |
POST | Rewrite a prompt (streaming) |
/health |
GET | Health check |
Non-Streaming Example
curl -X POST http://localhost:8000/rewrite \
-H "Content-Type: application/json" \
-d '{
"prompt": "Please write a comprehensive Python function that takes a list of integers...",
"model": "qwen2.5:0.5b",
"temperature": 0.3
}'
Streaming Example
curl -X POST http://localhost:8000/rewrite/stream \
-H "Content-Type: application/json" \
-d '{"prompt": "Your prompt here"}'
Response (SSE format):
data: {"chunk": "Write a "}
data: {"chunk": "Python function..."}
data: {"done": true, "original_tokens": 87, "optimized_tokens": 42, "saved_tokens": 45, "saved_percent": 52}
Example Response
{
"optimized_prompt": "Write a Python function that filters even numbers from a list...",
"original_tokens": 87,
"optimized_tokens": 42,
"saved_tokens": 45,
"saved_percent": 52
}
API Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt |
string | Yes | The prompt to optimize |
model |
string | No | Model name (default: from config) |
temperature |
float | No | Temperature 0.0-1.0 (default: 0.3) |
๐ Logging
API requests are logged to log/api-YYYY-MM-DD.log:
[2026-03-10 12:00:00] [REQUEST] input_length=250, model=qwen2.5:0.5b
[2026-03-10 12:00:05] [RESPONSE] output_length=120, original_tokens=62, optimized_tokens=30, saved_tokens=32, saved_percent=51%
[2026-03-10 12:00:05] [ERROR] Generation failed: Ollama not running
๐ณ Docker
Option 1: API Server Only (connects to Ollama on host)
# Build image
docker build -t redukon .
# Run (ensure Ollama is running on host)
docker run -d -p 8000:8000 --network host redukon
Option 2: Full Stack with docker-compose
# Start both Redukon API and Ollama
docker-compose up -d
# Stop
docker-compose down
๐ฆ Batch Mode
Process multiple prompts at once!
CLI
# From file with multiple prompts (one per line)
redukon batch -i prompts.txt
# Multiple files
redukon batch -i @file1.txt @file2.txt
# With output
redukon batch -i prompts.txt -o results/
redukon batch -i prompts.txt -o results.json
API
curl -X POST http://localhost:8000/batch \
-H "Content-Type: application/json" \
-d '{
"prompts": [
"First prompt to optimize",
"Second prompt to optimize",
"Third prompt to optimize"
],
"model": "qwen2.5:0.5b",
"temperature": 0.3
}'
Response:
{
"results": [
{"index": 0, "original": "...", "optimized_prompt": "...", "saved_tokens": 10, "saved_percent": 25},
{"index": 1, "original": "...", "optimized_prompt": "...", "saved_tokens": 15, "saved_percent": 30}
],
"summary": {
"total": 2,
"processed": 2,
"total_original_tokens": 100,
"total_saved_tokens": 25,
"overall_saved_percent": 25
}
}
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Redukon โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ CLI โ โ API โ โ Batch โ โ
โ โ Commands โ โ Server โ โ Mode โ โ
โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโผโโโโโโโโโ โ
โ โ Ollama API โ โ
โ โ (local models) โ โ
โ โโโโโโโโโโฌโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโผโโโโโโโโโ โ
โ โ Qwen/Llama/Phi โ โ
โ โ 0.5b - 4b โ โ
โ โโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Logging โ โ
โ โ log/api-YYYY-MM-DD.log โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Config โ โ
โ โ ~/.redukon/config.json โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Components
| Component | Description |
|---|---|
| CLI | Command-line interface for single prompt rewriting |
| API Server | Flask server with REST endpoints |
| Batch Mode | Process multiple prompts at once |
| Ollama | Local LLM runtime (connects to Ollama) |
| Models | Small models (qwen2.5:0.5b, llama3.2:1b, phi3:3.8b) |
| Logger | Date-based logging to log/ directory |
| Config | User settings in ~/.redukon/config.json |
Data Flow
- User Input โ CLI / API / Batch
- System Prompt โ Loaded from config or default
- Ollama API โ Sends prompt to local model
- Model Processing โ Optimizes prompt (removes filler, shortens)
- Response โ Returns optimized prompt + token stats
- Logging โ Records request/response to log file
โก Example
| Before (87 tokens) | After (42 tokens) |
|---|---|
| "Please write a comprehensive Python function that takes a list of integers as input and returns a new list containing only the even numbers from the original list. The function should handle edge cases like empty lists, lists with no even numbers, and lists with negative numbers. Please include proper type hints, docstrings, and error handling." | "Write a Python function that filters even numbers from a list. Include type hints, error handling, and docstrings." |
๐ Savings: ~52%
๐ง Options
| Flag | Description | Default |
|---|---|---|
-i, --input |
Prompt or @file.txt |
Required |
-o, --output |
Output file | Print to stdout |
-m, --model |
Override model | From config |
-t, --temp |
Temperature (0.0-1.0) | 0.3 |
๐ ๏ธ Requirements
- Python 3.10+
- Ollama (installed automatically during onboard)
๐ License
MIT ยฉ 2026 CharlesArea
Made with โค๏ธ for the AI community
GitHub โข PyPI โข Report Bug
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 Distributions
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 redukon-3.4.0-py3-none-any.whl.
File metadata
- Download URL: redukon-3.4.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36a095e24269c8b9c6599224fd0bf35969f9f2ac8b1b6474657c0ed309d09501
|
|
| MD5 |
4d919d90be028395a71379e038fc6134
|
|
| BLAKE2b-256 |
777695116917bb7ec1599e64d86480cce2564df35e1aa804f1feb6826ffaa806
|