How To Integrate ChatGPT in ASP.NET Web API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys welcome to digital Tech join welcome back I hope everybody is doing good and enjoying the videos that uploaded in my channel in this tutorial we are going to learn about integrating chat GPT and AI based chatbot developer open AI company in asp.net web API so let's go to open your website so here this is the link of the open openair website so open ai.com and once you type that you need to sign up and once you sign up you will have access to your API key which should be generated that will be used in our asp.net web API project so let's go to API reference so once you click on developer API reference you are redirected to the API reference page here you need to just do sign up if you are not having an account so you enter your email address and password and you'll have to enter your mobile number because open AI what it does is that to authenticate the validity of your mobile number and the user they send either an SMS or they also they can also send a WhatsApp code which is which is required to complete the registration I already have my account so what I'm going to do is that I will login so click on login and I'll enter my email address dot com and I'll continue with the password [Music] so I've logged into my account so here if I go to the top right hand side and click on my profile and here you can see view API keys so when you click on The View API key so I've already created an API key which I use for to create that demo project now here you can create one more API key you just need to click on create new API key and say digital diction any name you can give and you say create so once you do that you need to copy this key and save it so this key will be used this is a format of the key and this key will be used in our project so here's the format of the key which will be used I've already generated one key so I'll be using the the previous key that is this key which is there in my project I'll use that key now what we are going to do is that once the key is generated we need to go back to our Visual Studio 2022 and create the web API project so once the key is generated I am going to open my project knee project and I'm going to select ASP core web API you can type web API so I just type web API and you will be able to see asp.net core web API click on next so I am just writing chat GPT demo and click on next the next place I am going to keep configure over https and dotnet Frameworks 10.0 make sure that you enable open AI support and click on create the project template is getting created yes the project template is ready so the first thing we are going to do is that install the required nuget packages so I click on right click on the project manage new hit packages and I search for open AI and this first one open AI by ok go do LT so this is the one and version is 1.7 that you need to install so I've installed this package so package is successfully installed now we'll go to our controller folder we'll expand it right click and add a controller so we'll add one new items and it will be not a controller but it will be the apis I'll just select API controller empty and I'm going to name it as home so there is a I'll just delete and I create once again say add new item I say empty you're not supposed to delete the controller so I just write home okay fine so it's home controller my controller API is ready and here I'm going to write so before I go ahead and I just use a reference openai Dot completion and using [Music] open here so these two libraries have statements have included in the using now we'll write a code that will actually take input from the user or in in a web API and then return the result using the chat GPT so this method will be in HTTP post it's public async task action result and just get AI based result and this will be search text this will be the input now string API key I'll use the API key that had already generated and saved in my notepad I copy this paste it so this because my API key string answer the phone I'm setting it as empty where I declare open AI variable and here I see new open AI sorry open AI API and I pass the key API API keys this is the first step and then I declare a variable called completion result completion equals to new completion request now this completion request will take the input of the search string to prompt and then Dot model now this is a engine that will service us and respond to our AI queries so through AI it will respond to our queries dot models dot model and we are going to select DAV and CI text finally we need to give the max token press set to 200 so this is a result length and where result is open in a variably DOT completion dot create complete completion async and I pass the variable completion with all the parameters model prompt and token so once the request is hit to open AI like AI based API we need to Loop in and fetch the record so where item in result and then we will see answer that is declared over here equals to and then we return return OK and answer so our code is ready so this is result not okay result Dot result Dot completion yes this code was missing so it'll Loop in through all the result and assign that to the answer variable in the written so this is the small piece of code that we need to write to initiate a request to open AI Library so let's run the project now so it will open this weather and we'll be able to see the home controller and the method get eibase result yes we can see the home controller and this is the weather forecast my default this was included in the template so now let's expand this and let's try it out click on the button let's see what is asp.net let's let me put a breakpoint over here and let me exhibit it so this is a key now we're opening the connection we have opened the connection we are passing what is asp.net we are setting the model max token and here we call the result and we Loop into the result and we return that result to our API and here you can see the result is response over here got it so let me try one more what is database execute and remove the breakpoint is executing and here you can see it is return the result let me also try what is the weather of Mumbai it executed this code and is able to successfully display the weather as well so now you can consume this API this is already an API you can consume this API in your application you can create a usb.net MVC application and you can provide this interface to you can consume this API and allow the user to ask for any queries that will be returned by the API so consuming API is already created a video in my channel which actually talks about consuming web API in asp.18 MVC application I will add a link of that in this description as well as at the end of the video you'll be able to see that video as well so guys this was a very short video on how to integrate chat GPT in your application and remember one thing it has some limitation if you there is some certain period and certain rate limit that is included so if tall you come across any issue with too many requests and you know all those stuff then remember that it has some limit if you go with with the paid version then you will not get those issues this I just wanted to inform so that uh whenever you face any issue don't think that it is a code level issue it is only that it is it has a rate limit and the number of limit provided for the eating the open AI is exceeded so guys thank you very much for watching this videos uh please do share my channel link with your friends colleagues and family members help us grow our Channel like our videos and do like and comment our videos thank you so much
Info
Channel: Digital TechJoint
Views: 10,836
Rating: undefined out of 5
Keywords: chatgpt, chatgpt api, openAI, web api, chatgpt in c#, integrate chatgpt in web api, integrate chatgpt in asp.net, chatbot, AI based chatbot, AI integration in ASP.net, asp.net chatbot, asp.net chatgpt, chatgpt tutorials, learn to work with chatgpt, asp.net, asp.net mvc, asp.net web api, learn web api, visual studio 2022, dotnet framework 7.0, entity, entity framework, api, course, learning, web development, api development, learn to develop web api, mvc, Artificial intelligence (AI)
Id: dNJvLv3MCXQ
Channel Id: undefined
Length: 12min 33sec (753 seconds)
Published: Wed May 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.