Skip to main content

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.

Version License

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

  1. Fork and clone the repository
  2. Install dev dependencies: uv pip install -e ".[dev]"
  3. Make changes
  4. Run tests: pytest
  5. Submit a pull request

See Contributing Guide for detailed instructions.

License

Apache License 2.0 - see LICENSE

Project details


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.1.1.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

lion_service-1.1.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file lion_service-1.1.1.tar.gz.

File metadata

  • Download URL: lion_service-1.1.1.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for lion_service-1.1.1.tar.gz
Algorithm Hash digest
SHA256 167dc32fd3cc5770abd374f9ab64e08b1ca8d0a2df303c230d6e781319018194
MD5 550c8e3c4e7fb031df73ed25f0e1f3e1
BLAKE2b-256 e4403321060b6efea81e4ea936dfee8fedb66c1aea9acc1ba0398d433976a998

See more details on using hashes here.

File details

Details for the file lion_service-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: lion_service-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for lion_service-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3148db12711a448edfb973b5eca72e53e8468086846c252cfcc630ebb3362992
MD5 c30e0b6a624e4fafc86c68977e853141
BLAKE2b-256 d10d0e516ed6897e99f7a7f38ddfa0d51f227f9c6fbf4f9062ed6c790d007b4a

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