WEBVTT

00:00.000 --> 00:01.470
-: Welcome back, and in this video

00:01.470 --> 00:04.290
we're gonna look at how you can use custom prompts

00:04.290 --> 00:07.890
to tailor the responses you get from GitHub Copilot.

00:07.890 --> 00:09.480
Let's look at the first example,

00:09.480 --> 00:13.140
which we have an original function with no type annotations.

00:13.140 --> 00:15.600
What we're gonna do is select this code,

00:15.600 --> 00:17.220
and I'm gonna hit Command + I,

00:17.220 --> 00:19.620
if you're on Windows hit Control + I.

00:19.620 --> 00:23.430
Then we're gonna say, "I want to upgrade this function

00:23.430 --> 00:25.287
to have type annotations."

00:26.790 --> 00:28.350
Then we're gonna hit Enter,

00:28.350 --> 00:29.820
and just like the other slash commands

00:29.820 --> 00:31.110
that you were seeing in the previous video,

00:31.110 --> 00:35.610
we can actually provide custom prompts to GitHub Copilot.

00:35.610 --> 00:38.100
I'm gonna accept this recommendation.

00:38.100 --> 00:40.440
Let's have a look at another example.

00:40.440 --> 00:42.420
Maybe we want to simplify,

00:42.420 --> 00:44.700
but we want to do it in a way that makes sense for us.

00:44.700 --> 00:47.340
So rather than using the slash simplify,

00:47.340 --> 00:50.040
we're gonna say, "Simplify this function,

00:50.040 --> 00:54.960
but remember to add in some useful comments."

00:54.960 --> 00:57.240
So not only can we tell it to simplify the function,

00:57.240 --> 00:59.760
but we can also tell it add in interesting comments

00:59.760 --> 01:02.370
that might help other software engineers on your team

01:02.370 --> 01:05.280
to really understand the code while still simplifying it.

01:05.280 --> 01:07.890
Let's have a look at a translation task.

01:07.890 --> 01:09.720
We've got some JavaScript code here,

01:09.720 --> 01:11.040
but really what we wanna do is work

01:11.040 --> 01:13.140
with Python code in this example.

01:13.140 --> 01:14.760
So let's select all our code,

01:14.760 --> 01:17.460
and again, if I'm on Windows, it'll be Control + I,

01:17.460 --> 01:19.170
but for Mac it'll be Command + I.

01:19.170 --> 01:20.077
Then we're gonna say,

01:20.077 --> 01:22.977
"Translate this function into Python."

01:24.660 --> 01:26.550
And you can see after we've got that generation,

01:26.550 --> 01:28.080
we've then got our Python function.

01:28.080 --> 01:31.890
So we can translate code directly inside of GitHub Copilot

01:31.890 --> 01:33.420
via a custom prompt.

01:33.420 --> 01:34.770
What other things can we do?

01:34.770 --> 01:37.200
We could also tell it to improve the function.

01:37.200 --> 01:40.630
So we could say "/simplify, improve this function

01:42.120 --> 01:47.007
by adding error checking and handling edge cases."

01:48.450 --> 01:50.130
So not only are we simplifying the function,

01:50.130 --> 01:52.800
but we're also adding in specific edge cases.

01:52.800 --> 01:55.320
Now one thing to watch out from here is you can see,

01:55.320 --> 01:58.890
for example, it's important union, but union isn't defined.

01:58.890 --> 02:00.960
So one way you can actually solve these errors

02:00.960 --> 02:03.540
is you can put them straight back in, right?

02:03.540 --> 02:05.070
And we're just gonna run it again,

02:05.070 --> 02:06.540
and we're gonna say "Union" is not defined,

02:06.540 --> 02:09.630
and we'll pass that specific error back into Copilot.

02:09.630 --> 02:11.940
Copilot's then clever enough to know that

02:11.940 --> 02:14.790
although it's added specific typing to the Python function,

02:14.790 --> 02:16.860
it forgot to add the import.

02:16.860 --> 02:19.560
And therefore we can almost do a circular loop

02:19.560 --> 02:21.750
of constantly feeding back the stack traces

02:21.750 --> 02:23.520
of whatever language you're working in

02:23.520 --> 02:25.680
into Copilot and then fix the code.

02:25.680 --> 02:28.290
Let's also have another look at Copilot Chat.

02:28.290 --> 02:29.820
You can ask general questions in here.

02:29.820 --> 02:30.787
So like, you know,

02:30.787 --> 02:35.787
"Explain and write a bubble sort algorithm in Python."

02:37.410 --> 02:39.060
Now one thing that can be quite good

02:39.060 --> 02:42.033
about using GitHub Copilot over ChatGPT

02:42.033 --> 02:43.905
is that after it's explained

02:43.905 --> 02:46.860
or generated some specific bit of code,

02:46.860 --> 02:48.210
we can go and create a new cell,

02:48.210 --> 02:49.560
or just in any Python file,

02:49.560 --> 02:51.960
and you can see you've got copy to clipboard,

02:51.960 --> 02:54.510
so I can immediately copy it to clipboard.

02:54.510 --> 02:55.530
On the left hand side,

02:55.530 --> 02:58.350
I've also got this insert at cursor,

02:58.350 --> 03:00.270
which is quite nice because, you know,

03:00.270 --> 03:03.690
rather than having to go to ChatGPT and click copy code,

03:03.690 --> 03:05.010
I could just click one button,

03:05.010 --> 03:08.400
and boom, my code is directly inside of the file, right?

03:08.400 --> 03:09.840
So that's really, really fast.

03:09.840 --> 03:11.850
You can also run it directly on the terminal

03:11.850 --> 03:14.970
by clicking the triple dots or insert it into a new file.

03:14.970 --> 03:16.650
So this give you a bit more flexibility

03:16.650 --> 03:18.300
when you feel like being in the flow

03:18.300 --> 03:20.430
and rather than just having to constantly have one screen

03:20.430 --> 03:23.340
with ChatGPT and one screen with GitHub Copilot.

03:23.340 --> 03:26.580
I do still find that ChatGPT is better for exploring,

03:26.580 --> 03:28.710
especially powered by the GPT-4 model,

03:28.710 --> 03:31.020
but it can be quite nice to be in the flow of code

03:31.020 --> 03:33.090
and just using GitHub Copilot Chat.

03:33.090 --> 03:34.840
Cool, I'll see you in the next one.
