A unified framework for accessing multiple LLM providers
Project description
MonoLLM
A powerful framework that provides a unified interface for multiple LLM providers, allowing developers to seamlessly switch between different AI models while maintaining consistent API interactions.
๐ Key Features
- ๐ Unified Interface: Access multiple LLM providers through a single, consistent API
- ๐ Proxy Support: Configure HTTP/SOCKS5 proxies for all LLM calls
- ๐บ Streaming: Real-time streaming responses for better user experience
- ๐ง Reasoning Models: Special support for reasoning models with thinking steps
- ๐ก๏ธ Temperature Control: Fine-tune creativity and randomness when supported
- ๐ข Token Management: Control costs with maximum output token limits
- ๐ง MCP Integration: Model Context Protocol support when available
- ๐ฏ OpenAI Protocol: Prefer OpenAI-compatible APIs for consistency
- โ๏ธ JSON Configuration: Easy configuration management through JSON files
๐ Supported Providers
| Provider | Status | Streaming | Reasoning | MCP | OpenAI Protocol |
|---|---|---|---|---|---|
| OpenAI | โ Ready | โ Yes | โ Yes | โ Yes | โ Yes |
| Anthropic | โ Ready | โ Yes | โ No | โ Yes | โ No |
| Google Gemini | ๐ง Planned | โ Yes | โ No | โ No | โ No |
| Qwen (DashScope) | โ Ready | โ Yes | โ Yes | โ No | โ Yes |
| DeepSeek | โ Ready | โ Yes | โ Yes | โ No | โ Yes |
| Volcengine | ๐ง Planned | โ Yes | โ No | โ No | โ Yes |
๐ ๏ธ Installation
Prerequisites
- Python 3.13+ (required)
- uv (recommended) or pip
Quick Install
# Clone the repository
git clone https://github.com/cyborgoat/MonoLLM.git
cd MonoLLM
# Install with uv (recommended)
uv sync
uv pip install -e .
# Or install with pip
pip install -e .
Verify Installation
# Check CLI is working
monollm --help
# List available providers
monollm list-providers
โก Quick Start
1. Set up API Keys
# Set API keys for the providers you want to use
export DASHSCOPE_API_KEY="your-dashscope-api-key" # For Qwen
export ANTHROPIC_API_KEY="your-anthropic-api-key" # For Claude
export OPENAI_API_KEY="your-openai-api-key" # For GPT models
2. Basic Python Usage
import asyncio
from monollm import UnifiedLLMClient, RequestConfig
async def main():
async with UnifiedLLMClient() as client:
config = RequestConfig(
model="qwq-32b", # Qwen's reasoning model
temperature=0.7,
max_tokens=1000,
)
response = await client.generate(
"Explain quantum computing in simple terms.",
config
)
print(response.content)
if response.usage:
print(f"Tokens used: {response.usage.total_tokens}")
asyncio.run(main())
3. CLI Usage
# Generate text with streaming
monollm generate "What is artificial intelligence?" --model qwen-plus --stream
# Use reasoning model with thinking steps
monollm generate "Solve: 2x + 5 = 13" --model qwq-32b --thinking
# List available models
monollm list-models --provider qwen
๐ Documentation
- ๐ Full Documentation - Comprehensive guides and API reference
- ๐ Quick Start Guide - Get up and running in minutes
- โ๏ธ Configuration Guide - Advanced configuration options
- ๐ป CLI Documentation - Command-line interface guide
- ๐ง Examples - Practical usage examples
๐ฏ Use Cases
Content Generation
config = RequestConfig(model="qwen-plus", temperature=0.8, max_tokens=1000)
response = await client.generate("Write a blog post about renewable energy", config)
Code Assistance
config = RequestConfig(model="qwq-32b", temperature=0.2)
response = await client.generate("Explain this Python function: def fibonacci(n):", config)
Reasoning & Analysis
config = RequestConfig(model="qwq-32b", show_thinking=True)
response = await client.generate("Analyze this data and find trends", config)
Thinking Mode for Reasoning Models
MonoLLM supports reasoning models that can show their internal thought process:
# Enable thinking mode to see step-by-step reasoning
config = RequestConfig(
model="qwq-32b", # QwQ reasoning model
show_thinking=True, # Show internal reasoning
temperature=0.7
)
response = await client.generate(
"Solve this step by step: If a train travels 120 km in 2 hours, then 180 km in 3 hours, what is its average speed?",
config
)
# Access the thinking process
if response.thinking:
print("๐ญ Thinking Process:")
print(response.thinking)
print("\n" + "="*50)
print("๐ฏ Final Answer:")
print(response.content)
Supported Reasoning Models:
- QwQ-32B (
qwq-32b) - Stream-only reasoning model - QwQ-Plus (
qwq-plus) - Stream-only reasoning model - Qwen3 Series (
qwen3-32b,qwen3-8b, etc.) - Support both modes - OpenAI o1 (
o1,o1-mini) - Advanced reasoning models - DeepSeek R1 (
deepseek-reasoner) - Reasoning model
Creative Writing
config = RequestConfig(model="qwen-plus", temperature=1.0, max_tokens=2000)
response = await client.generate("Write a science fiction short story", config)
๐ง Advanced Features
Streaming Responses
async for chunk in await client.generate_stream(prompt, config):
if chunk.content:
print(chunk.content, end="", flush=True)
Multi-turn Conversations
messages = [
Message(role="system", content="You are a helpful assistant."),
Message(role="user", content="Hello!"),
]
response = await client.generate(messages, config)
Error Handling
from monollm.core.exceptions import MonoLLMError, ProviderError
try:
response = await client.generate(prompt, config)
except ProviderError as e:
print(f"Provider error: {e}")
except MonoLLMError as e:
print(f"MonoLLM error: {e}")
๐ Proxy Support
Configure HTTP/SOCKS5 proxies:
export PROXY_ENABLED=true
export PROXY_TYPE=http
export PROXY_HOST=127.0.0.1
export PROXY_PORT=7890
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
# Clone and install in development mode
git clone https://github.com/cyborgoat/MonoLLM.git
cd MonoLLM
uv sync --dev
# Install pre-commit hooks
pre-commit install
# Run tests
pytest
# Build documentation
cd docs && make html
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Links
- GitHub: https://github.com/cyborgoat/MonoLLM
- Documentation: https://cyborgoat.github.io/MonoLLM/
- Issues: https://github.com/cyborgoat/MonoLLM/issues
- Discussions: https://github.com/cyborgoat/MonoLLM/discussions
๐ Acknowledgments
- Thanks to all the LLM providers for their amazing APIs
- Inspired by the need for a unified interface across multiple AI providers
- Built with modern Python async/await patterns for optimal performance
๐จโ๐ป Author
Created and maintained by cyborgoat
Made with โค๏ธ by cyborgoat
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 monollm-0.1.2.tar.gz.
File metadata
- Download URL: monollm-0.1.2.tar.gz
- Upload date:
- Size: 61.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
294b1cf8885af9b82028410b7fc0880d3cabba9a6bc1f26aec60825fe41655d1
|
|
| MD5 |
b267736a6a13d9cbd155219977fd84cd
|
|
| BLAKE2b-256 |
eb9a81db793ab01d2d850ab197419aaecec1ee2171c0aaf7e43dbd73b8bbeb7c
|
File details
Details for the file monollm-0.1.2-py3-none-any.whl.
File metadata
- Download URL: monollm-0.1.2-py3-none-any.whl
- Upload date:
- Size: 42.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09bf759bf23d2cf160bcaaf06c3947737b3e0dcd2e0c5f699dff1496355d00f1
|
|
| MD5 |
cb09a274ddff50e5c49336121493a300
|
|
| BLAKE2b-256 |
961f231bd6229df7819a47ef618a09daf4d35ea14904c17f2cb5261ad8e38752
|