LiteLLM Router integration for Kamiwaza AI
Project description
LiteLLM Router Integration for Kamiwaza AI
This package provides a custom router for LiteLLM that integrates with Kamiwaza AI model deployments. The KamiwazaRouter extends LiteLLM's Router class to enable efficient routing of requests to Kamiwaza-deployed models.
Features
- Dynamic Model Discovery: Automatically discovers available models from Kamiwaza deployments
- Multi-Instance Support: Connect to multiple Kamiwaza instances simultaneously
- Caching: Efficient caching of model lists with configurable TTL
- Model Pattern Filtering: Filter models based on name patterns (e.g., only use "qwen" or "gemma" models)
- Static Model Configuration: Support for static model configurations alongside Kamiwaza models
- Fallback Routing: Automatic fallback between models in case of failures
Installation
pip install litellm-kamiwaza
For running the examples, you'll also need:
pip install python-dotenv
Requirements
- Python 3.7+
- litellm>=1.0.0
- kamiwaza-client>=0.1.0
Usage
Basic Usage
from litellm_kamiwaza import KamiwazaRouter
# Initialize router with automatic Kamiwaza discovery
router = KamiwazaRouter()
# Use the router like a standard litellm Router
response = router.completion(
model="deployed-model-name",
messages=[{"role": "user", "content": "Hello, world!"}]
)
Configuration Options
Environment Variables
KAMIWAZA_API_URL: URL for the Kamiwaza API (e.g., "https://localhost/api")KAMIWAZA_URL_LIST: Comma-separated list of Kamiwaza URLs (e.g., "https://instance1/api,https://instance2/api")KAMIWAZA_VERIFY_SSL: Set to "true" to enable SSL verification (default: "false")
Router Configuration
# Initialize with specific Kamiwaza URL
router = KamiwazaRouter(
kamiwaza_api_url="https://my-kamiwaza-server.com/api",
cache_ttl_seconds=600, # Cache model list for 10 minutes
model_pattern="72b", # Only use models with "72b" in their name
)
# Initialize with multiple Kamiwaza instances
router = KamiwazaRouter(
kamiwaza_uri_list="https://instance1.com/api,https://instance2.com/api",
cache_ttl_seconds=300
)
# Initialize with static model list alongside Kamiwaza models
router = KamiwazaRouter(
kamiwaza_api_url="https://my-kamiwaza-server.com/api",
model_list=[
{
"model_name": "my-static-model",
"litellm_params": {
"model": "openai/gpt-4",
"api_key": "sk-your-api-key",
"api_base": "https://api.openai.com/v1"
},
"model_info": {
"id": "my-static-model",
"provider": "static",
"description": "Static model configuration"
}
}
]
)
Pattern Matching Examples
You can filter models by name patterns:
# Only use models with "qwen" in their name
router = KamiwazaRouter(
kamiwaza_api_url="https://my-kamiwaza-server.com/api",
model_pattern="qwen"
)
# Only use gemma models
router = KamiwazaRouter(
kamiwaza_uri_list="https://instance1.com/api,https://instance2.com/api",
model_pattern="gemma"
)
# Only use static models
router = KamiwazaRouter(
model_pattern="static"
)
Static Models Configuration
For more organized static model configurations, you can create a static_models_conf.py file in your project root:
# static_models_conf.py
from typing import List, Dict, Any, Optional
def get_static_model_configs() -> List[Dict[str, Any]]:
"""Returns a list of statically defined model configurations."""
return [
{
"model_name": "static-custom-model",
"litellm_params": {
"model": "openai/model",
"api_key": "your-api-key",
"api_base": "https://your-endpoint.com/v1"
},
"model_info": {
"id": "static-custom-model",
"provider": "static",
"description": "Static model configuration"
}
}
]
The KamiwazaRouter will automatically detect and use these static models.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
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 litellm_kamiwaza-0.1.3.tar.gz.
File metadata
- Download URL: litellm_kamiwaza-0.1.3.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53a00de841e88be40a11296b7e83dd8c65d4c200bb0fcc0883a96db2b9f43b0a
|
|
| MD5 |
99ccf2b36b430221372340095bb338d5
|
|
| BLAKE2b-256 |
445d8339567059b24f219fb03c932f93a67ad2d18f3cac583867f142e965c19c
|
File details
Details for the file litellm_kamiwaza-0.1.3-py3-none-any.whl.
File metadata
- Download URL: litellm_kamiwaza-0.1.3-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dd765f321575e7e5d01c3d86e79f7e55c232c1057d9c788f06fccf649e7ea4c
|
|
| MD5 |
789d2ea869c162716de3417ba0358c4c
|
|
| BLAKE2b-256 |
d3ae20bb7425c6cc5e7047a11d69f6fbe159e12fd813ed55684f8b57173b6672
|