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.2.0.tar.gz (23.5 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.2.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

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

Hashes for lion_service-1.2.0.tar.gz
Algorithm Hash digest
SHA256 830c9f200c6e2d6a3c838ec6dbdd5a0da8ff01cea3a2475d7868313d3dc417fb
MD5 d7689c86c6596de084578afd908c229b
BLAKE2b-256 6785a938c3cd88ca4715125b04b9e8cc43df94ba185e8026b924f975c84221cb

See more details on using hashes here.

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

Hashes for lion_service-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd11036ff26c8b7490f2384a633347d3ea858929625612574c7af0cdedb7111c
MD5 c55cae79dcc008cf0918cab76514baef
BLAKE2b-256 1c605530762a16d8f6a66dc5627f00a7a70f08f9d3177f3525706c0285c4dfb1

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