Premium
Custom AI fields
Declare a field whose value the AI suggests while the user types.
Two serializer fields do this: PredictiveCharField for a single line and PredictiveTextField
for longer text. Both emit an ai format, which the frontend renders as
SchemaPredictiveTextInput.
Declaration
from habarico_enterprise.ai.fields import PredictiveCharField, PredictiveTextField
from habarico.serializers import AdminModelSerializer
from .models import Product
class ProductSerializer(AdminModelSerializer):
name = PredictiveCharField()
short_description = PredictiveTextField(source_fields=["name", "category"])
class Meta:
model = Product
fields = ["id", "name", "sku", "description", "short_description", "status", "category"]
Options
| Option | Type | Default | Description |
|---|---|---|---|
source_fields | list[str] | every other filled field | Which form values are sent as context for the suggestion |
Everything else is inherited from DRF's CharField — required, allow_blank, max_length, …
Generated schema
| Field class | type | format | Options |
|---|---|---|---|
PredictiveCharField | string | ai | ai.source_fields |
PredictiveTextField | string | ai-text | ai.source_fields |
The frontend renders both with SchemaPredictiveTextInput;
ai-text gets the multiline variant and asks for a longer completion.
caution
An empty source_fields means all other non-empty form values travel to the AI provider. On a
resource holding personal data, list the fields explicitly.
See also
- Usage — enabling the prediction endpoint on the admin
- SchemaPredictiveTextInput — the input this produces
- FieldSchema — where
options.aisits in the schema