WEBVTT

00:00.300 --> 00:01.140
-: Welcome back.

00:01.140 --> 00:02.550
So in this video we'll have a look

00:02.550 --> 00:04.410
at GitHub Copilot prompting.

00:04.410 --> 00:06.900
We'll also make sure that your installation is successful.

00:06.900 --> 00:09.540
So what you should do is in the bottom right here,

00:09.540 --> 00:11.550
you should have this icon.

00:11.550 --> 00:12.750
And then if you see, here it should say,

00:12.750 --> 00:14.670
would you like to disable Copilot?

00:14.670 --> 00:16.350
So we know that Copilot is running.

00:16.350 --> 00:18.450
Another way to test that would be to open up

00:18.450 --> 00:21.210
the 0_single_line_comments.py file

00:21.210 --> 00:24.900
and just have a look and just literally start adding a space

00:24.900 --> 00:26.820
and watching it as Copilot pulls out

00:26.820 --> 00:29.430
this multi-line comment inside of Python.

00:29.430 --> 00:32.220
Cool, let's move on and step it up a notch.

00:32.220 --> 00:35.430
We can also define complete functions

00:35.430 --> 00:36.600
and what those functions should do

00:36.600 --> 00:37.980
inside of Python comments.

00:37.980 --> 00:41.130
So in this example, we've got a function called get name

00:41.130 --> 00:43.920
and return name that takes in a single argument name

00:43.920 --> 00:46.860
and returns, hello name, and then let's see how Copilot

00:46.860 --> 00:48.510
starts to deal with this comment.

00:50.820 --> 00:53.280
Great, so now we've made the function.

00:53.280 --> 00:54.840
Let's also do this one which says,

00:54.840 --> 00:56.380
import the datetime package

00:58.020 --> 00:59.010
and then create a function

00:59.010 --> 01:00.760
that returns today's date and time.

01:05.580 --> 01:07.500
So sometimes here you've got an example

01:07.500 --> 01:09.330
where Copilot isn't starting.

01:09.330 --> 01:11.190
So what I'd recommend is doing something like something

01:11.190 --> 01:13.110
like this whilst adding a def

01:13.110 --> 01:14.940
and then that will trigger Copilot

01:14.940 --> 01:16.920
to then know the next piece of information

01:16.920 --> 01:19.620
that it needs is to make a function name.

01:19.620 --> 01:22.110
As well as that, we don't also just have to use comments.

01:22.110 --> 01:25.740
We could, for example, make a really explicit function name

01:25.740 --> 01:27.960
and then decide to see what happens.

01:27.960 --> 01:31.050
So in this one we've got Return State today's string

01:31.050 --> 01:32.583
using their datetime package.

01:33.450 --> 01:36.540
We can see that Copilot is really able to understand

01:36.540 --> 01:38.640
when we make a very explicit function names,

01:38.640 --> 01:41.280
it knows exactly what needs to happen inside the function.

01:41.280 --> 01:43.230
Let's also take this if statements.

01:43.230 --> 01:47.580
We've got a data Python list with a single key

01:47.580 --> 01:50.490
of a dictionary, single item of a dictionary,

01:50.490 --> 01:51.690
and inside that we've got a customer,

01:51.690 --> 01:53.520
product, quantity and price

01:53.520 --> 01:56.670
and we're saying if the first customer is customer one,

01:56.670 --> 01:59.283
then print customer is the first customer.

02:03.600 --> 02:07.500
So again, Copilot is able to handle if statements.

02:07.500 --> 02:09.810
Let's step it up an notch and look at looping.

02:09.810 --> 02:12.460
We can say, for example, loop over all the customers.

02:14.880 --> 02:17.550
Notice how as well as that, Copilot has copied

02:17.550 --> 02:20.150
some of our original code from the if_statements.py.

02:21.450 --> 02:23.220
The reason why the Copilot is doing this

02:23.220 --> 02:25.530
is 'cause it's scanning your entire project directory

02:25.530 --> 02:26.850
all at the same time.

02:26.850 --> 02:28.860
This could be quite useful because it understands

02:28.860 --> 02:31.800
and starts to learn your individual coding patterns.

02:31.800 --> 02:34.680
Let's have a look at a typing example in Python,

02:34.680 --> 02:37.830
where you can also do things such as import Pandas,

02:37.830 --> 02:41.370
get first customers age with a data frame, which is a type

02:41.370 --> 02:44.430
of PD.dataframe is passed in.

02:44.430 --> 02:46.420
Pandas is really clever

02:47.280 --> 02:50.160
and what we can see here is Copilot not only generates

02:50.160 --> 02:53.340
the documentation for the function given the types,

02:53.340 --> 02:55.530
but it also is able to work out the return type,

02:55.530 --> 02:57.900
knowing that it's probably likely to be an integer.

02:57.900 --> 03:01.230
Also, notice how it's using some package functionality

03:01.230 --> 03:02.400
from Pandas.

03:02.400 --> 03:04.770
Without adding the type, maybe it wouldn't have been able

03:04.770 --> 03:06.450
to reach that extra information.

03:06.450 --> 03:10.380
So having types in your code also helps Copilots understand

03:10.380 --> 03:12.210
what are the types going into the function

03:12.210 --> 03:14.580
and what are the types that should go out of the function.

03:14.580 --> 03:16.470
So far in this video, we've had a look

03:16.470 --> 03:20.040
at all the different ways that I recommend using Copilot.

03:20.040 --> 03:21.810
So not just using it in comments,

03:21.810 --> 03:23.280
but using it for function names.

03:23.280 --> 03:25.140
Also using it inside of your control flow,

03:25.140 --> 03:28.683
such as if statements, for and while loops, et cetera.
