Intelligent LLM dispatching with performance-based routing, multimodal support, streaming, monitoring, and comprehensive analytics
Project description
🏆 LLM-Dispatcher: Intelligent LLM Routing
LLM-Dispatcher is an intelligent Python package that automatically selects the best Large Language Model (LLM) for your specific task based on performance metrics, cost optimization, and real-time availability.
🚀 Features
- 🧠 Intelligent Switching: Performance-based LLM selection using credible benchmarks
- 📊 Real Metrics: Based on 2024-2025 benchmark data (MMLU, HumanEval, GPQA, AIME, etc.)
- 💰 Cost Optimization: Dynamic cost-quality balancing
- 🔄 Smart Fallbacks: Automatic failover with intelligent routing
- 🎯 Multi-Modal: Support for text, vision, audio, and structured output
- ⚡ Real-time: Live performance monitoring and optimization
- 🔧 Simple API: Decorator-based usage with minimal configuration
📈 Supported Providers
| Provider | Models | Capabilities |
|---|---|---|
| OpenAI | GPT-4, GPT-4 Turbo, GPT-3.5 Turbo | Text, Vision, Function Calling, Structured Output |
| Anthropic | Claude-3 Opus, Sonnet, Haiku | Text, Vision, Reasoning, Code |
| Gemini 2.5 Pro, Flash, Ultra | Text, Vision, Multimodal, Fast | |
| xAI | Grok 3 Beta | Text, Reasoning, Math |
🎯 Performance Benchmarks
Based on latest 2024-2025 data:
| Model | MMLU | HumanEval | GPQA | AIME | HellaSwag | ARC | VQA |
|---|---|---|---|---|---|---|---|
| GPT-4 | 86.3% | 67.4% | 82.1% | 91.2% | 95.1% | 96.4% | 78.2% |
| Claude-3 Opus | 84.6% | 67.4% | 84.6% | 89.8% | 94.2% | 95.8% | 76.8% |
| Gemini 2.5 Pro | 84.0% | 65.2% | 84.0% | 87.3% | 93.8% | 94.2% | 74.5% |
| Grok 3 Beta | 82.1% | 63.8% | 84.6% | 93.3% | 92.1% | 93.8% | 71.2% |
🚀 Quick Start
Installation
pip install llm-dispatcher
Basic Usage
from llm_dispatcher import llm_dispatcher
@llm_dispatcher
def generate_text(prompt: str) -> str:
"""Automatically routed to the best LLM for text generation."""
return prompt
# Usage
result = generate_text("Write a story about a robot")
print(result)
Advanced Configuration
from llm_dispatcher import LLMSwitch, TaskType
# Initialize with custom configuration
switch = LLMSwitch(
providers={
"openai": {"api_key": "sk-..."},
"anthropic": {"api_key": "sk-ant-..."},
"google": {"api_key": "..."}
},
config={
"prefer_cost_efficiency": True,
"max_latency_ms": 2000,
"fallback_enabled": True
}
)
@switch.route(task_type=TaskType.CODE_GENERATION)
def generate_code(description: str) -> str:
"""Automatically uses the best model for code generation."""
return description
@switch.route(task_type=TaskType.VISION_ANALYSIS)
def analyze_image(image_path: str) -> dict:
"""Automatically uses vision-capable models."""
return {"analysis": "Image processed"}
📚 Documentation
- Installation Guide
- Quick Start Tutorial
- Advanced Configuration
- API Reference
- Benchmark Data
- Contributing
🧪 Development
Setup Development Environment
git clone https://github.com/ashhadahsan/llm-dispatcher.git
cd llm-dispatcher
pip install -e ".[dev]"
pre-commit install
Testing & Coverage
Run Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=src/llm_dispatcher --cov-report=term-missing --cov-report=html
# Run specific test categories
pytest tests/test_core_switching.py -v
pytest tests/test_providers/ -v
pytest tests/test_multimodal.py -v
Current Test Coverage
- Overall Coverage: 47% (7,344 statements, 3,886 missed)
- Core Components: 98% coverage on base classes
- Provider Integration: 48-91% coverage across providers
- Multimodal Support: 47-86% coverage
- Monitoring & Analytics: 0% coverage (new features)
Coverage Reports
# Generate HTML coverage report
pytest --cov=src/llm_dispatcher --cov-report=html
open htmlcov/index.html
# Generate XML report for CI/CD
pytest --cov=src/llm_dispatcher --cov-report=xml
# Update coverage badge in README
python scripts/update_coverage_badge.py
Automated Coverage
- GitHub Actions: Automated coverage reporting on every PR
- Codecov Integration: Real-time coverage tracking
- Coverage Badge: Automatically updated in README
- Coverage Reports: Available as GitHub Actions artifacts
Run Benchmarks
pytest tests/benchmarks/ -v
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
🧪 Testing
LLM-Dispatcher includes comprehensive tests to ensure reliability and performance.
Test Coverage
Current test coverage: 22% (29/29 core tests passing)
- ✅ Core Functionality: All basic tests passing
- ✅ Performance Tests: Latency and throughput tests working
- ✅ Benchmark Utils: Metric calculation and validation tests
- ✅ Provider Integration: OpenAI provider tests
- ✅ Configuration: Switch configuration and validation tests
Running Tests
# Install with dev dependencies
pip install -e ".[dev]"
# Run all tests
pytest
# Run with coverage
pytest --cov=src/llm_dispatcher --cov-report=html
# Run specific test categories
pytest tests/test_basic.py # Core functionality
pytest tests/test_performance.py # Performance tests
pytest tests/test_benchmark_utils.py # Benchmark utilities
Test Categories
| Category | Tests | Status | Description |
|---|---|---|---|
| Core | 27 | ✅ Passing | Basic functionality, configurations, providers |
| Performance | 1 | ✅ Passing | Latency and throughput testing |
| Benchmarks | 1 | ✅ Passing | Metric calculations and validation |
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Benchmark data from Musaix, 51D.co, and Learnopoly
- LLM providers: OpenAI, Anthropic, Google, xAI
- Open source community
📞 Support
- 📧 Email: ashhadahsan@mail.com
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
Built with ❤️ for the AI community
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 llm_dispatcher-1.0.0.tar.gz.
File metadata
- Download URL: llm_dispatcher-1.0.0.tar.gz
- Upload date:
- Size: 327.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b078c1d305ef5aa03acf335d181524d493261e607f4eee6a2bf6228d423dfb79
|
|
| MD5 |
c489d932c7616d37f2ced2e064bb8570
|
|
| BLAKE2b-256 |
32782cb74c5be99920d498bfae0e3e5e0fea36d3d8a3016bf858e9c2b9fbebd0
|
File details
Details for the file llm_dispatcher-1.0.0-py3-none-any.whl.
File metadata
- Download URL: llm_dispatcher-1.0.0-py3-none-any.whl
- Upload date:
- Size: 164.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
456fddde7407cbd74bbf728b6208b2add9659aaaf19824f1df946102ee521728
|
|
| MD5 |
37d3d11a36621ed2c6e543b64e830217
|
|
| BLAKE2b-256 |
3ad6030fa5a2b399f2fe661020916d37ee88917ae1b07e9d822f98efa6f97f5d
|