lion api service system
Project description
Lion Service
A unified interface for AI model providers (OpenAI, Anthropic, Perplexity, Groq) with rate limiting and token management.
Features
- Unified interface for multiple AI providers
- Built-in rate limiting and token tracking
- Automatic retries with exponential backoff
- Token calculation using tiktoken
Installation
uv pip install lion-service
# Provider-specific packages
uv pip install lion-openai # For OpenAI
uv pip install lion-anthropic # For Anthropic
uv pip install lion-perplexity # For Perplexity
uv pip install lion-groq # For Groq
Usage
from lion_service import iModel
# Initialize
model = iModel(
provider="openai",
task="chat",
model="gpt-4",
api_key="your-api-key",
interval_tokens=90000, # Optional: Token limit per minute
interval_requests=3500 # Optional: Request limit per minute
)
# Make requests
async def chat():
response = await model.invoke(
messages=[{"role": "user", "content": "Hello!"}]
)
print(response)
Rate Limiting
# Token and request limits
model = iModel(
provider="openai",
interval_tokens=90000, # 90K tokens/min
interval_requests=3500 # 3.5K requests/min
)
Error Handling
from lion_service import RateLimitError
try:
response = await model.invoke(...)
except RateLimitError as e:
print(f"Rate limit exceeded: {e.requested_tokens} tokens")
Custom Services
from lion_service import Service, register_service
@register_service
class MyService(Service):
def __init__(self, api_key: str):
self.api_key = api_key
self.name = "my_service"
def list_tasks(self):
return ["chat", "completion"]
Contributing
- Fork and clone the repository
- Install dev dependencies:
uv pip install -e ".[dev]" - Make changes
- Run tests:
pytest - Submit a pull request
See Contributing Guide for detailed instructions.
License
Apache License 2.0 - see LICENSE
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
lion_service-1.2.0.tar.gz
(23.5 kB
view details)
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 lion_service-1.2.0.tar.gz.
File metadata
- Download URL: lion_service-1.2.0.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
830c9f200c6e2d6a3c838ec6dbdd5a0da8ff01cea3a2475d7868313d3dc417fb
|
|
| MD5 |
d7689c86c6596de084578afd908c229b
|
|
| BLAKE2b-256 |
6785a938c3cd88ca4715125b04b9e8cc43df94ba185e8026b924f975c84221cb
|
File details
Details for the file lion_service-1.2.0-py3-none-any.whl.
File metadata
- Download URL: lion_service-1.2.0-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd11036ff26c8b7490f2384a633347d3ea858929625612574c7af0cdedb7111c
|
|
| MD5 |
c55cae79dcc008cf0918cab76514baef
|
|
| BLAKE2b-256 |
1c605530762a16d8f6a66dc5627f00a7a70f08f9d3177f3525706c0285c4dfb1
|