Visual Studio Prompt Engineering with GitHub Copilot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
prompt engineering is all about how we get large language models to give us the answers we need to solve our problems and help us with our tasks we Face new challenges every day and having tools like get co-pilot by our side can really make a difference in finding Solutions however it's important to remember that these tools might not always hit the mark perfectly with their answers that's why it's crucial to ask our questions in a simple specific and short way this approach helps us get straight to the point and receive accurate responses I'll share some tips and tricks on how to communicate effectively with GitHub co-pilot while coding in Visual Studio by using these strategies we can get better help and make our journey a lot smoother so let's get started let's start off by simply taking a look at the demo application that we're going to be working with throughout this video I have a weather. Json file and here I have a bunch of countries inside of each country are some cities and then months we see January February March Etc and each have a high and low data point here I'm actually running the application already so what I can do is open up the browser and then I'm going to hit try it out to try out this endpoint that we have here it's a get weather forecast for/ countries and when we try this out it returns a list of countries that we have available and that Json so throughout this video alongside learning some prompt engineering best practices for GitHub co-pilot inside of Visual Studio we're also going to be adding an improv approving to this project all right let's start by writing some code I want to create an endpoint that will return the cities of a provided country as an example before we have this one that Returns the countries but in this case we want to be able to provide the country as a parameter now when you're writing comments to leverage as your prompts you want to make sure that you are single short and specific right but you don't want to be too short right if I just write some code for example it's probably not going to provide the best suggestions for me in this case it's not providing any suggestion really but if I leverage this prompt as an opportunity to just explain what I want in my case exactly what I just said return cities of a provided country perhaps this will provide us a better suggestion and actually this looks like what I wanted to do and we can just hit tab to accept this suggestion here awesome now what I'm to do is run this and we're going to wait for the browser to pop up and we should now be able to test this so I know we have Peru as a country here hit execute and this is correct it is now returning the cities of a provided country awesome so you see here it's definitely a balance of those three s is Right single specific and short the more you provide prompts and the better that you are i' expect explaining what you're trying to get at the better responses the better suggestions that you're going to get and obviously the more you do it the better you're going to get at creating these prompts all right so let's now see how we can add some functionality to this code that has been created for us what I'm going to do is select the uh cities uh endpoint that we just created I'll do alt forward slash and ask it to I need to make sure the provided country is in title case can you add that please all of the countries in our weather. Json start with a capital so if we were to provide a country with a lowercase we'd run into some errors so now I'm asking co-pilot by invoking it invoking it with all for slash to go ahead and add that functionality for me and it looks like it is actually doing it correctly I'm hit accept here and what I'm going to do is run this once more and now when we go to our City's endpoint I'm going to hit try it out I'm going to try Peru with a capital execute works perfectly and now I'm going to try Peru with a lowercase here and it works as well we'll try England execute we've got that correctly so it looks like this functionality is now working so now you can see how leveraging your prompt engineering experience to really explain what type of functionality you need to GitHub co-pilot is going to help you implement these functionalities a lot quicker get up co-pilot is great at implementing specific tasks so the first step to get a specific result is obviously highlighting the code that we want to work with so in this case that endpoint and I could ask it something like what airor handling should I Implement for this end point now from experience I'm thinking a null parameter an empty parameter uh something that's not formatted correctly or a parameter that doesn't exist and copalite is telling us argument n exception keynot found exception Json exception and a couple of other things and because we were able to highlight the specific code provide it a specific task we can also Now preview the suggestions that it's provided we're going to hit preview and it's going to tell us what is actually going to change here so I'm going to hit accept because these are all things that I do want to implement I'm going to run this now and we should now be able to H to test out our air handling here so what I'm going to do first is provide a country that I know does exist Peru perfect now a country that I know doesn't exist in R Json Colombia correct and let's just provide empty do a couple of spaces there and it's telling us the country field is required because we provided something empty awesome again because we were able to highlight the code specifically and provide a specific task GitHub co-pilot was able to do the job all right so GitHub co-pilot does have something called slash commands and it has a bunch of preconfigured contexts and functionality that it can Implement without you having to specifically outline what you need in your prompt so as an example what I'm going to do here is actually create a test for this G City's endpoint that we've created who here likes to tester code everyone at home should be raising their hand so we're going to do alt slash here once more and what I'm going to do is say tests and let's try not providing a prompt additional to the slash command and see what it generates for us now I do already have a test file and gith co-pilot will actually know that I have this file instead of creating another one and it tells us here what it's going to add for us here looks like it's adding a get cities with valid Country Return list of cities it's created actually a couple of uh tests here get cities with invalid country get cities with no country get cities with empty country okay awesome now I could add all of these but we could also get a little bit more specific so what I can do is go back here and then once again invoke co-pilot and use the tests SL command once more but I can this time provide a prompt saying create a test that uses Spain as the provided country and returns sevil as the city let's see what it does for us there it should now just generate one test for us because we got a little bit more specific here get cities return list of cities for Spain awesome that looks like what we want it to do we're going to scroll down here okay so what I'm going to do now is go to test test Explorer and run our our tests here and see it worked for us and awesome we can see how slash commands with their built-in functionality can help us accomplish things like creating tests a lot quicker something else I could have done to have gotten this uh end result here is given GitHub co-pilot the reference to the file that actually has the data so I didn't have to guess Madrid or sevil or anything like that right so what I'm actually going to do is erase this here and I'm going to do alt uh Slash here and then say test test for Country Spain and return the correct City from and then in order to reference file we use the pound symbol and we'll say weather. Json because that's where our data is and now it should correctly know that uh the city needs to provide a civil heus and I I would have gotten to this end result the suggestion a lot quicker had I referenced the file and this is something handy you should absolutely include in your prompts because again the more specific you can get the better result all right let's talk a little bit about refinement which is essentially providing an initial prompt and then providing a little bit more context to get the suggestion that co-pilot provides as tailored as possible for the solution that you are looking for right I'm going to select our endpoint once more and let's use another slash command let's use the optimized one just going to analyze our code and provide any improvements that co-pilot thinks would actually make a difference in our project here is the optimized version of your selected code it looks like it's going to remove yes it's removing the TR catch block and it's also replace linked with a for each Loop interesting okay now let's say in the case that I know I don't want to remove link I could say I don't want to remove length here let's see what it provides here here and of course it actually provided an additional suggestion here so it's probably going to add that one here too if you prefer to keep link you could still optimize code by removing the try catch block the try get property method is used to safely access the property while throwing an exception if the property doesn't ex does not exist therefore the adjacent exception will be thrown in this context making the tri catch block unnecessary which makes sense here so pretty good had I provided in my initial prompt so let's do this once more let's say optimize so let's now think about refining our prompt right yeah let's say how to improve this code do not remove link I need to keep it for readability purposes let's see if we can get to that last suggestion in sort of a quicker way because we provided a better prompt we refined our prompt here too as well so here is the optimized version of your code and let's see what it's telling us here the main change here is removing the tri catch block to only cover the code that might actually throw a Json exception awesome so it looks like it is actually working here for us also it's worth noting that the two list call at the end of Link carry will cause the entire sequence to be iterated immediately if the sequence is large this could be a performance issue in our case we have a small data set probably not going to be an issue but something to consider if you have a large data set and awesome you see how we got to what we kind of wanted to get to in the first place a little quicker by refining our prompt and again this is just a skill that you're going to pick up the more you leverage these tools and of course C- pilot is not only great for generating code and having a back and forth with questions optimizing and things like that it can also help us improve our documentation I'm going to open our solution Explorer and I have a readme here but it's a terrible read me because it doesn't have anything in it what I'm going to do here is uh clear this chat and I'm going to provide uh the name of this file which is read me uh uh this one this read me here actually we can reference a file using the pound and I'm going to say how can I improve my read me since I am referencing the file that actually have open here it's going to be able to understand where it needs to add these suggestions a good readme file typically includes the filing sections the project title it says you already have this and it's providing other things that we can additionally insert into our readme we just fantastic because documentation is important right I can hit preview here hit accept and we've got a much better read me than what we had before here we can also use uh ghost so I can say this is AI provides weather information for travel destinations it is part of and I'm assuming it was trying to uh suggest a project link here uh anyway that is how you can improve documentation and referencing piles with GitHub co-pilot and that's it for this video on prompt engineering with GitHub co-pilot and visual studio be sure to check out all the resources that we will have in the description any comments suggestions feedback please leave them in the comment sections I'll be taking a look and we'll see you in the next video with more awesome stuff on GitHub co-pilot with Visual [Music] Studio
Info
Channel: Microsoft Visual Studio
Views: 6,818
Rating: undefined out of 5
Keywords: Visual Studio, GitHub Copilot, Prompting, Prompt engineering
Id: 9hZsOeIINg8
Channel Id: undefined
Length: 13min 25sec (805 seconds)
Published: Wed Apr 10 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.