ChatGPT .NET API Client

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
oh I knew it didn't know everything for those of you who have been living under a rock for the last two months or so that is chat GPT and it's been taking the world the internet YouTube You Name It by storm and not being one who wants to jump on a bandwagon I did actually want to have a look and see what it is all about and I can see yeah I'm very impressed but in today's video I want to take a slightly different View and I wanted to see whether we could use the GPT 3 API from the same people that make chat GPT and use it from within the.net application to build an app that provides fairly similar functionality to this but with a little bit of a Twist and the answer is yeah we can do that and we do it into this video [Music] [Music] well hello wherever you are whenever you are where am I Melbourne Australia as usual and when is it it's January 2023 so yes in today's video we're going to be building a little.net application that's going to use the GPT 3 API to give us a little I guess you'd call a chat bot but with a specific use case in mind and just before we go on with a demo of the app that you're going to build then just want to see very quickly the usual sort of stuff if you like the video give it a like it really just helps me out and if you've not done so already maybe think about subscribing ding the little bell and if you want to and you'll be notified of any updates that I make this year of which I'm hoping to make quite a few anyway enough of that stuff let's take a look at what you're going to be building today so let's take a quick look at the app that we're going to be building today this is the end result and of course we're going to go through the coding completely step by step so the tool is a little use case let me talk about the use case first the use case is your developer um you're writing code you're using Docker you're using redis and you know you can't remember some command line prompts you might need to use such as listing Docker containers in which case you're in your developer workflow command prompt you can use our little application I've just called the ask and you can ask a question such as what command do you use to use to list dock I'm actually running Docker can take notes okay and I'll go away it will use What's called the gpt3 API which is by the same group open API uh the chat GPT is from and we're using that API we're providing that question to it it's responded back and another thing that you can see here on yellow is the response that it's given us okay and then what our app does a little bit further is it parses that string the overall response so you can see that we've got a question mark here sometimes you'll get other things like some textual descriptions or instructions or links to articles as well and so we want to try and extract the actual command prompt and what we do is make a guess and we copy that guest to the clipboard so in this case the guess will be correct seeing I'm guessing that Docker PS is the command prompt you use you want to use and if I just do a control V it's already in the clip portfolio so we can just hit enter and we have our answer so it kind of saves us from going to Google or some other some other place and it's just a bit of fun as well so let's make another go at it let's try something else and I just want to show you some of the limitations I guess of some tell me how I've built it so what commands do you use to run a not Rob run a darn A6 project let's see what we get with that the same idea go where you use the GPT vp3 API and this is a good example of what I'm talking about it's kind of giving us an answer for not using the command prompt but using visual studio okay it actually puts using the command to london.x project is okay so it's not really what we want at all and all my little guessing routine has done is guess that the command prompt would exist within the last line of the response and that's what it's saying to guess is and you know again if I do a control V that's what's in the clipboard okay so in that instance that's not right that's not particularly useful the answer itself wasn't quite what we wanted so maybe if we finesse the question and we just see.net core Project without putting a version in it we'll see if you get a different answer if you do we get a different answer and the answer that we actually want and again the only text that was returned would be a few newlines.net run and I'm guessing dotnet run is the command that we want control V is there to use so a bit of fun quite an exciting little project I really enjoyed building it and working with it and it's still in a very early stage as well but I think you could actually take it and do some really interesting stuff with it anyway Lee that's the demo hopefully it's piqued your interest and in the next section move on and we'll take a look at chat GPT itself as well as the API docs for the API that we're going to use we'll do that next so just before we move on with coding let's just take a quick look at chat GPT itself and I'm not going to do any massive amount on this there's already a million zillion videos on YouTube about this now anyway good old Google has taken us to this landing page just before we have a look at chat GPT I do want to just call out that it's actually created by this group here open Ai and I'm calling that out for a very specific reason that will become a bit obvious later but for now let's have a quick go with chat GPT and you can ask it anything you like obviously you can't ask it who I am or you can ask it who I am it wouldn't know the answer to that which is a massive blow to my ego and but it does know a lot of very cool very important stuff much more important than who I am of course so things like how do I make a HTTP call with C sharp and pretty cool it'll go away look at his model and it'll tell you what classes you need to use and I have noticed it will actually give you slightly different responses based on the question okay and this is actually a quite a different answer to what I've been getting previously and it's giving us a particular approach using web client which is interesting uh it's actually giving us three methods which is pretty cool anyway I'm not going to dwell too much on that the nice thing about it though is that you can ask more questions it retains the context of the thread anyway not going to go into that too much uh you know there's already huge videos on chat GPT in or on YouTube now I did call I was going to close that down I did call it open AI it's the group that have created it and so we're going to be using one of their apis to create something sort of similar as you saw in the demo it's going to allow us to ask questions and get responses back and it's but it's not technically chat GPT it's one of the open AI apis in this case the GPT 3 API lots of acronyms there so if we just come back over to Google and we'll just search for open AI API and come over here this is the dock side this is like the developer portal very good very easy to follow um some API documentation is kind of confusing their stuff very nice even you know given the the complexity of the subject matter so we just log in again with the same account that we used for chat GPT and we'll just uh oh traffic lights traffic lights traffic lights traffic lights I hate these things good continue and password and it logs you in to the API portal and again as I said the documentation is really rather nice now we are going to be using this text completion uh example here really to build our application but if you come over to documentation you can you know goes through introduction it goes through how you can authenticate so I found this API reference section down here is really kind of the nicest part of the docs you know tips through pretty much everything you need to do to you know build up any simple application and we're going to be using tells you all the different models that you can have we are going to be using this completions model here which will allow us to submit questions to it and it will come back with answers okay and we're going to integrate that into our console app all right but I'm going to cover this in the video so I'm going to dwell on it too much but again a really nice documentation website highly suggest that you check out now just before we move on with coding one thing you do need to do before we actually start coding is create API key so in order to do that make sure you're logged into the portal come up to your account click on view API keys and I have a few Keys here I'm just going to delete this one I'm no longer using that one and I'm going to create a new key that I'll use for this video which of course I will delete after the video is completed so if you attempt to use this it won't work unfortunately for you but I'm going to copy that off and I'm just going to put it into a I don't know an old pad or something for now let me just do that so I don't lose it okay cool so that's the key I'm going to use for the rest of the video and the other thing I want to show you just before we actually start coding is they have this rather nice tool at this location here where you can paste my get my key back you can actually make some API calls without writing any code it's rather nice I'll just paste my key back in here excellent and then you can just start playing around basically with with the API so I'll take that out and we'll see what I don't know um what command prompt do you use to list uh Docker containers because we'll be kind of requesting that same sort of information our Command Prompt you can use the different engines here I think I'm using this one here text DaVinci zero zero one and again the docs go through why you would choose one over the other and you have all these other settings here which I'm not really going to cover today and that kind of goes through how much risk it takes in attempting to answer and all that kind of stuff click submit uh come back straight away with Docker Pierce which is lovely and we're hopefully going to get that type of response back from the API when we actually come to using ourselves and then we'll just you know inject that command if we want into the command line and run it fantastic so that's a very funnel windy tour of chat GPT although technically we're not really using that um but we are going to be using this API in the sections that fall so yeah next we're going to scaffold up an application so let's get started so we're going to scaffold up an application now and I'm just going to open a command prompt which has opened on my other screen and I'm going to change into my working directory and this will of course more than likely be different for yourself but I'm going to move into my season six folder and move into my episode one folder on my D drive quick directory listing you can see there is nothing there now just before we get going with anything else the only thing you really need to create to these application is the.net framework and the way you can test to see whether that is installed is to type.net dash dash version and I'm using version six so so long as you get something that starts with a six that is all cool and of course yeah the only other thing you will need is an open EI account with an API key which we covered in the last section so that's all looking good I'll clear the screen and then we're just going to scaffold up our console application so.net new console goodness and give it a name and I'm just going to call it ask okay so.net and you were using the console template and I'm just going to call this particular application as fantastic quick directory listing you can see the ask application is there and we'll just change into that quick directory listing you can see there's not much there at the moment an object folder CS project file and the program CS file so let's open that in vs code by typing code space period and also opens vs code in my other main screen fantastic and you'll more than likely get this pop-up down here and building assets just click yes to that fantastic now in terms of our project structure it's not going to get any more complex than this so we have one CS project file and we have the program CS file we're not adding anything else to it super super simple so the only thing I want to do before we move on to actually doing some proper coding is adding a couple of package references to our CS project file so control and backtick to bring up the integrated command prompt within vs code and we're going to add our first package and we do that is by typing.net and not us add package uh Newton self Jason okay so this is the one we want here.net ad package using soft Json and the reason we need that is we're going to be deserializing the Json response that comes back from the API basically we want to you know deserialize it so we can get to the response text all right and again using newtonsoft to do that now if you are not that familiar with deserialization of jsons all that kind of stuff you can check out a deep dive I have on that subject over on Liz jackson.net that's part of my.net developer toolkit course if you're interested in that but I digress so we need that package and of course we'll go through how to use this particular package absolutely step by step in this video clear the screen and then we're going to add one more package and this package is an interesting one actually it's called the text copy and all it really allows you to do is copy some text to the clipboard okay and you know what I mean this package makes it that easy but if you didn't have access to this third-party package it's actually quite tricky to do it from within a console application as I found out making this video which really surprised me anyway we've been saved by the people who have created text copy and it makes it nice and easy all right fantastic so that's all we need for the moment so let me take a you know a little brief pause and then coming up next we're going to actually start coding our chat bot a command line application so let's get started and do that now so let's come over to our program class and start coding I'm going to get rid of the command prompt here to give us a bit more room and I'm going to get rid of this boilerplate code as we just don't need that anymore and the first thing I'm going to do is check to see whether we have any command line arguments passed when we start our application okay so args length if it's greater than zero then we know we have at least one command prompt click on that formatting and we're good to go otherwise we will give a message back to the user to say look in order for this to be useful you will need to provide some input so just a console right line and we'll see something along the lines of you need to provide some input good enough not the greatest ux in the world but good enough for what we want to do fantastic so next I'm going to create a HTTP client which is the main vehicle we are using to make HTTP requests now in a lot of my other videos I go on and I talk about HTTP client factories and all that kind of stuff and that's definitely relevant in certain circumstances but a very simple application such as this so we just run once and then it gets torn down the way we're going to do it here is fine and that is to directly use the HTTP client object here or HTTP client class to create an object so HTTP clients will call the object instance client and then we'll just make that equal to new HTTP client so again I'm trying to keep this app super simple and this video really quick so we're I'm not saying we're taking shortcuts but we're keeping it simple okay we're keeping it simple today and then on that client we do want to add a default header request header and that is going to be our API key that we created in the last section so when these requests are made we need to pass our key as a beta token to the endpoint to the API so we do that via headers so we will add a handle I mean to provide two things firstly what is the key I suppose they actually be careful here the the header key and that is authorization okay and if you are non-american like myself just make sure you use a zed here not an S as you're probably tempted to do and then the value so this is a kind of key value pair and the value confusingly is the API key as a beta token okay and we specify that by saying yes it's better and Beto's just uh an authentication scheme basically you're basic you have other ones as well but beta very common takes the form of a key so beta uh space and then we just paste in our API key that we generated in the last section now of course you're going to be screaming at the screen at the moment saying you should absolutely never paste Keys into your code you're absolutely 100 correct you should never be pasting Keys into your code like this you know if you commit this code to GitHub the key is visible and I'm just doing this for the purposes of quickness okay cutting a few cornrows really but you would want to in this case I would say you would want to create a user secret to contain the key and you would inject it in through the config layer I cover all this in the.net developer toolkit course I know I keep going on about it but I Do cover it there and um user secrets are a free module there so you can sign up for free and you can learn about how you could use this as a user secret over there but we'll keep it hard coded for the moment again not best practices but best practice but for our purposes it's okay all right the next thing we want to provide and I actually come back over to the open API documentation on the subject and just resize the browser here so again we're using the completions API and this is a rest based API and you can actually see here that they give you an example of how to run basically what we're going to be running as a curl request okay so we need to as you can see here they're providing a header just exactly as we've done authorization header with the beta token as you can see here we'll be dealing with the content type in just a minute we will take care of that in a second but you can see also what it requires is a model which is in this case they're using the text DaVinci 3 Model prompt so that's actually the text that we're going to be supplying as an argument that was put in at the command line prompt and then these two attributes here Max tokens and temperature now as you can see here this is actually getting passed over as Jason okay now again in the interest quickness what we're going to do here is I'm just going to provide a string yeah a string that represents that Json kind of like what they did there now I ordinarily would not do that and ordinarily would create an object and then serialize that using something like Newton soft or the Microsoft framework but again keeping it simple keeping it you know very lightweight we're going to create our content just as a string and you wouldn't usually do this but it's much quicker to do it this way so the way we do it is we're going to create some content so I'm going to create a variable called content and that is actually going to be something called a string content object and that will contain our string and it'll contain a couple of other things and one of the other things that's going to contain is the type of encoding that we want to use and also the the application Json media type as well so that's what the string content object gives us the ability to do okay so you can see here string content which is the string which we will create encoding and then also the media type so we're going to be using this kind of method signature here all right now what I'm going to do I don't like doing it but I am going to copy from my reference code and the code obviously for this is available on GitHub as well so you can you can do that I just feel typing this in would be way way way to laborious and error prone and I will go through this let me just get rid of the prompt at the site here so Ctrl B and this is just a string okay this is just a bog standard string and you can see here we're providing model attribute uh which is text DaVinci zero one The Prompt and we're actually injecting the first argument that we are passed at the command line the temperature and the max tokens now the only thing of naught is you can see that the double quotes here here they're all delimited with a backslash okay and you need that obviously so this is basically saying this first double quote is actually the start of our string and the one right at the very end here is the end of our string all the other double quotes in between are being interpreted actually with the exception of these ones here as well sort of a concatenating a string all the other uh double quotes are basically part of the string and they're being delimited by this backs backslash here all right so hopefully that made sense it is a bit yucky it's a bit messy I wouldn't usually do it this way but it's it's much much quicker to do it this way anyway put a comma there take a new line or tab in and we want to specify the encoding type and we'll bring in the namespace for that so uh cursor in the word encoding control and period and we'll bring in using system text and we will make that equal to UTF eight and we'll just stay on the same line and then the last thing we need to specify is the media type and we just see that as application okay so hopefully what we've done here is Cleo we've created this content object which is a typestring Content the main part of it is the string which I've just you know it's just raw string data representing the Json that we need to provide to the API and then finally not finally but for this section we're going to use something called the HTTP response message we'll call that spawns and we will wait on our clients HTTP client and we're going to post async so that's why we're waiting okay and what we're going to post to we're going to post to our API endpoint which will supply in just a second and we'll also Supply the content that we've just created okay so a HTTP post request which again is what is required if we come back to the documentation over here it tells you it's a post request okay so we're creating well we're passing data as a in a body basically is what we're doing all right and then just in here it's the API endpoint so come back to the docs again and here is the end point that we need so we'll just copy that from here and that should be the right endpoint let's paste that in like so and obviously paste it in a new line at the start now so we'll just Rectify that that's cool and then from this we're just going to get a string just to kind of wrap up this particular bit before we get a bit more detailed we just want to get the response string so and we'll just make that equal to a weight and we will wait on the response that we created here content and we will just read string async like so and finally we'll do a console right line so this is our kind of MVP we're going to make this a little bit better as we move forward but I want to test this out uh no basically and uh we'll just rotate the response string okay so very basic very simple again just to retreat we check to make sure that we've got arguments passed over if not then we'll give this message here if so then we create a new HTTP client we add a header for authorization uh we add our content in a rather or inelegant way and then we simply make a posting async call to this endpoint and supplier content and then we've respond back uh with uh yeah reading our string so let's do a clear screen let's do a net builds to make sure we haven't done anything too crazy stupid in fact also need to save this all right let's do that again make sure you save excellent and let's do a.net run and we need to provide some input indeed we do need to provide some input so the way you do that is you do a net run dash dash in this case and then double quarts and then put what input you want so this is treated as one argument okay but then the double quotes one argument so that's what we should be passing over hit enter and we just get a Json response string back from the API which is looking pretty good and you can actually see here the text it's the text attribute that we want so it says on a given host newline newline Docker images okay so that is looking pretty good to me it is working well and if you just maybe take this because maybe a bit difficult to read and we copy that and we come over to our best friend Google for the moment and type in Json editor uh online this is the tool I kind of like to use it just helps you kind of re Json if you just um paste that Json response in you can kind of tidy up over here and push over here and you can see this is the kind of response that we get back okay so there's a few there's an ID but object as a text completion I got some a few choices come back this is basically what we want okay so in within this choices array we want the text that's responded back with so on a given host Docker images okay which is fantastic so let me take a little um pause here and then the next section what we actually want to do is take this Json string and we are actually going to do it the right way and we're going to deserialize this okay so it's currently serialized when it deserialize it into an object so we can actually get to the various attributes specifically that text attribute so we can then do something with it but quick pause we'll do that in the next section so we want to deserialize this Json response so we can actually get access simply and easily to this text attribute so let me just get rid of the command prompt here and I'll bring the file explorer back up by doing Ctrl B in Visual Studio code and just to remind you when we scaffolded our app help we did include this Newton soft Json package which is what we're going to use now okay so back over here we have this response string which is just our serialized Json we want to D serialize that now and it's pretty simple using the Newton soft stuff so I'm going to put it in a try catch block anyway just in case it does through an error so we'll catch the exception first if there is any and call it ex and if there's an exception we'll just do a console right line and we'll see something along the lines of your string interpolation because we want to write out the error message if we have any and we'll just see I could not d C lies the Json and we'll provide the exception message in our response like that okay should be okay though now the reason I'm actually using the Newton soft Json package and not the system text Json package provided by Microsoft is for the very feature I'm going to use now and the Very feature I'm going to use now I am conflicted about it because what Newton soft Json allows you to do is to dynamically deserialize Json what does that mean it means that you just give it a Json string and it will work out what that object is okay you don't actually have to provide an object definition and deserialize into it okay so it's kind of um non-typed okay you end up with this Dynamic object that's not typed and I don't like that okay it's the kind of thing you can do in JavaScript and stuff like that one of the reasons I love c-sharp is because it's a strongly tight language and you kind of avoid all that so I'm kind of breaking one of my Cardinal rules but the reason I'm breaking it again is time okay it's quicker to do it this way and again if you want to learn about the way I think you should properly deserialize Jason again checking my course onlinejackson.net anyway enough of that so we're going to create some Dynamic data and if you didn't really follow what I meant by that you'll see in a second okay and we're going to make use of the Jason then you can solve Json framework so Json convert it'll bring in the namespace for that so control periods bringing using sort of Json and then we will deserialize object and what type of object are we going to deserialize into well this is where you can supply this Dynamic keyword okay now usually you would Supply an actual object that you had created or a class type that you'd created over here you know here you can just Supply Dynamic and the Newton soft framework will figure it out for you and what you the serializing from well just this response string that we have here okay so I dislike it but I also really love it at the same time because um when you're just getting stuff when you want to just get stuff up and running quickly and test out this is really really useful to be honest with you okay anyway so we'll do we'll change the color of the text output so we'll say console foreground color equals console color green just to distinguish the output and then what we're going to see is we're going to console right line the following again we'll use string interpolation and we'll see something like API responses okay now obviously we did write out the full string response okay previously we want to just get the text response if I bring up this command from there we just want to get this here in fact we just want to do yeah get this here on a given host that's all we really want here okay and so we can get to that by using this die data object so curly brackets die data and this is where you enter into the danger zone because what I'm going to do is I'm going to basically navigate through that object but again because it's a dynamic object at this point in time I can supply anything I like and it'll only be at runtime that you would get some issues so I'm going to say choices and again let's come back hopefully I still have it here yep so basically I'm navigating through this object so I'm coming down to this choices uh you know attribute here and then I'm going to navigate into the text attribute here okay that's all I'm doing and of course choices is an array so square brackets first element and then the actual text property okay and you can see we weren't getting any chord completion assistance here because at this point in time uh c-sharp does not know that this is what we're going to be getting it's not statically typed okay so it's dangerous and I also want to get rid of that warning that warning was just saying that this die data could be null which indeed it could be so again this is a super dangerous thing I'm doing here which is why I put it in a try catch block because it could not work okay and for me personally in a production type environment I would not do this I'm just doing this because it's quick and easy all right and then finally we just want to reset the color so console reset color just back to whatever it is gray or something all right let's give that a go and bring up our Command Prompt again we'll clear the screen up key up key and let's just ask it the same thing there we go and it's seeing API response is on your system Docker images okay and again I'm still writing out the full Json response okay but that's good we've actually navigated straight to the text element that we want all right that's cool uh been a good spot now so we could we could leave it there but what I want to do as you saw in the demo is take a little step further and we'll work with the text response that we've isolated from our API call and I want to try and isolate the command prompt string within the overall text response because what you'll see when you call the API multiple times even with the same question number one you might get a slightly different responses back usually always has the same command prompt in it but what you'll maybe see is additional text in there maybe like you know a link to an article or a bit more description about what the command does and I don't necess that's quite useful as of itself but in terms of just being able to have a nice quick workflow where we can use the command prompt in our in our command line at our command line and just cut copy and paste it at the point when we need it I want to try and isolate that bit of text so that's what we're going to do next so again yeah the workflow is we get a response back we isolate the command prompt copy it to clipboard and then we can simply do a control V to paste it in at the command prompt when we're happy it's the right one now the routine that we're going to write to isolate the command prompt is super simple actually all we're doing is looking for the last line of text in the overall response of the text component now that works I would say maybe about 60 70 percent of the time the rate the remaining time it doesn't really work because you'll get the last line might be something else or the last line might contain the command prompt along with some other text okay so it's not totally accurate and we could absolutely work on this method that we're going to develop now and make it much much better much more accurate but it's a first pass uh keeping it simple keeping it quick I think it's okay so back over in our code let's get rid of the command prompt and I'm going to create as I said a separate method to try and guess or isolate the command prompt former text a component in the API response so static method returns a string we'll call it guess command and we're just going to pass in string which is just this bit here the text component of our API response this thing that we are displaying on screen okay that's it I'm going to take that in so I'm just going to do a little bit of debugging here just to help us along you may want to turn this off at some point but just for the purposes of this video and my sanity I'm going to put this in and we'll see a GPT 3 API you turned text okay and what I'll do is we'll change the color of the console text just so we can kind of differentiate and we'll say console color yellow excellent and then we'll just write it out to the screen console right line and yeah just pump out the raw string excellent and then our methodology for isolating it as I said is super simple we just want to get the last but we just want to isolate the last line of the body and the way I'm going to do that is just to get the index of the last new line character so using our raw string we'll get the last index of and we'll just look for a new line character now if that isn't a new Lane character we'll just return the I think it was turning zero or whatever I can't remember it doesn't really matter anyway this routine will just return the the string and then we'll just make our guess we'll create another string uh to contain our gas I'm going to call it gas and we'll make that equal to Raw substring last index plus one okay and that will give us you know the string from the that index onwards we'll reset the console column so we're not writing out yellow any longer and then the other thing we want to do well while we're thinking about it is if you remember back over here we did add this text copy package I want to copy our guess to the clipboard anyway even if it's a bad case I just want to do that anyway so we'll use text copy clipboard service set text and we'll just put gas into it and yeah as I said that they kind of you know a bit earlier on copying a bit of string is copying a string to the clipboard from a console application is not really an expected use case and so that isn't really the support for it it's not that no you can do it you can do other ways outside of using this but this is a nice way of doing it I think to be honest with you all right cool so that's our guess command function or method completed so we'll just come back up here and we'll just jiggle this around a little bit and we'll make use of it so after making our deserialization call here we're going to create a string call it gas and we'll make that equal to guess command and we'll just pass through this fantastic we'll set the foreground color to Green and then we'll just change this console right line to something a little different I'll actually write out the gas and we will see my guess at the command prompt is and we will put a guess all right and then we'll reset the color there as well and what I'll also do is people just uh we'll just remove this and that was just waiting out the full actually we'll leave um I'll just comment out just in case we want to re-enable it again it just seems a bit typing but I don't want to do that okay I think that looks pretty good so let's give that a go now make sure it's saved control back tick clear the screen we'll do an up key up key run this again excellent so you can see here gpt3 API returned the text on the host so all the stuff in yellow is what we actually got back from GPT on the host a couple of new lines Docker images and so then a little guest routine has run and we've just isolated the last line which is Docker images and if we do a Ctrl d it was copied to clipboard and we have that command available for us and see I do actually have Docker running so this will error but that is the right command prompt excellent looking good let's just try it again see if we get a different response back which I have seen yes you can see it's ever so slightly different we didn't have that accounting Bob for the last one said but there was a kind of another bit of yellow text there saying something this one is slightly different but again working quite nicely excellent so the last set of our build is I want to take our application and I want to package it into a single executable so that we can actually use it in Anger at our Command Prompt by just using the ASC command Okay so the moment we're using Docker run I want to be able to type ask and then pass in you know whatever we want to ask it and have that as a little command line utility that we can run on our machine so we'll do that next so in terms of creating a single file executable I'm just following this document here that Microsoft have provided and I'll put the link in the description below so you can take a look now basically what you'll need to do is you'll have to add some of these um headers on my headers attributes to your CS project file within your property group so we'll do that and then you need to publish the app for a specific platform and architecture processor architecture so this is actually the command I'm going to eventually run.net publish Dash or win x64 because I'm running on windows with this particular processor architecture and you know they've even given you an example below if you're running on Linux okay so it's slightly different from just using.net run which is just ubiquitous you can run that on Linux Mac windows and it'll just run if you want to produce this single file executable you actually need to Target the specific platform so you need to create an XE for each platform which I don't think is unrealistic or unreasonable okay so just calling that out so let's not take too much more time I'll get rid of the command line prompt that could work on our CS project file yeah we're just going to add in some attributes within our property group and I'm just going to paste those in I don't think you want to see me typing those I could have had this rule where I prefer to type code I don't really type configured can I consider this config and it's literally just the stuff lifted and shifted from that article anyway so this these four are the ones that I kind of showed you in the article so let's bring it back onto screen here they are just these four here and then you'll have noticed there's a fifth one there that I've also put in and that comes down to here it's just this one here and that's about including the pdb file inside the bundle as well okay so I just included that as well so we definitely just end up with one file so we'll save that off and then all we need to do bring up the command prompt again clear the screen and we will just publish that executable for my particular platform which is when windows on the X 64 architecture here we are so just copy this maybe we should have used that application to see if it would give us a command prompt I'm not that brave though so let's go for it and uh we will see what happens okay perfect and it's this path here that you can see so nice you know this is my working directory if we follow this path all the way along there is an executable at this end point here so I just bring Windows Explorer onto the screen I've just navigated to ask bin debug net 6.0 here's the architecture folder they go in there there's a publish and then we have our ask executable excellent so that's looking good so I'm going to do is I'm going to copy that and I'm going to paste it into my E1 folder yeah let's put it into E1 okay so it's now sitting at you know my D drive S6 E1 and then I want to add this entry to my path variable to my path environment variable so a path environment variable just stores the paths of preo your command prompt amongst other things can find executable files so on Windows I've just clicked on a little search icon if you just start typing environment you should get something like this edit system environment variables and that's popped up on my other screen here we go and I'll just go into the environment variable settings this is what I want to add an entry to this or path click edit and as you can see here here are all the all the different segments that you know executable files can be found at so I'm just going to add a new one it'll be my D drive on my oh I'm going to get this right season six folder in the episode one directory and I'm not sure if it makes any difference but I'll just put I don't think it does put a trailing backslash as well so that's definitely correct yeah it looks good so click ok ok on that perfect and then we'll start a command prompt here and what that should allow us to do assuming it right in the path environment variable okay it should allows just to be able to type ask and then surely I can spell ask correctly and um let's just try this one here for what command do you use to hot reload a.net project and it should just go in work as before so again GPT 3 Return of the text and there's a couple of new lines and then this is the whole of the last line and so again as per our guess it's just guessed that this is the whole thing so if we do a control V not exactly what we want do you know what I mean and so we could definitely iterate around the guessing routine to try and isolate you know the.net watch component but I think that could actually get quite tricky to be to be honest with you I've been thinking about how you could do that I think it would be quite tricky if you've got any ideas please put them in the description below as you've said as you've seen sorry for you know other other ones it seems to work quite well so what command do you use to list Docker containers let's see what we get and again we get some you know question mark a couple of new lines and then my guess is dockerps which again control V is still at the command prompt followers and we can just run that excellent so that brings us to the end of this hopefully relatively quick video I've really enjoyed working with this API there's actually loads of other endpoints that you can explore and play around with you can create images and all that kind of stuff it's really rather cool but um for me I actually enjoy this little command prompt and I'm going to see if I might use it um in my actual workings as a developer it saves me having to go and Google things outside of my developer workflow and if there was one thing I was going to change firstly it would be the functionality of this guessing routine and then I would obviously go back and I would productionize things like not storing the API key and the code and um yeah there's a few other things here not having the Json there's a string and all that kind of stuff so there's loads of stuff you can do to really tighten this up and make it much better again the code is on GitHub so you can maybe have a go at doing that yourself anyway that's it for this video I've really enjoyed making it it's lovely to have you with me if you did enjoy it maybe give it a like and if you've not done so already maybe think about subscribing to the channel and other than that to my patreon supporters thank you for that extra support and your names are coming up next [Music] foreign [Music] [Music] [Music] foreign [Music] foreign [Music] foreign [Music]
Info
Channel: Les Jackson
Views: 91,751
Rating: undefined out of 5
Keywords:
Id: 25i-Dh6U6Cw
Channel Id: undefined
Length: 52min 28sec (3148 seconds)
Published: Mon Jan 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.