Here's a comprehensive README.md file for your LLM Providers library:
LLM Providers
A unified Python library for interacting with multiple Large Language Model (LLM) providers with a consistent interface.
Features
- Multi-Provider Support: OpenAI, Claude, Gemini, Groq, DeepSeek, HuggingFace (API and local)
- Unified Interface: Consistent API across all providers
- Async Support: Full async/await implementation
- Streaming: Real-time text generation
- Caching: Disk-based caching with TTL
- Rate Limiting: Built-in rate limiting
- Error Handling: Comprehensive error handling and retries
- Type Safety: Pydantic models for input validation
- Extensible: Easy to add new providers
Installation
pip install llm-providers
Supported Providers
| Provider | API Support | Local Models | Streaming | Async |
|---|---|---|---|---|
| OpenAI | ✅ | ❌ | ✅ | ✅ |
| Claude | ✅ | ❌ | ❌ | ✅ |
| Gemini | ✅ | ❌ | ❌ | ✅ |
| Groq | ✅ | ❌ | ✅ | ✅ |
| DeepSeek | ✅ | ❌ | ✅ | ✅ |
| HuggingFace | ❌ | ❌ | ❌ | ❌ |
Quick Start
Basic Usage
from llmfusion import get_provider, LLMConfig, LLMInput
# Configure OpenAI
openai_config = LLMConfig(
api_key="your-openai-key",
model_name="gpt-4"
)
# Create client
openai = get_provider("openai", openai_config)
# Create input
input = LLMInput(
prompt="Explain quantum computing",
system_prompt="You are a physics expert",
temperature=0.7,
max_tokens=500
)
# Generate response
response = openai.generate(input)
print(response)
Async Usage
import asyncio
from llmfusion import get_provider, LLMConfig, LLMInput
async def main():
config = LLMConfig(
api_key="your-api-key",
model_name="claude-3"
)
claude = get_provider("claude", config)
input = LLMInput(prompt="Write a poem about AI")
response = await claude.agenerate(input)
print(response)
asyncio.run(main())
Streaming
from llmfusion import get_provider, LLMConfig, LLMInput
config = LLMConfig(
api_key="your-api-key",
model_name="gpt-4"
)
gpt = get_provider("openai", config)
input = LLMInput(prompt="Explain blockchain technology")
for chunk in gpt.stream(input):
print(chunk, end="", flush=True)
Configuration
LLMConfig Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str | None | Provider API key |
model_name |
str | Required | Model name/identifier |
base_url |
str | Provider default | Custom API endpoint |
timeout |
int | 30 | Request timeout in seconds |
max_retries |
int | 3 | Maximum retry attempts |
cache_ttl |
int | 3600 | Cache time-to-live in seconds |
rate_limit_rpm |
int | 1000 | Requests per minute limit |
device |
str | "auto" | Device for local models (cpu/cuda) |
Advanced Usage
Custom Cache Directory
from llmfusion import set_cache_dir
set_cache_dir("/path/to/cache")
Disable Caching
config = LLMConfig(
api_key="your-key",
model_name="gpt-4",
cache_ttl=0 # Disable caching
)
Using Local HuggingFace Models
config = LLMConfig(
model_name="mistralai/Mistral-7B-Instruct-v0.1"
)
hf = get_provider("huggingface", config)
Error Handling
The library provides comprehensive error handling with custom exceptions:
from llmfusion import (
LLMError,
RateLimitError,
AuthenticationError,
ProviderError
)
try:
response = client.generate(input)
except RateLimitError as e:
print("Rate limit exceeded:", str(e))
except AuthenticationError as e:
print("Authentication failed:", str(e))
except ProviderError as e:
print("Provider error:", str(e))
except LLMError as e:
print("General error:", str(e))
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Documentation
Full documentation is available at https://github.com/mbenhaddou/llm_providers
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
- Inspired by the need for a unified LLM interface
- Built with ❤️ by Mohamed Ben Haddou
Metadata
Release files for llmfusion 0.2.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llmfusion-0.2.7.tar.gz | 19.2 kB | Without provenance | Details for llmfusion-0.2.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llmfusion-0.2.7-py3-none-any.whl | Python 3 | none | any | Details for llmfusion-0.2.7-py3-none-any.whl |
Total release size: 43.3 kB
Release files / llmfusion-0.2.7.tar.gz
| Download URL | llmfusion-0.2.7.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b25d3b7537555142260ae4ea1ab3439217e38f43fe3cf65cd333d19c5358bfd
|
|
BLAKE2b-256 checksum How to use checksums |
2c7815dc25541e48738fbb7e8814bac3c5623c1f13dcd94b447e1dca14c81b4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.8
|
Release files / llmfusion-0.2.7-py3-none-any.whl
| Download URL | llmfusion-0.2.7-py3-none-any.whl |
|---|---|
| Size | 24.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5bcb2cd708dcac4c59efd4c02207dd8e2ec0012f8e15c48e8cda70a8999efc3d
|
|
BLAKE2b-256 checksum How to use checksums |
1c91e261d0703872c62fe56a92474856bab04c44c6f97b1d467975531d14c10e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.8
|
Security for llmfusion 0.2.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.