Skip to main content

A unified framework for accessing multiple LLM providers

Project description

MonoLLM

Python 3.13+ License: MIT Documentation GitHub Issues

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/unified-llm.git
cd unified-llm

# Install with uv (recommended)
uv sync
uv pip install -e .

# Or install with pip
pip install -e .

Verify Installation

# Check CLI is working
unified-llm --help

# List available providers
unified-llm 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
unified-llm generate "What is artificial intelligence?" --model qwen-plus --stream

# Use reasoning model with thinking steps
unified-llm generate "Solve: 2x + 5 = 13" --model qwq-32b --thinking

# List available models
unified-llm list-models --provider qwen

๐Ÿ“– Documentation

๐ŸŽฏ 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)

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 UnifiedLLMError, ProviderError

try:
    response = await client.generate(prompt, config)
except ProviderError as e:
    print(f"Provider error: {e}")
except UnifiedLLMError as e:
    print(f"UnifiedLLM 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/unified-llm.git
cd unified-llm
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

๐Ÿ™ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monollm-0.1.1-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

File details

Details for the file monollm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: monollm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 41.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for monollm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7668cb44302001c79deb145bba3c2e5418441efd0de8f03e6e0b831910f580d1
MD5 40c7f3811487e58da64dd87fda1802aa
BLAKE2b-256 e71b5b01372e02e53c95f4c6fb67dd228cf5e6858cc58953f1b6a04cac755818

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page