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

aifw-0.2.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

aifw-0.2.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file aifw-0.2.0.tar.gz.

File metadata

  • Download URL: aifw-0.2.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for aifw-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c335bd1922c17fc2411ef40756afefb98af5df55c6e8e39ae7a1351444758b35
MD5 8304d2387d80e8004bb3052920e2a832
BLAKE2b-256 8a66d2313259fa0c74e57be4395c86327e6dc28f70ea77e546e173849f74f81a

See more details on using hashes here.

File details

Details for the file aifw-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aifw-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for aifw-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6c933d8e6b2c97166f07daf6a881ef0f4f179f013726550392174c3a92d2317
MD5 d4a68291386b9349cf30d14a10965a88
BLAKE2b-256 7762309351fd02f29b86d4638373151957a2f6fae9b2ad5866505a80ebb7e725

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