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.3.0.tar.gz
(12.1 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.3.0-py3-none-any.whl
(13.1 kB
view details)
File details
Details for the file aifw-0.3.0.tar.gz.
File metadata
- Download URL: aifw-0.3.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edf7d839e4059b7c6b0e3d7709a9371fa50af698e953ac06c9a0985b86b89eb8
|
|
| MD5 |
f4796056b7bd00c3ab599988997d66e6
|
|
| BLAKE2b-256 |
1ce45a48ed591c26aa0ae385725c21769390c6827f75586b439cc41b042afae0
|
File details
Details for the file aifw-0.3.0-py3-none-any.whl.
File metadata
- Download URL: aifw-0.3.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deda673365ce6dbbedbfe3c86bdb3fcbe76e01a2482ad8eab23933fb89b6d4dd
|
|
| MD5 |
c96aba914bb881bf02175092bf0a111e
|
|
| BLAKE2b-256 |
8b12293b4a53684fe3463f6f6fc7439367d4c323ea57282b998b34170f8676fe
|