ServiceNow and GPT3 Poetry - How it works!
[Music] [Applause] [Music] [Applause] [Music] [Applause] thank you [Music] hey everyone it's Justin thank you for watching and welcome to my house that's Justin's house in this video I've got one more behind the scenes video we're going to talk about my Integrations with open AI where I pull an image from Dolly like you see there right beside me and if you've paid if you've watched those videos the other fun part or fun part was the poems that were coming in is this something I added on at the last minute especially for Connor because I had a feeling he'd probably seen this image stuff before and I really wanted to surprise him and chat gpt3 had just come out like the week before I was scheduled to record so I was like hey I should be able to repurpose what I've already done and then have it generate a poem because they were able to do things like song lyrics and stuff like that so what I did is I came in and I created another action you can see that other action in my workflow in a previous video I'll put a link up above to the previous video but I've kind of stepped through this request the image and how I was requesting that image for from the rest integration so in this video I want to talk about this query The DaVinci model The DaVinci models what they call the text DaVinci model for this particular way to talk to the to the open API or open AI and um I did actually a script for the action so um the the action requires a text prompt right what are you asking the AI and I said basically I want to write a short poem about space and then take that description that was getting from the catalog item where they were putting in like show me a dog playing outer space with a flying pizza and all that stuff so I wanted to attach that and just to pre-pend it with write a short poem about whatever they said in that box and then return it that way I'm just using the same thing they did and then the poem should be similar to what the image is right so that's the custom action for The DaVinci model so if we look at the action itself there's two steps to this one the first step or the inputs are the text prop which you just saw in the workflow the second step is to make that rest query so again we're going to api.openai.com V1 but instead of the generate image endpoint I think it was the word looking for in the last video we're going to use this slash completions endpoint and I'm going to pass my application slash Json as my content type my Bearer token as my authorization but in the body text my model is now text DaVinci oath O3 which is the new model that came out my prompt is the input prompt that we just got up here in the inputs so I'm using that right here the max token size this is basically the way open AI is structured and the way that they offer you free tokens and then you use up the tokens as use the API and then you can buy more tokens that's how they make money you would make money in this if you were like making an app and generating lots of poems or lots of images like you see some apps doing in the uh the iPhone or not Apple and Google Play Play Stores so tokens is basically saying hey you could return me a poem that's 10 lines long or 100 lines long I don't know how I got to this 2048 number somehow I got to that number over and it was a decent sized poem that didn't take a long time to read the temperature when you're dealing with open eyes basically how wild or Innovative crazy you want it to be like do you want it to be and I can still can't remember you'll have to go look at Open Eyes documentation 0.9 was somewhere around uh could do some fun stuff for me but trying to stay out of Crazy Land is What I understood that temperature level to be but you can go from point one I think all the way to 0.9 or one uh I think is the zero to one is the Spectrum there and then the number of responses to generate was one so that did its work and then this time I got to use my Json parser step which is a step you can use or step within your action you can use that's out of the box right so you don't have to write any scripts all I had to do was take some sample Response Code from that open AI query and paste it into here and then it generates this object over here on the right hand side that's not too much behind my head so let's shrink it up here it's basically saying hey I see there's a root node which is this guy it's starting with number one that has everything in it and underneath that root node we've got ID object created model and then I've got another array of choices and I've got another object for usage so you can see that there here's the array of choices in my example there's only one choice being returned and I've kind of hard coded into that rest query that you saw there I'm only asking for one poem and then this usage is just a usage object so I was able to just use this button to generate the target it generated that over here on the right hand side automatically for me that was the extent of the work as part of that and then I just say hey for the outputs I want you to have an output called DaVinci response let's go ahead and edit this so my output is going to be called DaVinci response and it's going to be an object because that rest query in that Json parser step are returning an object to whatever calls that action so if I exit edit mode I was able to just go here let me move my head out of the way I was over here to go to the Json parser step and say hey take that root object and click and drag and drop it into the DaVinci response output variable and then once that's in the output variable I now have it in my flow so if you look right after my query DaVinci model I have a for Loop in theory there could have been more than one right I could have had more than one and also that object is kind of structured that way so in the for loop I go and set the flow variable image underscore poem to the value of the text that's inside that objects now I did some concatenation here here's a short poem about the requested image colon space and then appended concatenated the text that was returned from the AI so that when you look at this in the notes Here it looks a little prettier rather than there just being a poem with no explanation now it says here's a short poem about the requested image and then there's the text a honey badger and a bowler hat dot dot so that was the extent of the integration for the poem part of it and I'll tell you when I did the image part of this it didn't take that long for me to figure out the interface and get everything connected maybe let's say an hour tops to do this da Vinci model I did it while I was watching TV so I shared this with you to show that this stuff is not that hard it's it's actually pretty straightforward it's pretty well documented on how to do these things how to do things simple things like concatenation that you see there how to use that Json parser step and I think you can go away and do something really cool by having AI generate something useful for your business useful for your application useful for your workflow maybe even something like marketing where you saw there I'm not sure what you could use a poem for other than to entertain people on YouTube like we did here but having said that I hope you found this video helpful if you did please like Please Subscribe or share it with somebody who you think might be interested in integrating artificial intelligence with servicenow and having a little fun until next time don't forget to always be learning foreign [Music]
https://www.youtube.com/watch?v=q1yFoxLyieI