-: Welcome back, and in this video
we're gonna look at how you can use custom prompts
to tailor the responses you get from GitHub Copilot.
Let's look at the first example,
which we have an original function with no type annotations.
What we're gonna do is select this code,
and I'm gonna hit Command + I,
if you're on Windows hit Control + I.
Then we're gonna say, "I want to upgrade this function
to have type annotations."
Then we're gonna hit Enter,
and just like the other slash commands
that you were seeing in the previous video,
we can actually provide custom prompts to GitHub Copilot.
I'm gonna accept this recommendation.
Let's have a look at another example.
Maybe we want to simplify,
but we want to do it in a way that makes sense for us.
So rather than using the slash simplify,
we're gonna say, "Simplify this function,
but remember to add in some useful comments."
So not only can we tell it to simplify the function,
but we can also tell it add in interesting comments
that might help other software engineers on your team
to really understand the code while still simplifying it.
Let's have a look at a translation task.
We've got some JavaScript code here,
but really what we wanna do is work
with Python code in this example.
So let's select all our code,
and again, if I'm on Windows, it'll be Control + I,
but for Mac it'll be Command + I.
Then we're gonna say,
"Translate this function into Python."
And you can see after we've got that generation,
we've then got our Python function.
So we can translate code directly inside of GitHub Copilot
via a custom prompt.
What other things can we do?
We could also tell it to improve the function.
So we could say "/simplify, improve this function
by adding error checking and handling edge cases."
So not only are we simplifying the function,
but we're also adding in specific edge cases.
Now one thing to watch out from here is you can see,
for example, it's important union, but union isn't defined.
So one way you can actually solve these errors
is you can put them straight back in, right?
And we're just gonna run it again,
and we're gonna say "Union" is not defined,
and we'll pass that specific error back into Copilot.
Copilot's then clever enough to know that
although it's added specific typing to the Python function,
it forgot to add the import.
And therefore we can almost do a circular loop
of constantly feeding back the stack traces
of whatever language you're working in
into Copilot and then fix the code.
Let's also have another look at Copilot Chat.
You can ask general questions in here.
So like, you know,
"Explain and write a bubble sort algorithm in Python."
Now one thing that can be quite good
about using GitHub Copilot over ChatGPT
is that after it's explained
or generated some specific bit of code,
we can go and create a new cell,
or just in any Python file,
and you can see you've got copy to clipboard,
so I can immediately copy it to clipboard.
On the left hand side,
I've also got this insert at cursor,
which is quite nice because, you know,
rather than having to go to ChatGPT and click copy code,
I could just click one button,
and boom, my code is directly inside of the file, right?
So that's really, really fast.
You can also run it directly on the terminal
by clicking the triple dots or insert it into a new file.
So this give you a bit more flexibility
when you feel like being in the flow
and rather than just having to constantly have one screen
with ChatGPT and one screen with GitHub Copilot.
I do still find that ChatGPT is better for exploring,
especially powered by the GPT-4 model,
but it can be quite nice to be in the flow of code
and just using GitHub Copilot Chat.
Cool, I'll see you in the next one.