Django AI Services Framework — DB-driven LLM provider, model & usage management
Project description
aifw — Django AI Services Framework
DB-driven LLM provider, model & usage management for Django projects.
Installation
pip install aifw
Quick Start
# settings.py
INSTALLED_APPS = [
...
"aifw",
]
# Run migrations
python manage.py migrate aifw
# Use in views, tasks, management commands
from aifw.service import sync_completion, LLMResult
result: LLMResult = sync_completion(
action_code="story_writing",
messages=[{"role": "user", "content": "Write a short story about a dragon."}],
)
if result.success:
print(result.content)
Features
- DB-driven model routing — swap LLM providers/models via Django Admin, zero code changes
- Multi-provider — OpenAI, Anthropic, Google, Ollama, any LiteLLM-compatible provider
- Async & sync —
completion()(async),sync_completion()(sync),completion_with_fallback() - Usage logging — automatic token & cost tracking per action type
- Fallback models — configure primary + fallback model per action type
Models
LLMProvider— provider config (API key env var, base URL)LLMModel— model config (max tokens, cost per million tokens)AIActionType— action → model mapping with fallbackAIUsageLog— token/cost/latency tracking per request
Management Commands
python manage.py init_llm_config # seed default providers & models
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
aifw-0.1.0.tar.gz
(9.6 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
aifw-0.1.0-py3-none-any.whl
(10.3 kB
view details)
File details
Details for the file aifw-0.1.0.tar.gz.
File metadata
- Download URL: aifw-0.1.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b25f773490e613ff12f32bf9f67f45a03c29ac38652084789fe0a24e3e9c9e2
|
|
| MD5 |
bd85b87fbbefe6f0935feb4308a4d705
|
|
| BLAKE2b-256 |
67a6cad6ba5749f391201886a5094ab6c87f7f84ce07c0a4ff8bc1c38c22133a
|
File details
Details for the file aifw-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aifw-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae3591615f58202c1c6851fbecb6e86cfc87777f008410a94994c25a9b443711
|
|
| MD5 |
2a88eace5490442bf4ae92bd9c7dcfc7
|
|
| BLAKE2b-256 |
f622df39ce942eb4f0101c4f6e33dd7db9f2e3b7c355f80597dc7c3b0c25cfee
|