A tiny, extensible AI CLI for terminal workflows
Project description
Rabbit 🐰
A tiny, extensible AI CLI for terminal workflows. Follow your curiosity with multi-provider AI chat, persistent sessions, and streaming responses.
Features
- Multi-Provider Support: OpenAI, Anthropic, and Ollama (local models)
- Persistent Sessions: Keep conversation history across interactions
- Streaming Output: Real-time token streaming with
--stream - System Prompts: Customize AI behavior with
--system - JSON Export: Machine-readable output format
- STDIN Support: Pipe input for automation
- Modular Design: Clean, testable architecture
Quick Start
Prerequisites
- Python 3.7+
- API keys for your chosen provider(s)
Installation
- Clone the repository:
git clone <repository-url>
cd rabbit
- Set up Python environment:
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txt # If you have one, or install dependencies manually
- Set up API keys:
Option A: Using environment file (recommended)
# Copy the example file and edit it with your keys
cp .env.example .env
# Edit .env with your favorite editor and add your API keys
Option B: Using environment variables
# For OpenAI
export OPENAI_API_KEY="your-openai-api-key"
# For Anthropic
export ANTHROPIC_API_KEY="your-anthropic-api-key"
# For Ollama (optional, defaults to localhost:11434)
export OLLAMA_HOST="http://localhost:11434"
Note: The CLI will first check for keys in a .env file, then fall back to environment variables.
Usage
Direct CLI Usage
# Simple question
python3 core/rabbit.py -q "What is Python?"
# With specific provider and model
python3 core/rabbit.py -q "Explain async/await" -p anthropic -m claude-3-sonnet-20240229
# Stream response
python3 core/rabbit.py -q "Write a Python function" --stream
# Use system prompt
python3 core/rabbit.py -q "Hello" --system "You are a helpful coding assistant"
# Start a persistent session
python3 core/rabbit.py -q "Let's discuss Python" -s python-chat
# Continue the session
python3 core/rabbit.py -q "Tell me about decorators" -s python-chat
# Show session history
python3 core/rabbit.py --show -s python-chat --limit 10
# JSON output for automation
python3 core/rabbit.py -q "Hello" --json
# Pipe input
echo "Explain this code: print('hello')" | python3 core/rabbit.py
Using the Wrapper Script
The bin/rabbit script provides a more convenient interface:
# Make it executable
chmod +x bin/rabbit
# Simple question
./bin/rabbit ask "What is Docker?"
# With additional flags
./bin/rabbit ask "Explain Kubernetes" -- -p openai -m gpt-4 --stream
# Show session history
./bin/rabbit show -s devops --limit 12
Configuration
Environment File
Rabbit supports loading API keys from a .env file for convenience and security. This is the recommended approach as it keeps your keys out of your shell history and makes it easy to manage different configurations.
Create a .env file in the project root:
# OpenAI Configuration
OPENAI_API_KEY=sk-your-actual-openai-key-here
# Anthropic Configuration
ANTHROPIC_API_KEY=sk-ant-your-actual-anthropic-key-here
# Ollama Configuration (optional)
OLLAMA_HOST=http://localhost:11434
Priority Order:
.envfile in the current directory- Environment variables
- Default values (where applicable)
Security Note: Always add .env to your .gitignore to avoid committing API keys to version control.
Providers
| Provider | Environment Variable | Default Model |
|---|---|---|
| OpenAI | OPENAI_API_KEY |
gpt-4o-mini |
| Anthropic | ANTHROPIC_API_KEY |
claude-3-5-sonnet-latest |
| Ollama | OLLAMA_HOST (optional) |
llama3 |
Session Storage
Sessions are stored in ~/.config/aibot/sessions/ (or $XDG_CONFIG_HOME/aibot/sessions/).
Command Line Options
-q, --query QUERY Your question/prompt
-s, --session NAME Session name for persistent conversation
-p, --provider PROVIDER Provider: openai, anthropic, ollama
-m, --model MODEL Model name (provider-specific)
--system PROMPT System prompt to set behavior
--stream Stream tokens as they arrive
--json Output JSON envelope
--show Show session history
--limit N Number of messages to show (with --show)
Development
Project Structure
rabbit/
├── bin/
│ └── rabbit # Convenience wrapper script
├── core/
│ ├── __init__.py # Package marker
│ ├── rabbit.py # Main CLI entry point
│ ├── config.py # Configuration paths
│ ├── io_utils.py # Terminal I/O utilities
│ ├── messages.py # Message construction
│ ├── sessions.py # Session persistence
│ └── providers/
│ └── __init__.py # Provider adapters
└── tests/
└── test_rabbit.py # Unit tests
Running Tests
# Install test dependencies
pip install pytest
# Run all tests
python -m pytest tests/ -v
# Run specific test file
python -m pytest tests/test_rabbit.py -v
# Run with coverage (if pytest-cov installed)
python -m pytest tests/ --cov=core --cov-report=html
Adding New Providers
- Add your provider function to
core/providers/__init__.py:
def call_your_provider(messages: List[Message], model: str, stream: bool) -> str:
# Your implementation here
pass
- Register it in the provider dictionaries:
PROVIDER_DEFAULTS["your_provider"] = "default-model"
PROVIDERS["your_provider"] = call_your_provider
- Add tests in
tests/test_rabbit.py
Examples
Basic Q&A
python3 core/rabbit.py -q "What's the difference between list and tuple in Python?"
Code Review Session
# Start a code review session
python3 core/rabbit.py -q "I need help reviewing some Python code" -s code-review
# Continue in the same session
python3 core/rabbit.py -q "Here's the function: def calculate_total(items): ..." -s code-review
# Check what we discussed
python3 core/rabbit.py --show -s code-review
Automated Processing
# Process multiple files
for file in *.py; do
echo "# Reviewing $file"
cat "$file" | python3 core/rabbit.py --system "You are a code reviewer" --json
done
Local AI with Ollama
# Make sure Ollama is running locally with a model
ollama pull llama3
# Use local model
python3 core/rabbit.py -q "Hello" -p ollama -m llama3
Installation from PyPI
Once published, you can install rabbit directly from PyPI:
pip install rabbit-ai-cli
Then use it directly:
rabbit -q "Hello world" -p openai
Development & Publishing
Local Development
- Clone and set up the development environment:
git clone https://github.com/zeecaniago/rabbit.git
cd rabbit
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
- Test your changes:
python -m pytest tests/
- Test package building:
./test_build.sh
Publishing Process
This project uses automated publishing to PyPI:
-
Automatic Tagging: Every commit to
mainautomatically creates a new version tag (managed by.github/workflows/auto-tag.yml) -
Automatic Publishing: When a new tag is created, the publish workflow (
.github/workflows/publish.yml) automatically:- Builds the package
- Updates the version to match the git tag
- Runs tests
- Publishes to PyPI
- Creates a GitHub release
Setting up PyPI Publishing
To enable automatic publishing, you need to:
-
Create a PyPI account at https://pypi.org
-
Set up Trusted Publishing (recommended):
- Go to https://pypi.org/manage/account/publishing/
- Add a new "pending publisher" with:
- PyPI project name:
rabbit-ai-cli - Owner:
zeecaniago - Repository name:
rabbit - Workflow name:
publish.yml - Environment name: (leave empty)
- PyPI project name:
-
Alternative: Use API tokens:
- Generate an API token at https://pypi.org/manage/account/token/
- Add it as
PYPI_API_TOKENin your repository secrets
The workflow will automatically handle version management based on your git tags.
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
[Your chosen license]
Troubleshooting
Common Issues
"Import could not be resolved" errors: These are lint warnings for optional dependencies (openai, anthropic, requests). The code handles missing imports gracefully.
"Command not found: pytest": Install pytest with pip install pytest
API key errors: Make sure your API keys are set in environment variables and are valid.
Ollama connection errors: Ensure Ollama is running locally and the model is available.
Getting Help
- Check existing issues in the repository
- Run with
-hfor help:python3 core/rabbit.py -h - Use
--showto debug session issues - Check API key configuration with your provider's documentation
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
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 rabbit_ai_cli-0.0.10.tar.gz.
File metadata
- Download URL: rabbit_ai_cli-0.0.10.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f60b0351841d4a1fdf0987a228da9ab44dece92885e99e9ed41ba0dcd9cb8523
|
|
| MD5 |
3656cd5b2c4bcecd0d6af45563f3e1ee
|
|
| BLAKE2b-256 |
8747cd5c53860b73d5844f84e1aede0030dbb9d6ba30f538551dbc7bcff5d4d7
|
Provenance
The following attestation bundles were made for rabbit_ai_cli-0.0.10.tar.gz:
Publisher:
publish.yml on zeecaniago/rabbit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rabbit_ai_cli-0.0.10.tar.gz -
Subject digest:
f60b0351841d4a1fdf0987a228da9ab44dece92885e99e9ed41ba0dcd9cb8523 - Sigstore transparency entry: 601040700
- Sigstore integration time:
-
Permalink:
zeecaniago/rabbit@533dc1d03f055e8a03dead065809530a0186efd2 -
Branch / Tag:
refs/tags/v0.0.10 - Owner: https://github.com/zeecaniago
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@533dc1d03f055e8a03dead065809530a0186efd2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rabbit_ai_cli-0.0.10-py3-none-any.whl.
File metadata
- Download URL: rabbit_ai_cli-0.0.10-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f4e6afd781ef3ac13768923c8d4bb03782ba4992b464207031007a455a6bdf5
|
|
| MD5 |
c8d2688467136d0250c2f32bb12faee5
|
|
| BLAKE2b-256 |
a85084dabcf5a43d9c0ead4177ede16963d0e4932e5db409e555a2d19de87dfd
|
Provenance
The following attestation bundles were made for rabbit_ai_cli-0.0.10-py3-none-any.whl:
Publisher:
publish.yml on zeecaniago/rabbit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rabbit_ai_cli-0.0.10-py3-none-any.whl -
Subject digest:
5f4e6afd781ef3ac13768923c8d4bb03782ba4992b464207031007a455a6bdf5 - Sigstore transparency entry: 601040703
- Sigstore integration time:
-
Permalink:
zeecaniago/rabbit@533dc1d03f055e8a03dead065809530a0186efd2 -
Branch / Tag:
refs/tags/v0.0.10 - Owner: https://github.com/zeecaniago
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@533dc1d03f055e8a03dead065809530a0186efd2 -
Trigger Event:
push
-
Statement type: