Skip to main content
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​

OptionTypeDefaultDescription
source_fieldslist[str]every other filled fieldWhich 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 classtypeformatOptions
PredictiveCharFieldstringaiai.source_fields
PredictiveTextFieldstringai-textai.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​