A.I. Writing .NET C# Code - ChatGPT

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign thank you for watching this video I am Muhammad and today we're going to be doing some really interesting video we're gonna be actually getting some code generated by an AI and we're going to be implementing it and see how actually usable it is how can actually be utilized what could be some of the benefits that utilizing that AI tool in order for us to actually get started with it and how we can actually utilize it to understand some of the concepts that we need in order for us to create our web application our console application so on so forth if you like this video please like share and subscribe it will really help the channel as well if you'd like to support me please consider supporting me on patreon or buy me a coffee now grab your cup of coffee and let's get started when can I be utilizing AI in order for us to actually write some code and actually verify its work see how it actually approach certain aspect of our code we're gonna be giving different scenario and we're gonna be seeing what code AI the AI will generate and then we're going to be taking that quote putting it in our.not application and actually running it and see actually how it performs so so what we're going to be doing today is we're going to be actually utilizing chat TPT which is going to be an AI which is provided by the open AI platform and it's going to allow us to actually ask the AI to write some code for us we're going to take that code and then we're going to be actually implementing it inside our dotnet application we're going to be running it and actually see the validity of that code we're going to be giving the AI different types of examples that it needs to generate for us and we're going to be implementing it one by one and the platform or the AI platform that we're going to be utilizing is going to be chat GPT which is going to be provided by the openai it's a free uh software or basically free service that you can actually utilize all you need to do is just go to openai.com and then once you are there all you need to do is just click on try chart GPT it's gonna require you to actually register and have an account but other than that it's completely free to use and once once you're registered and everything is set up you're gonna be actually seeing something like this and here you can see all you're gonna have to do is you're gonna have like some kind of a chat uh text box where all you need to do is basically input whatever commands that you need and basically I will be able to pick it up so for example before we start with anything related to code let us just uh ask some anything regarding to any random question just to basically if I may realize I will self with it so we can start for example uh what is the best programming language and we can see it's already started replying to us and it's giving us some information about it and basically whatever we ask here we can either say that we like the response or we dislike the response and whatever information that we actually ask or whatever information that we actually provide it will help to train the AI so for example if the response that we are getting is actually valid and it actually fits with our needs it will basically train the AI or basically give more information that I took have give much more accurate answer and this is all part of the machine learning process so at the end of the day the data sets that the AI is all based upon it basically scans the entire networks of information across the internet and let's gather this data and basically it process it in a way in something called supervised learning and unsupervised learning that's completely different topics and basically it trained itself in order for us for it to be actually to provide this information for us it's much more complicated than that this is way way much oversimplified from the simplifications but it's something like how it works and basically when we give it a thumbs up or thumbs down it will help with the classification of the answers so this if this classification is right it will basically make sure it validates its information if not it will help correct this information for download I just thought I mentioned that so you understand why are we giving the thumbs up or down here so let us try with a very simple example or first let's say what is.net let's see if it's under able to pick that up let's say like this dotnet see it already start to be able to pick up some information okay Perfect all provided by Microsoft okay let's give it that's right okay so what else should we give it uh so let's start asking it by some question create a calculator app and not let's see how that's work and as we can see here while it's generating our code for loss all we did in order for us to get here all we did is just input a simple line and this is fascinating it's able to actually give us all of this okay now that is actually creating it let's see what we can do is now let's try to test it out see if it actually works or not so I'm gonna click copy code and inside my visual studio code all I'm going to be doing is I'm going to be creating a new console application so I'm just going to say dotnet new console is as visible let's zoom in a bit okay maybe we need to increase the font size just before we so it's visible simple to settings and let's put the font size here say 34 34 I think it's too big 34 let's make it 26. 26 yeah I think that should be fine so let's save this and let's close this okay so all we're going to say uh not the new console application we're going to give it a name calculator app and that's all we're going to be doing we're going to create an empty console and we can see here that a console application has been created for us and this is basically here if we look at the Cs approach we can see that it's utilizing.net7 so that means that it's going to be utilizing the top level statement out of the box we can change that that's fine but we can also take whatever it exists here and make it in a top level statement so what we're going to be doing is let's delete this and let's hide this for now we don't really need it so it will have a much more better release date and let's take this so let's copy the code here that's actually provided for us copy and let's put it here be perfect so let's save this right now and let's go to the calculator app and all I'm going to do is just not build for now perfect we can see that it's actually building correctly and now let's run it does not run okay so it's asking me for my first number I'm gonna put three second number I'm gonna put eight what type of operation do I want to do I'm going to start and we can see here I got a response 3 multiplied by 8 is 24 which is actually correct and to be fair it's actually very impressive that within a single line of code sorry with the single line of command on open AI I was able to actually get a full-fledged calculator app running yes it has its Pro it's not perfect still I have a lot of items that we need to figure it out but it's basically it gives me a good boilerplate code to uh get started and basically jump from there so if you take a look here so you might think to yourself okay that's fully working what is another potential enhancement that I need to do so for example here if we I'm not sure what happened there okay okay so for example here let's run this application again and it's going to ask me until your first number so what happened if I input a exactly it crashes why because it's expecting a number and the user might not be able to import a number so the parsing of an integer here so this might not be correct because we're not actually validating if it's an axillary number or not or a simply it's not even if we import a connector let's say if we enter an empty number uh or uh just click enter what up and putting anything not also can crash so we can see here that the code that's actually providing us it's an actually valid code it has all of the right functionalities that we are expecting from a calculator app but it is a basic Elementary performance or basic Elementary implementation because it has still a lot of the edge cases that we need to actually verify out of the applications that we need to actually make sure we are covered when we're creating any types of application but in general it's a very good a boiling plate code so for that that's a very good work for the AI so now that we have created a simple calculator service let's take it a bit more advanced than that so now let's click here and I want to basically ask the AI right now to create a API with a cloud operation so let's see how it does that so we can say create API with for a to do list in dotnet let's see okay we can see it's using an in-memory database okay so what we're going to be doing right now let's clear this let's go back here okay so now we have the calculator up what we're going to be doing is we're going to be creating a web API so we're going to put.net new web API Dash and we're going to be calling it what is it called let's use the same name in converter just to make it easy to do a list API let's copy this and let's run this perfect now let's do go to the to-do list API and I'm just going to do not build and now if I come here first of all you can see my calculator app now I have here my to-do list API and once I open this you can see that I have a normal API and we can take a look at the sort of not seven one perfect and what I'm gonna do is I'm just gonna basically clean this don't need actually let's leave it as is let's create a new class we're gonna put a new file and we're gonna call this to do list controller similar as the what the AI have created.cs and now all I'm going to be doing is I'm just going to copy everything here I'm going to paste it here I didn't do anything else all I did is just create a simple controller let me hide this and let us verify that this is working by doing a DOT not build first okay we have an error let's see what the error is it says that from body let's see where do we have from body here okay I'm not sure why it's not accepting the front body here let's click on this let us remove this for a bit inside this and let us try again okay okay so first of all we don't need these it's referring to an older version and here we're gonna say controller base it doesn't know what controller base is I can't remember what is the see here let's make it something similar to this where is this okay let's copy this Microsoft asp.net core MVC so using using microsoft.asp not core.mvc and we can see here that this one is using controller base as well so that should work let's run this again okay it's running let's close this so basically what we did here is we just adjusted it so one of the main issues that we currently have found here is the the version of the.net API that's created for us it was based on the technology framework because it references some.web and basically once it created that you have some compatibility issue because we are utilizing the latest version of the reducing the latest version of The Nut framework here where utilizing dot not core 7 and that did not work so we needed to actually refer to the actual name spaces we're utilizing microsoft.asp.netcore.mvc and order for it to work and then we actually utilized the controller basic class at the start of the API controller that it has provided for us so that's one item but other than those small configuration changes that we had to do let us see now it actually performs so let's put that not run and because we have created here a an application utilizing asp.net7 sorry asp.net core 7 and vitalize The Boiler paid code if we take a look at the program.cs not just program.cs the program is just inside our web application we can see that we have a Swagger implementation which makes it really easy for us to see all of these endpoints so what I'm going to be doing here is I'm going to take this endpoint and let's go here to my web browser I'm just going to put forward slash Swagger forward slash index.html and here we can see it did not show up I wonder why not show up so we need to add these references here so that's another item that it did not work so now let's stop this again and let's run it and now let's refresh and we should be able to see it right now okay it's not happy with it so the other item here is we're not actually specifying the attribute so we need to put http let's copy these let's make this HTTP post we already have this one here this is a post yeah this is a delete and let's try let's stop this let's run and let's refresh and you can see here that we got our to-do items to zoom in a bit yeah so you can see here that we got the basic items we got the gut we got the post and we got the delete so although this API right now or the source code that the API has generated for us it's actually technically working or basically technically contract we had to do a lot of fixing within the to the boiler create code that has been generated so because I think we're utilizing here a web framework rather than a console application that I was not actually able to figure out all of the right uh all of the right information or basically all the right configuration for that framework um and basically we had to do a lot of the work ourselves in order for it to make it work but let us do some experimenting experimentation with that we're going to be tweaking the commands from the AI in order to see if we can actually get the right version so let's just try it out so I'm gonna get get all execute it's empty let's add one so value here we can say go to the gym let's execute and we can see here we have got a 200 and now if I click on execute we can see that go to the gym perfect and for the to-do list so for the ID I'm just going to put id1 I'm not sure if it will work and we got a 500 because it does not know what id1 is but if I put on ID 0 it will work because it's an array and it deleted it and now right now it worked so we can see it's a bit clunky but it works so now let's go back to our Ai and let's say the same command again create a to do a to-do list API and dot not core seven let's see if that will work I think seven will not work it's a bit older saying that code only actually started oh okay so you can see here because we have given it a much more precise precise command we can actually actually see that we are actually getting the most up-to-date information when it comes to our.net so that's really interesting perfect now we can see that's actually all working and I can see directly that we are referencing here the right version of Microsoft of the light Library we can see that actually inheriting from the right controller base we can see it actually provided the right information here the right parameters and the right attributes that we needed we can see that actually provided the right attribute for every action so that makes sense basically it duplicated whatever we have done here which is exactly what we needed okay perfect so now we can see with much more better commands we're actually able to get much more precise responses so the last one that we're gonna be requesting from the AI today and we're going to be actually able to implement which is a little bit more complicated than that which is we're gonna see if it actually can Implement an example with dependency instruction and we're going to be seeing how if that will work or not so we're going to say create a let's say an application in.net core with dependency injection and the nice thing about this is I did not specify what type of library for the dependency injection that it needs to create all I said is go and create something for me with Independence instruction and it's going to be really interesting to see what type of dependence instruction the AI would decide to create for me so let's see right now let's go all the way down we can see okay that's all should be fine so choose the web one we can see here MVC create a controller by controller to create an i generic I service she got do something and then they created a service interface an implementation indicated an extension okay okay well actually that's a really really good so what I did here is I did not actually give us the full set of code uh okay that's really interesting so what I did here it did not give us the full set of code for our application to run but what it did is it actually gave us all of the right boilerplate code that we need in order for us to make sure that the service is working so what we're going to be taking it I'm actually really surprised so what we're going to be doing here we're going to take those pieces of code and we're gonna put it inside this web API that we currently have and we're going to be seeing if it's actually it's gonna work or not so let's just take let's first create the interface so I'm just gonna create a new folder here new folder I'm just going to call it services and I'm just going to be creating here and let's say what is it called an interface what is it called I service dot Cs and I'm just going to copy this I'm just basically copy pasting whatever exists here and then I'm gonna create this one which is called myservice.cs new file mindservice.cs and let's take this perfect and now I'm just going to create the service extension new file service extensions even went to the Oak I need to add the CS at the end so let's copy this okay we're gonna have to add an extra one at the end okay and what I'm gonna be doing right now is I'm gonna go to my program.cs I'm gonna put up dot uh add my service and all I'm gonna do right now is go to my controller and I'm gonna inject it similar to the way they injected that's all I'm just gonna copy this and I'm just gonna take this for us now let's create a controller uh sorry uh let's create a Constructor and let's inject this service into my Constructor and for the get I'm gonna just do this return the service to something before it calculates okay uh yeah actually yeah why not I don't really need to return the list okay let's stop this now and let's run this again dot not run and now it's running okay we have an error the web application does not contain the finish and add my service okay so now it's all gonna be a referencing issue so let's add this here we're gonna put using um to-do list API dot services and now let's run this again so let's do this in a different way just to make it save us some time so let's take this and I'm going to remove this uh actually let's delete this let's make it in a different way so let's delete the service extension and let us make it this way here so we can just say up Shady Builder dot Services dot uh we can make it like this let's remove this and that should work oops sorry I should be capital and let's delete this line let's try again okay let's error now no extension is it surface or what did I do see it's all typos let's try this again okay now it's running so after a lot to try and error it's just a bit destroyed and error let's now go to my web application let's go here and what I'm gonna be doing just gonna refresh this and right now I'm just going to try this out and I didn't get anything here I'm going to hit execute and as you can see here from the API said hello from service and it's actually injected for me so the concept that the AI have given me was correct so when it comes to actually implementing a dependency instruction that actually created an interface it created a service it gave me the correct way to inject into my services it had a lot of issues when it comes to actually configuring the right parameters maybe because it all gave it to me in a single class rather than different folders but that should be fine it's a user for it's a user error or basic interpretation error here but other than that we can see that actually giving us a right way to actually inject a service and utilizing a service and that's basically the main item here that the AI was able to actually understand what dependency instruction is how to actually utilize inside a controller and how it can actually be injected and as you can see from this video here that although AI is getting more and more advanced and getting much more capabilities than before I still have some way to go in order for it to actually say try to replace all of us but it doesn't see it we can think about this tool it's much more of a learning tool where it actually help us understand some of the concepts and give us some body plate code where we can actually utilize to jump start whatever we need and when it comes to programming so here we can see how it actually created the basic calculator app then a basic controller and then some basic regarding dependency injection and all of that was basically within a few Lines within a single command we got all of the source code available for us and it's really important for us to understand here that whatever that code that's generated just a boilerplate or starting code still needs a lot of work before it actually can be utilized I hope this video was a bit insightful it's a bit different than the usual one but basically it's kind of it allows us to see the different potentials that they are going to be able to provide for us on the long run it's going to give us much more insights on how actually AI can help us write better code on the long run and we can see this in some of the intelligence that the Microsoft's implementing as well as the GitHub AI tool that you can actually subscribe to and pay money in order for it to help but this one here is completely free please please like share and subscribe if you like this video it would really have the channel have a great day
Info
Channel: Mohamad Lawand
Views: 15,358
Rating: undefined out of 5
Keywords: .net, api, beginner guide, step by step, csharp, c#, dotnet, dependency injection, code with me, coding, ef core, sqlite, database normalization, database, entity framework c#, entity framework core, entity framework, asp.net core tutorial, rest api, crud, artificial intelligence, ai, chatg, chatgpt, chatgpt coding, chatgpt explained, chatgpt programming
Id: _X0-RE8c-yU
Channel Id: undefined
Length: 27min 52sec (1672 seconds)
Published: Tue Dec 13 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.