Skip to main content

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 & synccompletion() (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 fallback
  • AIUsageLog — 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

iil_aifw-0.5.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

iil_aifw-0.5.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file iil_aifw-0.5.0.tar.gz.

File metadata

  • Download URL: iil_aifw-0.5.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for iil_aifw-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f19bdc10dde1de0796d42fb68f07619ce4fdce6bfb5f8c63b592a37901de5d44
MD5 d86223d66a52c4c7b2317d1b84645774
BLAKE2b-256 5ea781b3b057335ce3cfccb81cb85982c34aaf592e7d0b25b366f0c8531dbfc4

See more details on using hashes here.

File details

Details for the file iil_aifw-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: iil_aifw-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for iil_aifw-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 386b3579dfff67634f9f75d74558687bebf385f468d9d134784b4e4989abd0ea
MD5 9c4b5d2bd2cec1dbb1b6388ffc2121a8
BLAKE2b-256 b481c7094921f1dbc29f7f7a39f201b8a34a13cca3d0eb495abb1d8b70c90692

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