Learn ChatGPT API with C# | How to integrate ChatGPT with C# 2023 | Console Chatbot #ChatGPT #OpenAI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign how to create console chat boot with the c-sharp the interesting part is that at the end of this video you will able to do and create this console app chat boot yourself if you don't even know anything about the programming so the fun part is that at the end we will ask very interesting question after creating our chat board with the jet GPT so it will be very fun and keep watching and let's continue [Music] for the purpose of this tutorial I will use Visual Studio Community which is a free integrated development environment for c-sharp applications so if you don't have installed already you can download it and from the real Studio Microsoft website official websites and install it so I have already installed it I am going to open the visual studio on my window from this new window dialog box I will select create a new project from this new project window dialog box I will select console app .NET Framework if it is not showing here in the list you can write it console and hit enter it will be show here I'm you can select it and click on the next now you can name it your project I will write chat GPT console chat put you can give any app you want just yeah write the name and hit create now that we have our project created let's move on to install open a AI API nuget package to do this I will go to the tool for tools and then I will go to the nuget package manager and new get package manager I will select package manager console so you can see that tab of package manager console is now open so I will write let me expand it more and I am going to write install then package and I will write it open Ai and and then I will hit enter now it's going to install on our this project you can see it will be added here in the references so for now we have some classes after the installation of open API we will have more references in our reference tab now we have successfully installed open AI package in our project let's take a look at in our to our code the pro program dot CS this is the default code that generated when we create our console application projects let's go through the step by step the program class is the entry point to our application its contain a static method Main and the main method is where we write our code to execute so I am going to expand the code window more and I am going to hide the properties also now I am going to write our code here let me make the code format bigger now it's look better so first of all I am going to use our library which we initial which is open AI API now in the body of our main method I am going to declare a variable by writing a commits commits are basically very helpful to understand a code and always ignored by the compiler so I am going to write by double slash and then I will say declare and initialize input variable with value of empathy streak so now I am going to write string data type and then variable name input equal to double quotes mean we are going to input input string so now I am going to write while loop debt run until user enter exit while application is running so I will say while and then in the small brackets the while condition will be the input not equal to the value of exits so I am going to write double curly brackets which will be the body of while loop and in the body of while loop I am going to get the input from the user so I will say input equal to console.readline I will press tab and then I'm going to write our code I am going to create open AI instant or you can say object so I I will say VAR open AI equal to new and then I will say open Ai and then API I will add a key which will be the API key provided by open AI webs if you don't have a key you can go to the open AI website website and let me show you I am going to open my browser in the browser just code the platform dot open ai.com and you will get to the open AI website so if you don't have created your account yet on open AI you can go and then it will ask you to sign up sign up and create account so it is free and they will give you us some credit to use open AI so after login you go to the profile and view API keys and in the view API key session you can create a new secret key so I am going to create my new secret key here and I can I am going to copy it you can see it is generated and it is copied let me open Visual Studio and go to the our code now I am going to add my API key which I got from open AI website so I am going to paste it here now after this I am going to create a completion request this completion request will have properties so I will set the properties of it so let's some add here so what completion request now I am going to create with new keywords it will be an object so I will say completion and then request and then practice smart brackets and now we have created completion requests let's set the property so completion request First Property will be the prompt The Prompt is the value which we will send and pass to the open AI chair GPT API so for this uh it will get the input when the application run the input have the value of the user so we we pass this value to the prompt so let's start writing and enter request parameter which will be the model so we will select the model which we are going to use so for now we are going to use the model for this I will say open AI API namespace start models dot model dot now we going to select a model we are going to select this model for our this application so now semicolon no one more property we have to set for completion request is Max stop color so maximum token for this application I am going to use 80 so basically this is asked chat boot so and we don't need a longer text response so we will need a short report response because it's a jet put so if you want to increase you can increase the max token to whatever you want so let's we have completed our request and its property let's create another object which will be called completion and it will be equal to the open AI which we created recently this one instant open AI that completion start create completions async we are going to call this method and we are going to pass our this request which we created and I'm going to pass it now I am going to set one parameter because we need only one response if we ask some question ask some uh pass some values that GPT API will responds only one so parties now I am going to write when this will run and the completion request will have the value which will be the response which the open AIG GPT will send so the result of the average GPT API have in the this completion object so for this we have to iterate over it for each group will be needed to I to rate our the values okay now for each I will say for each then in the small bracket for each I will write War form and then in completion in completion Dot is held and then card completions we will have multiple completions in a result so we will say completion so for this now I am going to write the body of the Polish Loop in the body of our lead flow I will write code to display for this I will say console we are going console dot right line and in the smart brackets I will say comb dot text so now we have one port line is remaining which will be the console dot right line so for this we will use this line after the while loop whenever someone a someone enter exit it will be displayed so we'll say you enter exit app is closing okay before to run our code and I'm going to make some changes but I am going to do I am going to add some text here I will say plus and then I will in the double quotes I will say slash n it's mean new line whenever a response generate by the chat GPT API and send us back to application our application will show the cursor to the new line so to do this to start this application you can go to the start button to start this application or you can press F5 from your keyboard let's press F5 amazing our application console jet boot is now running let's have some fun with this chat Boot and say hey you are not so intelligent is human so enter and let's see what it show us wonderful what a nice response we got let's say this question again and we will get another different response on same question thank you for your feedback I understand that although I am not as much be intelligently developed as human so have some more fun and say hi why are not you all ways right amazing no one because no one is perfect nice very amazing and wonderful question let's say who is the crazy Dent of USA so Biden so very nice everything you can ask and it will responds you very nice and amazing if you want to try you can Will have a very amazing wonderful fun with this state GPT and I am going to attach this code of application below to the video in the description I hope you may find this video very helpful and you may have some fun if you try yourself and don't forget to like And subscribe my channel thank you so much
Info
Channel: codepey
Views: 173
Rating: undefined out of 5
Keywords: integrate ChatGPT with .Net Core, integrate ChatGPT with C#, ChatGPT with .Net, chatgpt with C#, C#, ChatGPT, API, integration, tutorial, coding, chatbot, machine learning, OpenAI, chat gpt, chatgpt explained, ChatGPT C# API, chatgpt coding, chatgpt tutorial, how to use chat gpt, chat gpt tutorial, chatgpt programming, chat gpt prompts
Id: olZStJKSerU
Channel Id: undefined
Length: 16min 21sec (981 seconds)
Published: Mon Apr 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.