AI-filled event details¶
Version v1
You can apply this model as a recipe (Drupal 10.3 or later) to your own Drupal site:
1 2 3 4 5 6 7 8 9 10 11 | |
Purpose¶
One button on the Event node form asks an AI chat model for the facts an editor would otherwise copy out of the description by hand. "Extract the event details" fills the compound Event details field, whose columns hold the venue, the city, the capacity, the ticket price, whether the event is online, a contact address and a registration link. The button reads the title and the description of the form that is open at that moment, so it works on a node that has never been saved.
The mapping keys are your column names¶
Custom Field is a field type whose properties the site builder defines. A column carries a machine name and a data type, and the columns of one field make up one item, so nothing about them is fixed by the module. That makes the column names the contract between the field and the model: the "Set field widget value" action returns a mapping, and its keys are the storage column names of the field it fills.
This model ships seven of them, venue, city, capacity,
ticket_price, online, contact_email and registration, and its
fill action returns exactly those keys. On a site whose field already
exists, read the names off either of two places. Open the field at
/admin/structure/types/manage/event/fields and edit its storage
settings, which list one machine name per column. The token browser
lists them too, as the last segment of a token such as
[node:field_event_details:0:capacity].
Typed columns take strings¶
Token replacement produces strings, so every leaf of the mapping arrives
as one, and the JSON schema asks the model for strings for the same
reason. The integer, decimal and boolean columns cast what they receive:
the string 120 in the capacity column becomes the number 120, and
1 checks the online checkbox while 0 leaves it unchecked.
An empty string is the deliberate answer for a fact the description does not carry. It leaves a number column empty rather than writing a zero, because the widget turns a value that is not numeric into no value at all.
The email and the URI column are validated when the node is saved, not when the button is clicked. A malformed address, or a URL the URI column rejects, is therefore reported by the save, which is also where an editor can still correct it.
How the AI answer becomes columns¶
Tamper: Strip tags turns the description into plain text, the Chat action
sends the title and that text with a strict JSON schema, and Tamper:
Encode/Decode in Json Decode mode turns the response into structured data
under details. The fill action then addresses one leaf per column, as
[details:venue] or [details:ticket_price].
The raw response keeps a token of its own, details_ai_response, because
decoding a token into its own name would discard the string the failure
branch logs.
The guard on the decoded response reads [details:online]. The schema
allows that property the values 1 and 0 only, so an empty one can
only mean that the response did not decode. Neither venue nor city is
usable for that question: an online event has no venue, and either column
can legitimately come back empty from a response that decoded perfectly
well. The unusable case goes to the eca_ai_lookup log channel with the
raw response.
The editor has the last word¶
The button fills the widget and nothing else. It never saves the node, so review the details before you save: the prompt asks for an empty string rather than a guess, but an AI model can still be confident and wrong.
Requires an unreleased ECA Field Widget Actions¶
Two changes this model needs arrived after 1.0.0-beta2. The compound
fill and the use_yaml setting came with
issue #3588902, and the recognition
of custom_field's field type as a compound one came with
issue #3588913.
A 1.0.x-dev at or after commit c7c3edb carries both. The recipe's
composer.json always asks for any version, so check the installed one
by hand.
Before you run it¶
Select a chat model that supports structured output in the "Ask AI for the event details" action. Without structured output the schema is ignored and the response does not decode. Each click waits for the provider, which takes a few seconds.
Requirements¶
This recipe installs custom_field, node, text, path and
field_widget_actions next to eca, eca_base,
eca_field_widget_actions, eca_log, eca_tamper, ai_integration_eca
and modeler_api. No core recipe provides an Event content type, so the
recipe ships it with its body field, its field_event_details field and
both displays.
Dependencies¶
- module
- ai_integration_eca
- eca_base
- eca_field_widget_actions
- eca_log
- eca_tamper
- modeler_api