Create a ChatGPT bot using Microsoft Bot Framework v4 with OpenAI | Azure Bot Service | C# SDK

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back to JD Bots in this video we are going to explore and create the open AI chat GPT chatbot for the Microsoft teams Channel using Microsoft bot framework so chair GPT is a new Revolution in the generative AI so why we stay behind when we can Implement that using the Microsoft bot framework so as you already know at this point of time chat GPT API is yet to be released so we can use the open AI gpt3 apis like text completion to build our chatbot so let's go ahead and set the things up I'll be going through some of the first documentations so this is the text completion end point that we'll be calling from our Microsoft board framework chatbot all right so if you go to the API reference here and click on making request so this is how we'll be making the request this is our endpoint this is a content type and authorization API key API key you can get it from here view API keys under your profile and this is the rest request body it has some required fields that is what is the model that you want to interact with since we are interacting with the text DaVinci which is the most powerful as of now and we have to give the prompt that user has asked and the temperature and the max tokens all right so let's dive into so yeah so this is what we'll be building we'll be making use of echo bot template and this is what we modified that open AI where I just ask what is open here it gave me response even I can ask code it gave me some response I have set the max tokens to 100 words 100 tokens that is why it has just given me only this person this much response but yeah this is how it will be look like okay all right so let's dive into and create our project and I am going to make use of echoboard template and which is I think Echo bot yeah here it is and let's give its name as chat GPT teams bot all right and let's create the new project all right so before starting let me run this project and show you in the emulator and here we have hello and welcome hi Echo high so this you already know so now let's go ahead and modify our part all right so these two methods you are only aware of hello and welcome this is a welcome message so I am just going since we are developing it for the Microsoft teams Channel so let us try to greet the user and hello and welcome and here we'll just let's store the user's response to input prompt so basically this property will be used to send to our open AI API and whatever user has asked we will be just storing that to this particular input prompt text and now we are going to call our method that is result response equals to let's call completion API Handler all right and here we'll be passing our input from text and that is all so let me create a method out of this and since the return type will be a string it can be null as well if we are not able to communicate with the backend servers then we might get null as well all right and yep so let's add some try catch and also here let's add this condition if it is not equals to null what happens and if it is equals to null what should happen let's suppose if there is an exception then we can just send null and in order to handle that null we can just have a else part and we can send a response turn contacts dot send activity message Factory dot text and here the response should be let me copy this and paste it here and here all right and here our response should be I am having some trouble communicating with our servers please try again later all right okay so this message will be sent to the user if you are not able to authenticate or some error occur during our API call then we will show this message correct and now if at all everything is fine we'll just show the input not input basically we have to show this message that is result response okay all right and let's get rid of this particular response here we can just call our API right so I already have a piece of code which before that uh in our app settings.json file we have to add few configuration for our open AI and let's say completion endpoint here we have to add our completion endpoint and here we will store our API key okay so let's get the completion endpoint so I'll go to the docs and here under API reference making request so this is the one for the completions and API they're like others as well based on the models and this based on the like if you are generating an image then you can use the image generation endpoint yeah by the way let me show you that this is my image generation this is being developed using the same open AI image generation API and I can just ask anything to the bot for example uh smart phone dancing in the rain this is my input prompt and let's see what image is generated by this bot okay it is processing something [Music] oh perfect it does something really cool smartphone dancing in the rain here we have some smartphone and some rain okay all right basically even this can be implemented in the same bot but for now we'll only focus on the chat GPT only for the text generation all right yeah so we were just getting this end point and paste it here all right okay and yeah I think that is all is required let me get the piece of code that is used basically that is basically used to call the API in C sharp it's a common C sharp code and I'll get it from my own repository for the image generation bot and by the way if you're looking at this you can call this particular piece of code for the image generation as well this has been implemented so here I'm just creating HTTP client and here we have to include our configuration to include our configuration let's initialize that into the Constructor all right now we will be able to access all the configuration property from our bot source code so let's say configuration and this is how you can extract here you just have to add the key since our key is open Ai and this inside open here we have completion endpoints so first you have to include open AI colon completion endpoint all right and this is a content type application slash Json and here you have to include your API key again same way and this is API key all right and this is the place where you since this is a post request you have to mention that and this is where we create our body content so let's go to the official documentation and let's copy the whole and replace it here all right so this is the model that we are currently targeting text Darwin C 0 0 3 and currently it's the most powerful gpt3 model and we have to pass the prompt let's get it from my parameter that is input prompt text and temperature and Max tokens let's skip it 100 for now okay and yeah so this is the place where it sends the response since this is a a synchronous method let's add that here is we are just checking if success status is there and just storing the response into a string variable and then converting that response to a Json object if two parts the Json properties so before passing that let's add one more condition if Json object is not equals to null and one more property if we are able to get the response property is not equals to null this is for the image generation let us see for the text completion so this is a sample response that you will be getting and your response is under choices under choices it's a array under array first element and we have the text so let's include that choices and we are first checking if it is not equals to null then we will store that here let's directly return that return string Json object choices the first element and text all right then let's get rid of all of this piece of code that was only for the image generation bot then we just return null all right if we do not find this property we return null okay and yes we are done with this one Let's test this out on the emulator first and then we will try to deploy it to the Microsoft teams I think for the Microsoft teams you can look at my previous series uh what was at Enterprise bot series for working with Microsoft teams but I think for now let's first test it on this one uh emulator because if we are doing for the Microsoft teams we have to create all those different resources Azure bot resource and connect that to channel and many other configuration okay so let's first test it on emulator it will not work let's see the error message because we haven't provided the API key and let's ask something who are you let's say let's ask something about what is open AI and here you see I am having some trouble communicating with our servers please try again later so this is a error response that we have provided because we haven't given the API key so let's add that API key let me create a new Secret and let's add it here all right now we'll be able to communicate with our part let's restart the conversation let's first greet the bot hi oops it is its responses in this one code because once I have asked the bot to basically give a C sharp code but let's see how are you foreign I am also fine that's great okay let's ask something else uh do you what do you know about what do you know about AI future okay I expected to have a major impact on the future of humanity I expect to and yeah since I have included Max token as hundred so it is just giving me under 100 tokens if I modify that to let's say even you can configure the max tokens just add the new property here let me modify that to let's say 10 let's see how it behaves for the 10 tokens what do you know about AI Bots okay perfect so it has given me a response within that 10 tokens that's pretty cool and very exciting okay this is all about if you want to deploy this bot to the Microsoft teams Channel like how I have done it you can visit my previous Enterprise bot series and learn it from there okay all right see you thanks everyone
Info
Channel: JD Bots
Views: 11,884
Rating: undefined out of 5
Keywords: open ai, openai, chatgpt, gpt-3, gpt3, ai, chatbot, bots, microsoft bot framework, azure bot, ms bot, c#, microsoft bot, azure bot service, bot builder sdk
Id: S1ZYuWAO564
Channel Id: undefined
Length: 18min 51sec (1131 seconds)
Published: Sat Feb 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.