Build ChatGPT in Power Apps with Azure OpenAI and Power Virtual Agent

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today we're going to build our own chat GPT into the power apps using the Azure opening AI we will deploy our own models and using a power automate to call our API in the power virtual agent now let's see how we can get that into the actions first go to your Azure open AI make sure you have the prescription so we'll create a new resource let's call it how can use the existing one that's fine choose East us and give it a name records chat GPT PVA demo I'm going to select a price tier and go next I'm going to select all networks but you probably won't do that if you are building this for internal corporate only gonna clear create and now we wait once it's done let's go to the resource so now we are in our Azure Opening Our resource next thing you want to do is deploy your model so let's click on this go to open a studio we'll go to deployment maybe just click here create new deployment we're going to create a new deployment and the model we're going to choose is just GPD 3.5 and we'll give it a name GPT PVA am I 48 now that didn't take long and we can open this and this is our demo opening the playground you can try some basic prompt you can chat with it we don't have to select the system message remember from GPD 3.5 and the four you can you can define a system row just basically tell what what type of boy is going to behave for us it's called the system message right here you can just start typing your message and chat with it hello API deployment for this resource does not exist if you heard it within the last five minutes please wait okay so we'll come back and show you how you can use this now it's about five minutes let's test it hi to the bot is responding okay explain quantum physics to me like a child okay so you can see this is just a gbt basically 3.5 but within Azure tenants okay we're not going to make much modification to it because our goal here is just to bring chat GPT into our power um virtual agent and um to use it with Azure open AI model internally so we're not gonna put too much boundaries on the system row and you can see this is actually all wrong we don't need these are just a message I typed uh not actually it's not wrong so the raw system row is your content and this now it is wrong raw user row system raw user row okay that is not wrong okay this is just basically what's happening in this chat window and uh yeah that's all we need to know just look real quickly to show you a few difference in the public open AI this part we just saw is very similar we'll decide we'll Define the system row then use a message and this is the response from the model and what's different is for example and this article talks about how to switch open Ai and Azure open AI actually you can see in open AI we know the key API key is start with SK and we usually put a Bearer in front of that in Azure opener you just it open AI keys right there and of course the endpoint is different if we have a look at this the endpoint will be you're going to copy this as your endpoint which we're going to use later in the power automate and this is your API Keys okay first through for it um for those of you who are interested uh somebody asked what's different between Azure open Ai and open AI I think most of you if you are looking into this for the company you will most likely worry about where the data sits right so here the data submitted to the Azure open uh opening so it remains with Microsoft Azure and it's not passed on to open AI right so my understanding is your company has your own Microsoft tenant these data should stay within your tenant and they are not used to train the action model and also it's not a puppet model you are using your private model with your Azure or bank account which also sits within the tenant and I can paste this link in description which explains the data privacy and security for Azure open data services okay now we've got our own Azure open air model deployed it's time to test it the quickest way to test it is to call the API from our power automates flows now at this time we'll do something different compared to the previous videos we've done this time we're gonna do everything within a solution okay so let's just start a new solution from powerapps and let's call it azure open um put chat PVA demo select a publisher I had a one create you can use default and just go create so the reason we want to use solution is not only is easier for us to deploy it from Dev to prod also instead of using the API Keys directly in the flow we're going to put into environment environment variable which you have to do it within solution and everything you do today will be in the same Solutions okay so first let's go new and create environment variable to hold our endpoint URL and our API keys called GPT model description we'll have endpoint URL and API key and we're gonna add a Json format so you can create text and put your API key here and create another variable to put endpoint here as a text but I'm just going to create one variable having two different values in Json array if you have a look at my blog this is for the Json array format should look like so here you're going to paste between double quotes your API endpoint that I showed you before and here is just your API keys and we're going to paste the whole copy in the paste whole thing into the environment variable now we got the value in save it next we will create a power automate just to test that model works and later on when we create our power virtual agent we're going to call the same flow and just make some modifications with the input and output okay so we go to new go to automation call cloudflow let's try instant flow we're just going to try a manual input and we'll call it chat GPS demo I just quite everything so if you did a manual instant Cloud flow like just outside the solution but you have to create solution the variable inside the solution you will not be able to import this flow back to a solution there's some limitations for the certain trigger flows so you have to start this flow within your solution okay the menu trigger we're going to say we're just going to provide you the input that will serve our user questions that we're going to pass to the model next we're going to do the HTTP action some of you will remember this when we did our very first video also creating chat GPT within with the power virtual agent but we use the public open air model not the private one now most of these are the same you're going to use a post now you're going to use this URI which is endpoint of our model now you've got just paste threading but here we're going to use the parameters that we grabbed from um environment that are variable so when you highlight here you can see the parameter came up as your open AI now this is the old one created before all right so this is the one GPT model that's the one we just created okay but now we're not going to just click here and put in here because remember this variable we had a two value in it it's a Json for uh Json array there's two values in here we're just gonna reference to the endpoint so we're going to use an expression the expression you're going to use is just the parameter and in here we're gonna pick Dynamic content and then pick the environment variable we created and then we're going to reference the endpoint here which goes to the first value of the Json so we go okay invalid parameters too many parameters so let's get rid of that parameters like that and I'll click on me that parameters brackets brackets okay and then we copy this and then we're going to put into this API key again same variable but we gonna reference a different value if you remember that our value is called API key so okay now this is the body and if you have look at what we've done before and even with open your documentation it is exactly the same here you're gonna just put user role which is use the message the content and we're gonna pick um from here the dynamic content of the input so we're gonna do that by the way you cannot add a row for the system here for some reason every time I add it and I go save it disappears so looks like in this core in this body you can only just pass the user messages to the model all right let's save it and we will do a test quick manual test click on the test will provide a menuing query to the model what do simple how many days in the front so this input will be supplied to the body and sent to the model now we expect a much quicker response stun because we are using our own private model within azure we're not calling the public model which have some capacity issues during the pick time so looking at let's click on this where's my raw output anyway there are 365 there's instantly however in leap year that's 366. okay so this just quickly demonstrates our flow is working with Azure open AI jpt3 model we just deployed next let's build our power virtuations so click on new chatbot remember everything we built today have to be within the same solution okay so this should load our power virtual agents web interface and we'll call it chat pptpv demo we're not going to use boosted conversation here so just go create now the idea is we'll try to replicate the chat GPT with power virtual agent so we're not going to build any topics what we're going to do next is gonna is we're gonna modify the system for back topics to link that with chat GPT in the flow basically pretty much whatever you're typing it should trigger because we don't have any topics it should trigger the fallback topic which caused the flow that make the API calls without Azure opening air models okay so let's go to our topics let's turn off this topic that we don't need one two three come to the systems and we will add it there's four back topics previously we have talked about this and unfortunately there are still no better way to achieve this short memory that make the Bots to remember the conversation history we know chat GP automatic does that but also has a limit when we try to build a chat jbt like bot within the power virtual agent we need to replicate that and the way to give the bot the shorter memory to remember the context is to pass all the previous questions and answers together at the whole conversation history plus your new questions to the API call okay so to do that first we're gonna Define a This Global variable we'll call it compensation history and we initialize it and with empty string then you want to add your first you have a question and then we're gonna make the API call so we'll call the model once we got the response back we will append the response to the variable so now the variable has the first question and the first response now when we look back when you ask follow-up questions will add I will append questions to the variable and then we'll call the model get the response then append response back again you get the idea so the key is we always want to use this Global variable to make the API call which always keeps the conversation and the problem with that is eventually this variable will gross or large that hits the token limit for the model okay now there are other way to solve that it's not what we kind of discussed today so we're going to leave that the system fallback topic kicks in when we couldn't find any match to users questions okay so the trigger is aren't unknown intent and you can see in this building fallback flow there are a fallback count if it's less than three then trigger this message I'm sorry I'm not sure how to help then on the other conditions it will go redirect and escalate right we not going to replicate all of that um I'm going to do that for another day for now let's uh Delete all of them and just build our own fullback which basically we want everything that user asks goes to the Open Air Model to do our API calls with the power automate okay so let's start with a variable and we're going to make a new one let's call it VA conversation and we're going to make it a global variable okay now what's the value as we said before we're going to initialize it with the anti-string okay so that's step one step two we're gonna add users first question to it now remember we are not asking because we are not triggering any topics so we are not asking capture users response so we will use another method just to capture what user just typed in go to the variable and then we're gonna set the same variable again so pick the variable which is a global the VAR conversation and what value we want to give it to this time okay so we wanna just add the user's response to it the questions to it so Global variable so we just pick that one which at the moment is empty string is nothing there we're gonna add um just give a space and we're gonna add user's input but because within art user a question we can capture the response at the entire response like we normally do within topics what we're going to do is here's your SQL weapon it's called the system.activity.txt basically it catches those unintended user input and now we added this substitute here which just removed unwanted text so let's go insert right so at this stage we have created a global variable started with nothing and then we add it the users first question to it what's next we're just gonna call the flow we just created foreign Plus action figure out Floyd and we're going to pass the input which is our VAR conversation so we'll pick that this our glow variable remember we're always going to pass this variable to the model and then we'll get response back from okay let's not to map this yet let's go to our flow so the one we look at is this GPD flow we've got edit so we need to modify our inputs and outputs from oh it's already updated for us that's pretty good Okay so query this is the input it's going to come here called the model that's great fantastic there's not much we need to do we're going to pass this response back so if we switch to back to our fallback topic the responses are being mapped let's write the user message back to the console so we'll go to send a message and then we'll pick the variable which is the response it's been passed back simple as that and don't forget the last step we need to do is we need to set the variable again by appending the response back to the global variable so we're going to pick up our Global variable and value what the value is going to be this time let's go to the formula so the value will be itself which is global dot VAR and what we're going to add we're gonna add the responses got returned which is the topic that response we'll go insert save and then let's test it here we come to the bot now because we didn't Define any topics so anything I typing here I'll expect it would trigger the fallback topic and send to the GPT model by our power ultimate flow so let's say what is the biggest country in southern so the atmosphere like that let's see where the hour first How uh topic will be triggered you can see the fallback topic trigger triggered triggers oh well it triggered that was really quick that is very fast the large country in the southern Hemi is Australia okay so it works and if we come to our power flow ornament flow you should see the runtime one second fantastic so now you can really see the power of azure open AI model because this is your private model within your tenant even though they might not in your region but the performance is much better than you creating a public open AI model now let's see what he remembers the conversation history so let's do not mention Australia again let's say what's the biggest economic five for it Atomic Drive does it make sense okay you can see quickly it triggers the action power ultimate wow however the biggest kind of driver for any industry may vary for example um well it didn't really say Australia let's ask again what's the pop you translation population I'm sorry I need the more information so this just proves the bot has no context there's no shortened memory and I wonder why if we have a look at our fallback notice every time I ask a question it will trigger the fallback as new it starts from this top top of the Top Line and the first thing we did is empty variable so every time I ask a question is keep amp emptying the variable with no context of course when you call the API by the flow the bot has no idea what you're talking about so what we need to do here is we need to set a condition here we do not want to send we do not want to set initialize this variable as empty strip every single time okay why when the we want to win this up go back so we want to add a condition here meaning not every single time we want to empty this variable they do it it didn't do it okay that's okay let's just start here go out of condition so the condition is going to be we're gonna check this Global variable we're going to check whether there is information in it if it's not blank if it's not blank that means there are some compensation history there and I'm not gonna I'm not gonna initialize it with empty string so our life flows through but other conditions in other conditions I am gonna initialize it just like this node and we'll delete that so we will select that and we'll empty it or we can delete this okay so this is our update flow what does that mean every time you ask a question it will trigger this fallback topic from top to bottom start over again however this time we're gonna check whether this conversation variable is blank or not it is blank that's fine we fold under all other conditions then you will start with empty string that means we'll start a new conversation but if it's not blank we're not going to go through this root to get it cleared out it will just go straight to this node which is adding users next question the system activity text to this variable and the code is flow to do our chat GPT our GPT model API calls now let's test it out so where you ask another similar question let's say we said this what is the youngest country in the world let's see whether it will hit the topic well it went through quarter model oh wow it's back already South Sudan okay now let's ask a follow-up question what is the population of that now if you cleared the common searching variable you wouldn't know what we're talking about but this time it will okay okay what language do they speak mainly again if you didn't remember the competition history you wouldn't know what the questions the official language of salsana is English language okay so you get the idea now we are not clearing This Global variable that holds our conversation history that's how we give the bot a shorter memory now before we wrap up I want to show you one more new preview feature how easily we can bring the power virtual agent we just created into the powerapps so to do that make sure you publish your bot already in the power virtual agent next go to your power apps let's create a new canvas app records that gptpv demo will make it a phone layout and just remember this is a gated preview you have to apply for it and at the moment I believe it only supports canvas app let me show you how easy it is to bring your PVA bot to the canvas app all you need to do is click on insert under the input scroll all the way down to the bottom it's not there what you need to do is you need to go to settings go to the upcoming feature look for chatbots component turn it on come back here try insert input again here we go this is the chatbot feature just need to drag it out make it fill up your full screen and pick the Bots that we created from the power virtual agent which is this one PVA demo pick that it just automatically picks up your schema name is here there's not much to do here and that's it this is how easy it is now let's play it and say tell me about days in the month thank you now it's just gonna bring the whole PVA bot down call the power automates use a flow to do the API call without opening our model here we go it is that easy now I just want to touch on the multi-language support real quickly since this question has come up many times among the community power automate sorry power virtual agent already support tons of language as you can see from here all the major language you can just type strain to it there's nothing you need to do and you probably already aware that open AI model has multi-language support as well in the chat GPU you just need to type whatever language you want to say my major language and it will respond accordingly so if we come back to our demo we can just type in so here is Chinese please tell me about these scientists background so not only it can switch between among different languages it can carry on a conversation this is quite amazing um well that didn't do in Chinese but I understood my question let's do that again so close here crochet data basically I'm saying please tell me about this sound this background again in Chinese so this Hub is should respond in Chinese and then we'll try another language okay see so the name is kept as English fantastic that's what I want and just explain every uh scientist's background where they're from what they do in Chinese perfectly next I'm asking in French um what was the result what outcome did it lead to as a result of us creating the first atomic bomb now I would understand this but we'll probably putting the charge GB to translate but for you folks who understand French you probably tell me and I believe it's correct once you are happy with the app don't forget to publish once they've been published we can go back to our solution and include the power app into our Solutions so did it do it let's go back go to solution open the solution up add existing apps cameras app outside of database let's pick this one go at and now we're done with the whole solution and if you want to deploy it to a different environment you can just export a solution to a zip file here comes to the end of our video so today we have created our own chat GPT and wraps it up into a powerapps we created a power virtual agent with our own Azure open air model we call Api in a power automate flow we also used the power app Solutions and environment variables in the end we had a brief look at multi-language support which shows the capability that you can just type any major language into the bot and the bot will respond hope you enjoyed the video and I will see you next time
Info
Channel: GPT Odyssey
Views: 3,465
Rating: undefined out of 5
Keywords:
Id: 4KJ4Vc3Qdok
Channel Id: undefined
Length: 39min 55sec (2395 seconds)
Published: Thu Aug 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.