AI integration
Optional AI features for an admin: fields that suggest their own content, an assistant that fills a whole form, and a fulltext filter that understands intent rather than substrings.
Everything here lives in habarico-enterprise —
habarico_enterprise.ai — and is opt-in — a project that does not configure a key keeps the plain
behaviour.
Setup
pip install habarico-enterprise
# settings.py
OPENAI_API_KEY = "…"
Then use the AI variants of the base classes:
from habarico_enterprise.ai.admin import AIModelAdmin
from .models import Product
class ProductAdmin(AIModelAdmin):
model = Product
search_fields = ["name", "description"]
fields = ["name", "sku", "description", "short_description", "status", "category"]
AIModelAdmin wires the AI fulltext filter and the prediction endpoint; predictive fields work
from that point on.
Every AI call is billed by the provider. The endpoints are therefore open only to an authenticated
caller on a resource that somebody may write to (can_create or can_update), and each part of
the request is size-capped — see Usage. A resource that
gets 405 from the AI endpoints is missing one of those two flags.
Field values are sent to the AI provider to produce a suggestion. On a resource holding personal
data, name the source fields explicitly with source_fields instead of letting the default
“everything filled in” apply — see Custom AI fields.
Pages
| Page | What it covers |
|---|---|
| Usage | AIModelAdmin and what it turns on |
| Custom AI fields | PredictiveCharField and PredictiveTextField |
| Viewset | Overriding the AI viewset |
| Serializer | Overriding the AI serializer |
| Filterset | Overriding the AI filterset |
| AI client | Calling the provider directly |
See also
- SchemaPredictiveTextInput — the input rendered for these fields
- AiAssistantButton — the whole-form assistant