---
title: "AI module #1"
video_id: s1O_KjSnFqU
url: https://www.youtube.com/watch?v=s1O_KjSnFqU
workflow_page: https://workflows-of-ai.com/workflow/ai-module-1
language: en
captions: generated
---

0:00 hey there as always this is sponsored by
0:03 freely give freely give uh pays my
0:06 salary to contribute to the community in
0:09 terms of AI if you ever need help with
0:12 AI and Drupal that combination we are
0:15 experts and it's not just me there's
0:18 other Consultants as well that knows
0:20 this uh field inside out so please
0:23 contact us if you need help with uh
0:25 anything for your Enterprise or or paid
0:28 Solutions
0:30 today I'm going to talk about something
0:32 else than the AI inter interpolator I'm
0:34 going to talk about a completely new
0:36 module that has been in the planning for
0:39 a couple of weeks so a lot of the people
0:41 from the AI Community came together
0:44 basically uh with the idea to create a
0:47 foundational module for
0:50 druple and this is something I wish
0:52 existed when I was doing the AI
0:54 interpolator I have like created
0:56 abstraction layer in the AI interpolator
0:58 but it's still
1:00 very much just for the interpolator so
1:04 what this is going to be is uh first
1:08 and maybe most important a foundation
1:11 and abstraction layer for all possible
1:14 AI providers for all possible types of
1:17 calls you can do for AI the video I'm
1:20 going to show today has is actually very
1:24 different from everything else I show
1:26 usually I show something that anyone
1:27 should be able to set up without knowing
1:29 develop Vel M today I'm just going to
1:32 talk to
1:33 developers so I'm going to Showcase why
1:36 you should use this when you're either
1:38 working privately with AI and Drupal or
1:42 when you're creating a contributed
1:44 module and why you should uh rely on us
1:48 so uh if you install these well well I
1:53 will also say two things about the
1:55 module AI interpolator is going to be
1:57 built in here so it's going to be
1:59 renamed to a i automator and it's going
2:01 to be the version
2:02 two uh also what I'm talking about today
2:06 the abstraction layer that all comes
2:09 from the brain of uh Michael gov so this
2:12 guy SEO go that created the llm
2:15 abstraction layer that is now deprecated
2:18 that has gone into the AI and I have
2:20 just tried to uh add a lot of features
2:24 on top of it so that's what I've been
2:26 working on the last week so that's what
2:28 I'm going to showcase
2:30 so now if you get this uh module and
2:35 search for AI there's going to be a lot
2:37 of modules but what's important is this
2:39 one AI Core so that's what you need to
2:42 be able to use this layer I'm going to
2:44 talk about today then of course you need
2:47 some kind of Provider so you need to
2:49 work against some Service as you can see
2:51 it already comes with a lot of providers
2:53 that you can use uh
2:56 both uh like services like open AI or or
3:00 like model cataloges like hugging face
3:03 but also uh LM Studio no Lama that you
3:06 can actually host locally or set up on a
3:08 server so you can make sure that your
3:10 prompts never leaves your company
3:14 Network um so you just need to install
3:16 one of those uh to get going with this
3:19 there's small documentation here or a
3:22 little documentation I haven't written
3:24 enough there's going to come more
3:25 documentation
3:27 soon um so so uh what I want to showcase
3:31 in this case oh sorry about the image
3:33 here but this is actually connected to
3:35 what I want to showcase so this is the
3:37 normal article in in um Drupal you
3:41 install the Drupal standard installation
3:43 I've added one field called image prompt
3:46 and what I want to do in this uh case is
3:48 that I want
3:50 to uh ask via prompt about
3:55 um basically ask V prompt uh to take
3:59 take this article and create a image
4:01 prompt from this and then take this
4:03 image prompt and create this image of
4:05 course you can use a interpolator you
4:07 can use augmentor AI to do this uh but
4:10 in this case I want to develop it myself
4:12 to to understand what I'm doing so I
4:16 have uh the possibility to write
4:19 something like this right so uh and
4:23 we're talking now before the the AI
4:25 module existed so you you're basically
4:27 having up you know if it's article
4:30 create a prompt you can you generate a
4:32 sentence image and uh then you have this
4:36 open AI client open AI is it's actually
4:40 very easy so I'm taking the easiest
4:42 route now because this is a very well
4:45 developed client that exists right you
4:48 have to figure out how you're going to
4:50 sideload the API key in a secure
4:52 manner uh and then you're going to write
4:54 this long array that is basically how
4:57 you're uh creating the first call here
5:01 do the call make sure you do exceptions
5:03 if something fails then you save this
5:05 into the field and then you have to
5:08 start creating the image and exception
5:11 and then since it's a image you have to
5:13 create that image entity I didn't even
5:15 write all this code because there's so
5:17 much code that you have to
5:19 write and then you have solved it right
5:21 so when you click save this is going to
5:23 go into pre-save and start doing this
5:26 but with this new layer you can do this
5:28 instead so it looks like this
5:30 um so there's a couple of things that's
5:33 important here so first of all we have
5:34 the AI provider service so this is
5:36 always what you reference when you're
5:38 going to do a eii
5:39 call um and then you can
5:44 uh basically take this provider create a
5:48 instance which is a provider instance
5:51 which can be in this case open AI then
5:54 and in this case we want to make a chat
5:56 message so if you if you just make sure
5:58 that you have um
6:00 a good ID you're going to be able to
6:02 autocomplete all these different objects
6:05 right so in this case we take these
6:08 messages and say that we want the same
6:10 thing GPT three to five turbo you don't
6:13 necessarily need to add this here you
6:15 can set a default model for every type
6:17 of operation and provider so you have
6:20 something default but for now we say
6:23 gpt3 to five turbo and we want this back
6:27 normalized so we're basically pushing in
6:30 normalized values and we're getting
6:33 normalized uh values
6:36 back uh
6:38 and I will Showcase in a minute why this
6:41 is but I can also showcase that you can
6:43 actually do this if you want so if I
6:45 copy the messages
6:47 here I could instead do this because I
6:50 know this is open Ai and I could do get
6:53 raw here and then it would actually get
6:56 me the raw response as it is the Json uh
7:00 array that comes from open
7:02 AI um so it is possible to use it that
7:06 way you can even do but I you should not
7:10 do this but you can actually do this
7:12 even if there is something that the
7:15 whole abstraction layer can solve you
7:17 can actually do this you get the open AI
7:21 client you can't necessarily do that
7:23 with every provider but with open AI you
7:25 can do it so we get this and this
7:29 returns then a chat message so this
7:31 looks exactly like this it's it's just
7:33 like dto objects right uh that you can
7:37 connect uh some values to a a getter or
7:41 a Setter inside there so in this case we
7:44 create a chat message we create another
7:46 one and in this case we get the chat
7:47 message back and then we can do the get
7:49 message to get the message right we just
7:52 set it into file image prompt here's the
7:56 also Nifty thing then we do another open
7:59 Ai and I'm going to show you why I'm not
8:00 reusing it here set a configuration
8:03 similar to how we did here that we just
8:05 want one well that's actually default I
8:07 don't think I have to set that uh I
8:10 don't think I have to set response
8:12 format either but I just wanted to show
8:14 you that you can set a configuration
8:15 here right same again we do a normalized
8:19 input send it say we want all three but
8:23 instead of get the get raw which is the
8:26 response from open AI or get normalized
8:28 which is a a file
8:30 binary I can have helper functions here
8:33 depending on what it is we're trying to
8:35 create so there is a get us image
8:37 reference there is a get us media
8:39 reference there is a get us file
8:41 reference when we're talking about file
8:43 fields for instance uh which means in
8:46 this case I can do get us image
8:48 reference uh and this takes just where I
8:51 should put
8:52 it and then it's solved so if I do this
8:56 if we just want to resave uh oh I I
8:59 haven't thought about the alt text we
9:01 should probably set that but uh if I
9:03 resave now you see it takes time because
9:05 it goes in here again and uh rewrites
9:08 the prompt so you can just see the
9:10 prompt here uh and but it's going to
9:13 rewrite that now
9:15 right uh and the cool thing
9:18 then when this is done when we say that
9:21 okay this was really bad quality because
9:24 we don't trust open in AI or oh
9:26 fireworks AI it's so much cheaper or I
9:29 want Croc because it's so fast so say
9:32 that we uh uh want to use um the default
9:38 mod model from from Gro instead then
9:42 it's as simple as this we take away this
9:45 WR groc and that's it so now we're using
9:49 groc instead same thing here there does
9:52 only exist currently one image uh text
9:55 to image model model but soon dream
9:57 studio is going to come so you can do
9:59 dream
10:00 Studio the configuration might differ of
10:03 course so either you just don't give a
10:05 configuration and have the default
10:06 values if you really want to make it
10:08 flexible but you should probably expose
10:10 this as a form I will come to this in
10:12 another video because we help you with
10:14 this as well uh and because I've used
10:18 normalized input and normalized output I
10:20 can just swap hot swap however I want
10:23 here right well if I do dream Studio of
10:25 course here it should probably like sd3
10:29 or I can take the
10:31 default model as well then um
10:38 and that is it that is the reason why
10:41 you should be using this there are a lot
10:44 of other reasons we can maybe talk about
10:46 them because I actually I think I um
10:48 written them down because I forget about
10:50 it but basically here you know it's hot
10:54 swapping is one thing takes care of API
10:56 keys so we're using the keys module it
10:58 is as good of a pattern as you can get
11:01 it can still still be saved in
11:03 configuration by mistake but you know it
11:06 is at least making sure that people
11:07 thinks think about it it also makes sure
11:10 that there is always a consistent place
11:12 so I will show you it's always under
11:14 configuration AI setting provider
11:16 settings and there's these different
11:18 configuration where you can just set a
11:20 key so it's just one place not that
11:23 every person that makes a contributed
11:25 module wants to set their own form uh
11:28 and this is not calling anyone out I do
11:31 the same thing with AI interpolator
11:34 right
11:36 um it also triggers event so it makes
11:40 sure that every call uh that is done via
11:44 this is triggering event which means
11:46 that we can have stuff like
11:50 um how we show you we can have for
11:52 instance a logging module that can log
11:55 prompts and these prompts are getting
11:58 tagged by like um you can manually tag
12:01 each of the queries so this is just a
12:03 parameter I can show you here you can
12:05 just add a third one and do my image
12:09 call so when when you're uh triggering
12:14 the event you can look for my image call
12:16 for instance if you want to do something
12:18 specific before it sends it or after it
12:21 sends it uh and this make sure that you
12:24 can do stuff like moderation you can use
12:26 external moderation so something we can
12:28 do uh for for instance
12:30 with uh a very sensitive provider like
12:34 anthropic is that anthropic doesn't have
12:36 moderation themselves but we can put
12:38 open AI moderation in front of it and
12:40 this is triggered via the event system
12:43 then um so that's all that but
12:49 uh all right so this takes care of
12:51 logging the logging also I'm going to
12:54 show at another time you can replay your
12:57 prompts which means that if this is log
12:59 we're going to have prompt explorers I'm
13:01 going to Showcase them at another time
13:03 where you can actually see uh the
13:05 underlying prompt that some module does
13:07 because then you can uh improve that uh
13:11 prompt because that's a problem with the
13:12 a interpolator it's adding a lot of
13:14 prompting around your prompts with
13:17 asking for Json and doing like uh few
13:20 shot learning in many cases where it's
13:22 giving examples and if you want to
13:24 really figure out what's going wrong and
13:27 maybe you want to use some playground
13:29 then we have that playground where you
13:31 can try any model try any uh provider
13:35 and see the actual prompt that like it
13:37 was done
13:39 right
13:42 um
13:43 so yeah that's it first video about AI
13:47 more videos to come thank you
