---
title: "API First"
video_id: TaHZhNRpgb8
url: https://www.youtube.com/watch?v=TaHZhNRpgb8
workflow_page: https://workflows-of-ai.com/workflow/api-first
language: en
captions: generated
---

0:01 hey there Marcus here um today I'm going
0:05 to talk about
0:07 uh it's not actually a workflow so what
0:10 I'm going to do is I'm going
0:12 to
0:14 um set up and use something called the
0:17 AI interpolator post OB processor so
0:20 that's the module you see
0:22 here and what this does it basically
0:25 opens up the AI interpolator for API
0:28 usages so druple comes with a lot of uh
0:32 well it comes with Json API but you can
0:35 also basically extend it to use any uh
0:38 API
0:39 Service uh and for those that don't know
0:43 I will just introduce this first you're
0:45 what you're seeing in front of you is a
0:46 vanilla druple site I have added admin
0:48 toolbar I have added the AI interpolator
0:51 modules and the these are the extra
0:53 features that I add on top of droople
0:56 then that I have
0:57 developed uh that are open source
1:02 um what I am uh going to show you
1:07 today it's then very different from what
1:10 I show normally so normally I show just
1:12 how you connect you know different AI
1:14 Services together in this uh use case
1:19 I'm going to show you how you can set up
1:20 from scratch uh API service instead
1:23 where you can basically take single
1:25 input multiple
1:27 inputs uh use AI services or other kind
1:30 of processors on this uh to change this
1:34 content into something else so in this
1:36 case I'm going to make something that's
1:38 very stupid nothing that makes really
1:41 sense I'm just going to create articles
1:43 from one one sentence uh and an article
1:47 and article image using open Ai and Del
1:51 in this
1:52 case uh the AI interpolator has a lot of
1:55 services we're up to 14 now I think that
1:57 you can basically chain so there's a lot
2:00 of use cases for it I've started
2:03 creating videos for it but this uh
2:06 there's so much ways you can basically
2:09 combine this that are not documented
2:13 that I haven't done videos for but there
2:15 will come more and more videos when I
2:16 have time basically but I there's
2:19 probably hundreds of use cases where you
2:21 can actually combine this into different
2:23 services so it could be it's completely
2:26 multimod you can take anything you can
2:28 input a text you can inut put a audio
2:30 file with someone talking you can input
2:32 a image that you want to
2:34 describe do multiple steps there uh
2:38 where you can do stuff that gets
2:40 outputed as text as images as audio full
2:45 audio and I mean truly podcast you can
2:48 generate so say that you want to uh I've
2:51 seen these services available where you
2:53 can for instance input a
2:56 URL uh and after some time you get a
2:58 podcast output put the right where two
3:02 people or three people are talking about
3:04 the subject in this
3:06 article uh this is super simple to set
3:09 up the whole back end you will just have
3:10 to focus on the front end in this case
3:13 uh so the reason to use API then is of
3:16 course you might first of all not want
3:18 to use the Drupal front end you might
3:20 want to run Drupal headless and then uh
3:25 generate um the front end using react
3:29 angular View something like that but
3:31 it's also Drupal is very opiniated uh
3:34 not Everyone likes CMS or cmf
3:37 systems uh so of course if you built a
3:40 system in some other tool that you
3:41 prefer even if it's you could be outside
3:43 of PHP world even you know write
3:46 something node write something Java
3:49 whatever yeah you can still use the
3:51 Drupal and the AI interpolator to
3:54 combine all the different uh AI stuff uh
4:00 via aui and the advantage of that is of
4:03 course that AI is not deterministic
4:07 right if I set up a database set certain
4:09 indexes and ask it to store something I
4:12 know exactly what will happen that's
4:14 deterministic I know the output I get if
4:16 I do a get request to it if I write a
4:19 specific function I well I might add a
4:22 bug into the function but usually I know
4:24 what I input and what I am supposedly
4:27 getting as output with AI it's not like
4:30 this you can guess what you're going to
4:32 get as output but it might not be true
4:35 and then you might want to chain a lot
4:36 of stuff so if you take the podcast
4:38 example what you need to do uh with AI
4:41 uh well if you don't have the AI
4:43 interpolator you need to use something
4:45 like a scraping tool or let's take it
4:48 one more another step you you want to
4:51 search and uh research some news fat of
4:55 the day so say the the um
5:00 yeah whatever it can be there's a
5:02 volcano being uh exploding now in might
5:05 that might explode in Iceland so say
5:08 that you want
5:09 to analyze 10 articles from
5:13 this uh you want to scrape these
5:15 articles you want to create a summary of
5:17 this article and then you want to create
5:19 a summary of this summary and then use
5:21 this summary to create a script for a
5:24 podcast and with this podcast you want
5:26 to create a MP3 where multiple people
5:29 are talking to each other with
5:30 personalities and everything right if
5:33 you're going to do this using Lang chain
5:35 or something you need to code there is
5:37 no other way around it you know you need
5:39 to know how to code they're starting to
5:42 get up chaining tools that you can pay
5:44 for but this is completely open source
5:47 anything you see here you can do
5:48 afterwards of course you have to pay for
5:50 the services they're not going to
5:51 generate stuff for you for free but as
5:54 long as you pay for the services
5:56 actually chaining them and prototyping
5:58 this because since I said what I said
6:01 it's not deterministic something might
6:03 go wrong in this chain and you don't
6:06 want to spend a week or two weeks to
6:08 prototype something in JavaScript or
6:11 python or something and then it turns
6:13 out okay I can't actually get the end
6:15 result I want instead you can basically
6:17 set it up in couple yeah 20 minutes in
6:20 in the AI inter leer it's gooey based
6:23 anyone can do it the project manager can
6:25 do it the the uh the CEO can do it if
6:28 you want you just need to know how to
6:31 prompt correctly right uh so it's very
6:34 good for that and because of this I
6:37 think there might be people that want to
6:39 try this out with this and then they
6:41 find a product and then they say well
6:43 this is fine we can keep it here we
6:44 don't want to spend the time on
6:45 developing this but we don't like druple
6:49 so we just keep that there and then we
6:51 can make API call with inputs and get
6:54 response with this output so
6:56 maybe if we take the podcast example you
6:59 just just going to make API call that uh
7:01 is just a search word and you're going
7:05 to pull it until you see okay it's
7:07 finished and here we have MP3 and that's
7:08 my
7:10 result
7:13 um and I just want to mention this
7:17 uh because uh with Drupal 7 something
7:22 Drupal 7 to druple e something happened
7:24 where it lost its popularity among the
7:26 masses because basically it went away
7:28 from being a hobby programming CMS
7:31 similar to or I'm not going to say hobby
7:33 that's uh that sounds like a very
7:37 negative connotation I mean WordPress
7:39 currently you don't need to know that
7:42 much about development and you can
7:43 create a really great website and for
7:46 articles for blog posts this kind of
7:49 news sites best content management
7:52 system there is Drupal went another path
7:56 path where they wanted to make
7:57 everything Enterprise
8:00 what is great with this is that the
8:02 developers that work with it usually
8:04 knows what they're talking about which
8:06 means that if you hire a Drupal
8:08 developer create a project and that guy
8:11 quits if you find another Drupal
8:12 developer that person probably knows the
8:14 same
8:16 stuff uh but what it's also great at is
8:21 that it's a Content management framework
8:23 that's why the goo is not as easy to use
8:26 as WordPress it's not in general as easy
8:28 to use as WordPress
8:29 there's not a plugin for everything
8:31 there used to be in Drupal 7 and that's
8:33 what changed in Drupal 8 then it became
8:35 more professional more developer Centric
8:38 less site Builder Centric but what does
8:41 exist that there is there there is a
8:43 great framework for how every field
8:45 looks like which means that for AI
8:50 services this is already done so if we
8:53 need
8:54 validation on a address field this is
8:56 already done if uh open
9:00 AI since it can generate Json what what
9:04 isable uh what is available in the AI
9:07 interpolator is that you can basically
9:09 take a text search for locations like
9:12 Apel Tower or something check these with
9:14 Google Places check that it exists then
9:19 get the address of it and map it on a
9:21 Google Maps so we're talking about
9:23 really complex field that you can just
9:25 set up within minutes using uh just a
9:29 guy tool no development no programming
9:34 needed uh so for this the inator is
9:38 perfect that's why I I mean I I I
9:41 started looking at L chain and that's
9:43 great you can create something extremely
9:45 sturdy so if you're going to create Big
9:47 Data if you're going to create a
9:49 software as a service where you know you
9:51 have a lot of customers so you have the
9:53 money to set it up to work on a big
9:56 development team Lang chain in in uh
9:59 no or langen in Python is great and
10:02 there's so much more services but if you
10:04 just want to test something this is
10:07 fabulous um
10:10 so as I said this video is completely
10:12 different from the other I probably
10:14 talked more in this introduction than I
10:17 than the normal video is I will also
10:20 mention I don't have anything prepared
10:22 there might be some bugs on the way uh
10:26 usually the videos are so simple that
10:29 you don't see any bugs because it's so
10:30 simple to set up the
10:33 interpolations uh that there is no time
10:35 for bugs in this case I need to set up
10:37 apis and stuff so because of this there
10:40 might be bugs but that's maybe good to
10:43 see that not everything works flawlessly
10:45 by clicking around and I had a script
10:47 where I made everything perfect the only
10:50 thing I will show you that I have
10:51 prepared is basically the API requests
10:55 so I have tried those out
10:57 already so let's let's get started as I
11:00 said this is druple with AI interpolator
11:02 modules I haven't enabled this post OB
11:06 processor module because I'm going to
11:07 show you the difference when I do enable
11:10 it
11:12 um I'm also going to enable Json API
11:15 extras because this can do uh a little
11:18 bit cooler stuff with uh Json API but
11:22 let's get started now so what I do have
11:26 installed already is Json module so this
11:30 is you comes with Drupal core you just
11:32 have to enable it basically what I'm
11:34 going to do is I'm going to install this
11:37 Json API extras as well so we have it up
11:40 and
11:41 running this is basically how you
11:43 install something Drupal add
11:45 functionality so this uh gives me better
11:48 control over Json API this is what this
11:50 module does and then what I'm going to
11:53 do is I'm going to go to content types
11:56 and I'm going to create our uh well
11:59 droup of people knows it as content
12:01 types you can think of it as a workflow
12:03 basically so we're going to create an
12:05 article right uh it needs a
12:08 title and we can actually use the title
12:11 as the prompt for generating our
12:15 description and for generating our
12:20 image sorry there was a cut there I got
12:23 the call thing fit so we're going to
12:26 generate
12:27 our article right so we need text
12:31 formatted long for that which is
12:33 basically
12:34 HTML field uh we're just going to call
12:38 that the
12:40 article uh so when you write this
12:45 prompters it's very important how you
12:47 write this because it might be perceived
12:50 differently by the AI depending on how
12:52 you write this so when you choose the
12:54 amount of fields when you're going to
12:56 write a prompt like create x amount of
12:58 paragraphs it might read that that each
13:01 paragraph should be be its own value
13:04 right so what you can do here is either
13:07 you do unlimited field save each in a
13:10 field or you make sure that the prompt
13:12 is
13:13 so uh exact that it will generate one
13:17 field
13:18 only but I um will basically do it in
13:22 multiple Fields now so we choose full
13:25 HTML we want to add some HTML on the
13:27 output uh we enable the AI interpolator
13:31 and this is what's going to do the magic
13:32 now then so we use open AI text long and
13:34 we base it on the
13:36 title and then we write our uh prompt
13:39 based on the title No based on the
13:44 context uh generate
13:46 an article that is around 12
13:51 paragraphs
13:53 long you may use HTML Fields tags
13:59 text it is like headers p e
14:05 m
14:07 um P
14:17 strong we have the
14:27 context
14:30 then under advanced
14:32 settings
14:37 um sorry about that so under advaned
14:42 settings um we're going to choose
14:46 gp4 because we want it basically in this
14:50 case to take a little bit longer to
14:52 Showcase what the the post OB processor
14:55 is doing so this is for long running API
14:58 requests if you have ai stuff that can
15:02 answer within a second or so you don't
15:04 need this
15:07 basically and then you see interpolator
15:09 workers and that's the normal workers
15:11 that comes with
15:13 the uh AI
15:16 interpolator so in the showcases I
15:18 always use batch because that's very
15:20 visual it's using JavaScript uh to cut
15:23 up all the jobs into a cube basically
15:26 make sure that nothing times out so if
15:28 you have a CDN or Patcher engine X
15:30 timing out it's not going to
15:32 happen but anyone sending API request
15:35 can't run Javas script of course this
15:38 means that that's not available so what
15:40 you can do instead you can run it on
15:42 Chrome but then it's very important of
15:45 course that the CR jobs runs often
15:48 enough so if you run every minute then
15:49 it's probably okay but if you run every
15:52 hour it's going to suck if someone asks
15:55 a request that they want to create a
15:57 article and then they have to wait 1
16:00 hour so what we can use from the
16:02 beginning is direct and that means
16:03 basically it when you do the request
16:06 it's running in the background
16:08 right taking
16:11 time uh which is not super for API but
16:15 it kind of works depends on if you have
16:18 a long timeout or not on your uh CDN
16:22 engine X AER so on
16:27 then so I added the article with this
16:30 now I'm just going to add a image then
16:32 that we call the article
16:36 image we're going to save this we just
16:40 need one
16:42 image there's a lot of fields here you
16:44 see that's basically what comes with
16:46 Drupal and why Drupal is very good for
16:49 Content as I name said before we're
16:52 going to use the open AI do to generate
16:56 the image we're going to base it on type
16:59 title I'm going to write generate an
17:02 image based on the
17:05 following now generate an a header
17:11 image for an article based on the
17:15 following
17:17 uh
17:18 text we put the context of course this
17:21 is going to be very bad results you need
17:24 a better prompt to be honest and there
17:27 is I can do some
17:29 advertisement here well not that I earn
17:31 any money on it but there is the prompt
17:34 perfect uh module you can use so you use
17:37 this service prompt perfect in between
17:40 there where you can take a simple prompt
17:42 that generates a good prompt for do so
17:44 you see the example here using spaghetti
17:46 bolog and you get this great prompt for
17:49 do for
17:51 instance that's just another part of the
17:55 chain right same thing here Direct 100
17:59 we do Dolly 3 so it takes some time save
18:02 that we don't have to change any
18:04 settings I can show you first manually
18:06 how to create this
18:08 then uh and this is now based on the
18:11 title I write here so I'm going to write
18:13 Obama like
18:15 poems it's going to create the article
18:18 on this now then and while we're doing
18:21 this then I'm going to show you the how
18:22 to set up the Json API so this is the
18:25 Json API is already set up actually it's
18:28 set up
18:30 here and you can see the different
18:32 things that gets exposed by
18:34 default and then you can of course turn
18:37 off
18:38 stuff uh so there's going to be
18:40 something called node which is what the
18:42 article is and this is available here so
18:45 this doesn't have anything yet but it's
18:47 going to soon have something but say
18:50 that I want to make this a little bit
18:51 nicer
18:53 now what I can do then
18:57 is
19:00 uh the
19:01 following take some time so that's what
19:04 I am using this Json API extras for that
19:06 I
19:09 enabled see here if we do
19:16 admin we go
19:19 to web services here Json
19:25 [Music]
19:27 API
19:38 and so this do take some time but there
19:42 we see it's finished let's see if we
19:44 have a picture also that this nothing to
19:46 do with ob as I said this is a very very
19:49 bad prompt to be
19:52 honest but you can see here at least it
19:55 has generated all the article paragraphs
19:58 and you see it generated it then one by
20:02 one and you can read it here Obama and
20:05 his connection to his poetry and so on
20:07 since I didn't add any context of course
20:09 it's making up everything anyway here we
20:12 have the Json API settings then we're
20:14 going to accept create read and
20:16 everything right because we need to
20:18 create over the API it's under Json API
20:21 but what we're going to do now is we go
20:23 to the
20:25 article so here you can hide different
20:27 end points that you don't want to show
20:29 right so I'm going to put this under
20:31 Articles as the resource type article
20:34 I'm going to hide a lot of stuff so we
20:36 just want the uid because that's what we
20:38 work with in Json API and as I said Json
20:42 API is just one version but the
20:44 advantage of Json API and why I wanted
20:48 to show this is that I don't actually
20:51 have to develop anything to enable
20:54 it
20:57 uh
20:59 and then you see here if you use the
21:01 field UI for creating fields in Drupal
21:05 it prepend everything with field which
21:08 is not so nice so you should really not
21:10 use this if you need something scalable
21:12 you should rather uh write this in code
21:15 but of course for most use cases you
21:17 don't actually need to scale that much
21:19 so it's it's a nice Q is solution you
21:23 see there's a AI interpolator status so
21:25 this basically says the status of the
21:27 Curve
21:29 processing so I'm just going to call
21:31 this status to have a little bit nicer
21:34 name to it if I reload now it's going to
21:37 be gone because as I showed you we moved
21:40 it to
21:41 articles we're going to look for file as
21:44 well because there is a image connected
21:46 to it right we're just going to do the
21:49 same here to nien it up uh so it is uh
21:56 now stored under files instead and it's
21:59 called a file let's see here we need the
22:02 URI basically that's what we
22:06 need and if we save this now what we can
22:10 do is using Json API then
22:12 for uh let's see here including
22:20 stuff where did you go here article
22:24 file so I'm going to include the article
22:27 image now
22:28 now and then you can see it has included
22:31 the image here also so if I go to this
22:34 one I
22:35 should there are ways you can make it
22:38 absolute but yeah here you have the
22:40 image
22:41 [Music]
22:44 then so now we have set up everything we
22:47 have the API there's one more thing I
22:50 need to do now so there is
22:53 uh uh authentication module for API in
22:56 Dro B uh from
22:59 oh mini
23:01 Orange it's here even I have it in
23:04 history so it's called rest API
23:06 authentication so there you can set up
23:08 any authentication layer you want right
23:11 so all jot tokens
23:14 everything however in this case I don't
23:16 want to showcase this this take some
23:18 time so what I'm going to do instead is
23:20 something you should definitely not do
23:23 that's that I go into permissions
23:26 here and here you can control who can do
23:29 what so we have a role called content
23:30 editor and they should maybe be able to
23:32 create new content but what I do now is
23:34 I I allow anyone to create
23:37 content uh I can just show you before
23:40 because I have my Json API
23:44 here where I'm going to then send to the
23:48 same endpoint Biden likees poems right
23:50 so if I send this now you're going to
23:53 see it's forbidden
23:54 403 but if I save now because now I
23:58 allow everyone then I can save and you
24:02 see it starts uh responding
24:06 basically and the problem now then
24:09 is this nothing happens right takes
24:13 forever because it takes forever to
24:15 create this and if I go to the Json API
24:19 end point it hasn't actually generated
24:22 anything it's still just Obama article
24:25 here so there's no way for me to pull to
24:27 check someu status as well but it
24:29 because it has actually not written
24:31 anything to database yet and this is
24:34 then where the post OB processor comes
24:37 in and where it uh does its job because
24:40 the what the post OB processor does is
24:43 the following first of all OB then it
24:46 stands for output
24:49 buffer so it makes sure
24:53 that Drupal does whatever Drupal does
24:56 right if this is Json API graphql or if
25:00 you're even using the GUI it make sure
25:03 that it finishes everything like it does
25:06 normally which means it has saved the
25:09 article it just hasn't run any a AI jobs
25:12 on it and then it makes sure that this
25:15 is getting processed
25:18 afterwards so the PHP process continues
25:22 uh running it just outputs the buffer
25:25 and tells your web server and J X Apache
25:27 that hey I have a answer for you here
25:31 right output this answer and then I
25:35 continue processing here in the
25:38 background uh and this is of course very
25:40 good for the use cases where you want to
25:44 run the API command get a uu ID back
25:47 well uu ID then when we're talking about
25:49 Json API depending on what API uh
25:52 standard you use and then pull on this
25:55 until it's
25:56 finished so so that's what we're going
25:58 to do now we're going to
26:01 um enable
26:10 this uh so we have enabled this and what
26:13 we need to do now is go to our content
26:15 types again and manage fields and then
26:18 under the process
26:21 workers we have post output
26:26 of
26:31 so we just save
26:36 this go back to our
26:40 example here you can see by the way it
26:42 has generate
26:45 something we can just for the fun of it
26:47 by the way reload and take the second
26:50 file included
26:52 here see how Biden
26:55 looks still doesn't look like like B him
26:58 but at least it's a old man so it looks
27:00 a little bit maybe like him
27:03 so anyway what we're going to do now is
27:05 we're going to run Trump likes
27:08 poems and we're going to send it and
27:10 then you're going to see oh there's a
27:12 response directly so this is what the
27:14 post op buffered uses right so now what
27:19 we can do is
27:26 this
27:30 so I forgot the S there I think let's
27:35 try there we go so you see it's still
27:38 processing right because this is going
27:39 to take some
27:41 time so what we can do now is that we're
27:44 just pulling this until processing is
27:46 done
27:48 right um and this is what the post OB
27:52 processor does then it makes sure that
27:56 your API service basically works like a
28:00 API service should
28:02 do I will say that I can also add on top
28:06 this of this if someone does a feature
28:09 request uh that it could send
28:13 a web hook as well when it's finished so
28:17 you don't have to sit and
28:21 poll but that is of course yeah
28:24 something we can add later so now
28:26 finally you see it's status is
28:28 finished we have an output
28:31 here
28:34 um and that's basically
28:39 it it has generated
28:42 something
28:45 um can look at the image I guess by
28:49 include article image we called it I
28:54 guess yes so you see that that was
28:56 included did as
29:00 well uh yeah well he looks very pretty
29:04 there Donald
29:06 Trump
29:07 so that is basically it this is what
29:10 this module does it opens up uh the AI
29:13 interpolator to be very flexible to work
29:15 with other
29:16 systems where you can set up the
29:19 workflows in the interpolator but not
29:24 having to use Drupal if you don't want
29:26 or if you use Drupal and want to offer
29:28 this as API
29:30 service you can do this as well so
29:34 that's it thank you for watching and I
29:37 hope you like it and if you like it
29:41 please use it it's free open
29:45 source and any feature request you can
29:47 think of any bug requests just add them
29:50 to the to the drost website thank
29:56 you
