A unified interface for multiple LLM providers with caching and interactive development mode to get massive cost savings.
Project description
HyperLLM
A unified Python interface for multiple LLM providers with intelligent caching and cost-saving interactive development mode. Stop burning money on API calls during development - use interactive mode to prototype with real LLMs at zero api cost!
๐ Why HyperLLM?
Save Development Costs: Interactive mode eliminates expensive API calls during prototyping. Copy prompts to your clipboard, paste responses back, and build your application without the API meter running.
Provider Freedom: Switch between OpenAI, Anthropic, local Ollama, or any custom API with a single line of code. No vendor lock-in, no rewriting.
Smart Caching: Never pay for the same prompt twice. Responses are automatically cached and reused across development and production.
Developer Experience: Built by developers, for developers. Clipboard integration, file I/O, and seamless workflows that just work.
โจ Features
- ๐ Unified Interface: One API for all LLM providers - OpenAI, Anthropic, Ollama, and more
- ๐ฐ Cost-Saving Interactive Mode: Develop without API costs using copy-paste workflow
- ๐พ Intelligent Caching: Automatic response caching with prompt-based deduplication
- ๐ Extensible Provider System: Easy to add new providers or custom APIs
- ๐ Clipboard Integration: Automatic prompt copying for seamless workflows
- ๐ File I/O Support: Read prompts from and write responses to files
- ๐ก๏ธ Production Ready: Robust error handling, validation, and monitoring
- ๐ฏ Zero Configuration: Works out of the box with sensible defaults
๐ฆ Installation
# Basic installation
pip install hyperllm
# With specific provider support
pip install hyperllm[openai] # OpenAI GPT models
pip install hyperllm[anthropic] # Anthropic Claude models
pip install hyperllm[clipboard] # Enhanced clipboard features
# Install everything
pip install hyperllm[all]
๐ Quick Start
from hyperllm import HyperLLM
# Initialize once, use everywhere
interface = HyperLLM()
# Configure your preferred provider
interface.set_llm('openai',
api_key='your-api-key',
model='gpt-4')
# Get responses (cached automatically)
response = interface.get_response("Explain quantum computing simply")
print(response)
# Subsequent identical prompts use cache - zero cost!
cached_response = interface.get_response("Explain quantum computing simply")
๐ฅ Interactive Development Mode
The game-changer for LLM development costs:
# Enable interactive mode - save money during development!
export LLM_INTERACTIVE_MODE=true
from hyperllm import HyperLLM
interface = HyperLLM()
interface.set_llm('openai') # Provider doesn't matter in interactive mode
# This copies prompt to clipboard and waits for your response
response = interface.get_response("Write a Python function to sort a list")
# Workflow:
# 1. Prompt automatically copied to clipboard โจ
# 2. Paste into ChatGPT/Claude/etc.
# 3. Copy response and paste back
# 4. Response cached for production use
# 5. Zero API costs during development! ๐ฐ
Perfect for:
- Prompt engineering and iteration
- Building demos and prototypes
- Testing different prompt variations
- Learning and experimentation
๐ Supported Providers
OpenAI GPT Models
interface.set_llm('openai',
api_key='sk-...',
model='gpt-4o', # or gpt-3.5-turbo, gpt-4, etc.
temperature=0.7,
max_tokens=2000)
Anthropic Claude
interface.set_llm('anthropic', # or 'claude'
api_key='sk-ant-...',
model='claude-3-sonnet-20240229',
max_tokens=2000)
Local Ollama
interface.set_llm('ollama',
base_url='http://localhost:11434',
model='llama2', # or codellama, mistral, etc.
temperature=0.7)
Custom APIs (OpenAI Compatible)
interface.set_llm('custom',
base_url='https://api.your-provider.com',
api_key='your-key',
model='your-model',
headers={'Custom-Header': 'value'})
Check Available Providers
from hyperllm import get_available_providers
providers = get_available_providers()
for name, info in providers.items():
status = "โ
Available" if info['available'] else "โ Missing deps"
print(f"{name}: {status}")
๐พ Smart Caching System
Responses are automatically cached using prompt hashing:
# First call - hits API/interactive mode
response1 = interface.get_response("What is machine learning?")
# Subsequent calls - instant cache retrieval, zero cost
response2 = interface.get_response("What is machine learning?")
# Manage cache
stats = interface.get_cache_stats()
print(f"Cached responses: {stats['total_entries']}")
interface.clear_cache() # Clean slate when needed
๐ ๏ธ Advanced Usage
One-Line Setup
from hyperllm import create_interface
# Create and configure in one step
interface = create_interface('anthropic',
cache_dir='/custom/cache',
api_key='sk-ant-...',
model='claude-3-opus-20240229')
File-Based Workflows
# Configure file I/O for automated workflows
export PROMPT_OUTPUT_FILE="/tmp/prompt.txt"
export RESPONSE_INPUT_FILE="/tmp/response.txt"
export LLM_INTERACTIVE_MODE=true
Provider Comparison
# Easy A/B testing between providers
providers = [
('openai', {'model': 'gpt-4'}),
('anthropic', {'model': 'claude-3-sonnet-20240229'}),
('ollama', {'model': 'llama2'})
]
for name, config in providers:
interface.set_llm(name, **config)
response = interface.get_response("Compare these approaches...")
print(f"{name}: {response[:100]}...")
Custom Provider Registration
from hyperllm.providers import register_provider, BaseLLMProvider
class MyProvider(BaseLLMProvider):
def validate_config(self):
return True
def _setup_client(self):
pass
def generate_response(self, prompt, **kwargs):
return f"Custom response for: {prompt}"
# Register and use
register_provider('myprovider', MyProvider)
interface.set_llm('myprovider')
๐ฏ Real-World Examples
Development to Production Pipeline
import os
from hyperllm import HyperLLM
# Development phase - zero API costs
os.environ['LLM_INTERACTIVE_MODE'] = 'true'
interface = HyperLLM()
interface.set_llm('openai')
# Build your prompts interactively
prompts = [
"Generate a REST API design for a blog",
"Write error handling for user authentication",
"Create database schema for user profiles"
]
for prompt in prompts:
response = interface.get_response(prompt)
# Responses cached automatically
# Production deployment - use cached responses + API
os.environ['LLM_INTERACTIVE_MODE'] = 'false'
interface.set_llm('openai', api_key=os.environ['OPENAI_API_KEY'])
# Cached responses used when available, new prompts hit API
response = interface.get_response("Generate a REST API design for a blog") # From cache!
new_response = interface.get_response("Add OAuth2 to the API") # New API call
Multi-Model Analysis
# Compare responses across providers effortlessly
interface = HyperLLM()
test_prompt = "Explain the trade-offs of microservices architecture"
results = {}
for provider in ['openai', 'anthropic', 'ollama']:
try:
interface.set_llm(provider, **provider_configs[provider])
results[provider] = interface.get_response(test_prompt)
except Exception as e:
results[provider] = f"Error: {e}"
# Analyze differences in responses
for provider, response in results.items():
print(f"\n=== {provider.title()} ===")
print(response)
๐ Use Cases
- ๐งช Prototype Development: Build LLM features without burning budget
- ๐ฌ Prompt Engineering: Iterate on prompts using interactive mode
- โก Production Applications: Seamless transition from development to production
- ๐ A/B Testing: Compare providers and models effortlessly
- ๐ Learning & Experimentation: Explore LLMs without cost concerns
- ๐๏ธ Enterprise Integration: Unified interface for multiple LLM services
๐ Environment Variables
| Variable | Description | Default |
|---|---|---|
LLM_INTERACTIVE_MODE |
Enable interactive development mode | false |
PROMPT_OUTPUT_FILE |
File to write prompts (interactive mode) | None |
RESPONSE_INPUT_FILE |
File to read responses (interactive mode) | None |
OPENAI_API_KEY |
Default OpenAI API key | None |
ANTHROPIC_API_KEY |
Default Anthropic API key | None |
๐ง Error Handling
from hyperllm import HyperLLM
from hyperllm.providers.base import ConfigurationError, APIError
try:
interface = HyperLLM()
interface.set_llm('openai', api_key='invalid-key')
response = interface.get_response("Test prompt")
except ConfigurationError as e:
print(f"Configuration error: {e}")
except APIError as e:
print(f"API error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
๐ค Contributing
We welcome contributions! HyperLLM is designed to be extensible and community-driven.
Quick Start for Contributors
-
Fork and Clone
git clone https://github.com/your-username/hyperllm.git cd hyperllm
-
Set Up Development Environment
# Create virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install in development mode with all dependencies pip install -e ".[all,dev]"
-
Run Tests
pytest tests/ -v
๐ ๏ธ Development Setup
# Install development dependencies
pip install -e ".[dev]"
# Run tests with coverage
pytest tests/ --cov=hyperllm --cov-report=html
# Run linting
flake8 hyperllm tests
black hyperllm tests
# Type checking
mypy hyperllm
๐ Contributing Guidelines
Adding New Providers
We're always looking for new LLM provider integrations! Here's how to add one:
-
Create Provider File
# hyperllm/providers/newprovider_provider.py from .base import BaseLLMProvider class NewProviderProvider(BaseLLMProvider): def validate_config(self): # Validate configuration pass def _setup_client(self): # Initialize client pass def generate_response(self, prompt, **kwargs): # Implement response generation pass
-
Register Provider
# Add to hyperllm/providers/__init__.py from .newprovider_provider import NewProviderProvider PROVIDER_REGISTRY['newprovider'] = NewProviderProvider
-
Add Tests
# tests/test_providers/test_newprovider.py import unittest from hyperllm.providers.newprovider_provider import NewProviderProvider class TestNewProviderProvider(unittest.TestCase): def test_validation(self): # Test provider validation pass
-
Update Documentation
- Add usage example to README
- Document configuration options
- Add to provider comparison table
Code Style
- Black for code formatting
- flake8 for linting
- mypy for type hints
- pytest for testing
- Google style docstrings
Commit Guidelines
# Use conventional commits
git commit -m "feat: add support for NewProvider LLM"
git commit -m "fix: handle timeout errors in OpenAI provider"
git commit -m "docs: add examples for interactive mode"
๐ Bug Reports
Found a bug? Please open an issue with:
- Environment details (Python version, OS, package version)
- Minimal reproduction code
- Expected vs actual behavior
- Error messages/stack traces
๐ก Feature Requests
Have an idea? We'd love to hear it! Open an issue with:
- Use case description
- Proposed API/interface
- Benefits and alternatives considered
๐ฏ Good First Issues
Look for issues labeled good-first-issue:
- Adding new provider integrations
- Improving error messages
- Adding configuration examples
- Writing documentation
- Adding tests for edge cases
๐ Development Resources
- Provider Base Class:
hyperllm/providers/base.py - Main Interface:
hyperllm/interface.py - Test Examples:
tests/test_providers/ - Integration Examples:
examples/
๐ Contributors
Thanks to all contributors who make HyperLLM better!
๐ License
MIT License - see LICENSE file for details.
๐ Links
- PyPI: https://pypi.org/project/hyperllm/
- Documentation: https://github.com/hyper-swe/hyperllm#readme
- Issues: https://github.com/hyper-swe/hyperllm/issues
- Changelog: https://github.com/hyper-swe/hyperllm/releases
โญ Support the Project
If HyperLLM saves you development time and costs, please:
- โญ Star the repository
- ๐ Report bugs and suggest features
- ๐ค Contribute new providers or improvements
- ๐ข Share with other developers
Made with โค๏ธ by developers who got tired of expensive LLM development cycles.
HyperLLM - One interface, all providers, zero waste.
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 hyperllm-1.0.1.tar.gz.
File metadata
- Download URL: hyperllm-1.0.1.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb6cd64047f8f853b15c7fd1c876ca1a9cd6403c967a5c2aa12b1a005fe4c3e9
|
|
| MD5 |
8eaa13355ab37a165a222c5701f38bd5
|
|
| BLAKE2b-256 |
24692e936148afc5951618322631fc10d4f6009b28483055d95d2977857fba12
|
File details
Details for the file hyperllm-1.0.1-py3-none-any.whl.
File metadata
- Download URL: hyperllm-1.0.1-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
067d2b964f1dccf6e0432fc26f7548f649b20578b24f4d11853159953cb29ad4
|
|
| MD5 |
2d963809a13015ee8388ed343f740d21
|
|
| BLAKE2b-256 |
c714fff2a60835cf834ee1f6f06f5e86d1105025e0c157b0bd03b40eb0a1b218
|