This video will showcase how you can use the AI and AI Automators modules to pre-screen any content in Drupal before it gets published. You can use any criteria for flagging or allowing content and any AI provider like OpenAI, Ollama, Anthropic etc.
It works together with the Content Moderation module to set content to a specific moderation state, by reading the content (or images).
The setup takes 5 minutes.
You can find more workflows under https://workflows-of-ai.com/
Links from the video: AI Module: https://www.drupal.org/project/ai Base Field Override Module: https://www.drupal.org/project/base_field_override_ui
This video is from before the AI Interpolator module became AI Automators, part of the AI module . Module and menu names have changed since, and some steps look different today.
0:00
this episode is sponsored by uh freely give if you need help with Drupal and AI and consultancy around it just get in contact with us so hey there Marcus here uh what I'm
0:12
going to show today is how you can use the Drupal buil in moderation State and have AI Control it automatically so you can do a pre-screening of content where basically AI can tell that okay this
0:26
should probably be flagged or this should probably be allowed to be published um so you can you know put your content in the hands of unior editors or even the the actual end
0:40
user uh to be able to do this we're going to use the AI module as usual we're going to use automators as it's called now so this if you have followed my channel you have seen a lot of videos
0:51
about the AI Interpolator AI Automator is just the basically AI interpolator 2.o uh with a lot of new functionality and I'm going to show one piece of that new functionality here so you need to
1:07
get that uh the thing I added here is still not in uh the Alpha version so you would have to get the dev currently until Alpha 9 uh exist and you would need this file base field override UI so
1:22
I'm going to show you what this does the the cool thing with this is that you can use the automators on builtin fields like the moderation stat this you also need
1:31
the token module for the AI automator to work uh so the only thing I've done on this website I've logged into it I've added a key for OpenAI I'm going to use OpenAI in this case you can use any
1:44
provider that you want uh but I'm going to Showcase this with OpenAI and I have added admin toolbar as you can see and that's it so I'm going to start adding stuff here so what we need is the AI
1:57
Core we need the AI automators we don't need any plugins for the AI automators just the core one is will be able to handle this OpenAI provider uh and then we also need to add the base field
2:12
override UI and that's it so if we install all those that is going to be enough oh no of course we need to actually install the content moderation module that takes care of the moderation
2:25
State as well so this is just a standard installation it comes with a article um article right so what we're going to do is we're going to go to workflows and we're going to change the
2:39
editorial workflow and first of all connect it then to our article but then we're also going to add two new States so we're going to add one that's called flagged that's not going to be
2:57
published of course that basically means that AI has flag this because of whatever criterias you set it to flag on uh and when it's flagged basically an admin should have to go in to put it
3:12
into pre-published as we're going to call the new State uh because of course AI doesn't always get stuff right sometimes it's wrong and then it's good that a human
3:24
eye goes in and looks at it but it's at least good to get uh initial View uh of what's working and what's not working so it's going to it's still going to start at draft but directly on
3:37
draft it's going to either be pre-published or be flagged uh and to be able to do that we have to add some transitions here which means that uh when it's adding a
3:50
draft it's not allowed to go published draft goes to draft uh and then published only comes from pre-published uh in this case so it has to be pre-published before it can be
4:07
published uh and uh archive can still be published to Archive restored to draft Yeah archive could go to draft archive could go to publish all that is okay we're going to add a new transition
4:24
how it becomes pre-published and that comes from draft uh and add the same for flag then so flagged can come from draft as well and uh let's see here from from flagged we need to be able to
4:52
push it to pre published as well so in the pre-published we're also going to say that it can come from the flagged can be uh given back from published of course as
5:05
well uh and we have the draft as the default so we set all this go to our content type um and uh here we have our Fields but because we added the base field over
5:23
right we get the extra tab here with actual field overrides of Base Fields you can do and this is what we're going to work with so we're going to use the moderation State here we click add
5:33
meaning that we want to take over this after we have added it we can click edit and then the automator will show up um oh okay I I should actually fix this error message so the problem is this I
5:51
actually forgot something we need to actually uh set up the provider of course so I'm going to select the key OpenAI key connect that save and this now sets a lot of defaults if you're on
6:06
new site where basically takes over a lot of operation types now if we go back here and go to the base field overrides hopefully there's no error message anymore can enable the AI
6:21
automator and now we can basically either you know use a lot of fields but in this case we just use the body field so we're saying if uh the body field contains something that we don't like so
6:37
I'm just going to take a very uh weird example now I can't think of anything but if the text you see is about Lord of the Rings make sure it gets flagged right so you can copy this
6:58
uh placeholder otherwise it can be pre-published so we want it to go to pre-published and uh we just use text we do like this separation and we copy the context so
7:21
it's going to read this text that is the body of the article if it's about Lord of the Ring it should get flagged otherwise it can be pre-published right uh and we can just keep all this
7:36
as it is what is is important are these settings so I'm just going to start with uh not going through these two I'm just going to set that it triggers when it's
7:47
draft that's important so normally a automator is triggered when it's uh the value is empty but this value is never empty so you have to tell it when should you trigger it and you always trigger it
8:00
when it's a draft so if you actually want draft you should probably add a pre-draft or something like that so you actually can have a draft as well um so I save this now and I just go
8:15
to create the article and uh my new article uh yesterday yesterday I ate pudding this shouldn't be flagged right so if I save it now uh you can see it becomes pre-published so we try the same thing
8:40
again here um yesterday I met Gollum so you can see I don't use the word Lord of the Rings AI is SM to understand context uh and save it and now it should then be
8:59
flagged because this was talking about uh Lord of the Rings so that that is a initial way you can set this up but there is actually more to it because uh as I said it might not always
9:15
be perfect and you might wonder why did it do what it did so what you can actually do is create a new plain text long it has to be a plain text long uh and call it uh uh State
9:27
moderation reasoning or or something you can call it whatever you want of course reasoning uh you just save this this field of course you should hide for from the end users I can't do it here just to
9:41
show you how you do it so they don't see it it should just be part of the uh actual uh forms you forms you see right um and when you have added that you can go back to the moderation State and you
9:57
can actually tell it in the bottom that you want to store the explanation and you get all the long text field so we just say we want to store this in state moderation
10:09
reasoning and I will showcase this again now then so I create another article oops Gollum uh I met Gollum yes day uh and you can see you see this field it might be that if you don't want
10:29
to expose this to the editors that you know you have to have like uh for uh field permissions but I mean you get the idea behind this so now it got flagged if I
10:40
click edit now you can also read here the text mentions Gollum a character from Lord of the Rings therefore it should be flagged so you get a reasoning uh and that is it I will
10:56
explain the last thing that actually exist there that might also be interesting because uh I mean this is fine when you actually want AI to read through something very nuanced and uh have a
11:13
deep understanding of the text you know then OpenAI Anthropic Claude uh llama gem llama you know 45b or gemini or something are great for this right but they send the data so if you're if if
11:29
you have other reasons why you want to stop this like this has personal information of course you don't want to send this to OpenAI because that's personal information right
11:41
so there is another mode in here uh so usually the automators are pretty complex they create complex JSON so they need a model that is mediumsized at least um but there is this thing you can do so
11:57
you can do use small mod model uh and basically look for these states so you're looking now for pre-published and flagged uh and what's and you can actually still store
12:12
the explanation so what's going to happen now is that you can use a like a local model like Gemma 2B or v um V3 2B V3 1B that are so small that they can even run on a Raspberry Pi they are not
12:31
super good at creating JSON they are not super good at answering exactly as you want but they are fairly good at understanding text and what you want to have read out of the
12:44
text uh so what is happening here when you say that it should be looking for flagged or pre-published what it's going to do it's going to take the whole answer that might be something like uh
12:57
yes I can look for this it seems like they mention Gollum that is part of the uh Lord of the Rings therefore this is flagged and when you when you use this it's basically going
13:10
to look for the word flagged anywhere and if it finds the word flagged it's going to flag it same with pre-published word then uh and that way you can have a a first screening that actually runs
13:23
locally that's not sent to some third party which means that you can uh you know know check for pis and stuff like that without having any privacy concerns um yeah so that's how the state
13:38
moderation automator works thank you for watching