WEBVTT

1
00:00:01.640 --> 00:00:07.460
So, we get some routes for accepting and deleting reservations, but of course there's no business

2
00:00:07.460 --> 00:00:08.320
logic in there.

3
00:00:08.900 --> 00:00:15.680
Now it would make sense to validate any submitted data, to make sure that a valid time and date

4
00:00:15.680 --> 00:00:21.100
was submitted, a valid number of people, and to then maybe store that data in a database.

5
00:00:22.200 --> 00:00:28.640
So what we could do is write another prompt here, refer to that file to be safe, though

6
00:00:28.560 --> 00:00:34.120
it should normally consider the open file, but anyways, and then after adding this context

7
00:00:34.120 --> 00:00:40.700
here say, validate the received input and store it in the database.

8
00:00:41.900 --> 00:00:47.360
Now again, if I write it like this, that's very unspecific, so I'll get a reply, but

9
00:00:47.360 --> 00:00:53.900
chances are that the reply is not really that great, that it's not really what I want.

10
00:00:56.060 --> 00:01:02.080
And there also is another problem with this prompt here, it's not just not very specific,

11
00:01:02.740 --> 00:01:04.980
it also asks for a lot.

12
00:01:06.540 --> 00:01:11.660
I want to validate the received input and store it in a database, and both problems

13
00:01:11.660 --> 00:01:14.580
are more or less complex.

14
00:01:16.039 --> 00:01:21.140
For example, validating the input, I could add way more information here, which input

15
00:01:21.300 --> 00:01:26.980
to validate, what to validate it for, so what my conditions, my criteria are.

16
00:01:28.100 --> 00:01:33.120
And the same for a database, which database, which data should get stored there, and so

17
00:01:33.120 --> 00:01:33.440
on.

18
00:01:33.560 --> 00:01:39.640
So this is a short prompt for a complex problem, and you want to avoid prompts like this.

19
00:01:41.060 --> 00:01:47.000
You want to split them up into multiple problems and into multiple prompts instead, typically.

20
00:01:48.660 --> 00:01:53.580
Because here I'm getting back some code, but I'm not sure if it's really the code I

21
00:01:53.580 --> 00:01:54.000
want.

22
00:01:54.100 --> 00:02:00.940
And indeed here, if you take a closer look at the code it generated here, you can see

23
00:02:00.940 --> 00:02:06.940
that regarding that database storage part, it did not generate any code for that.

24
00:02:07.120 --> 00:02:12.620
It just assumes that there is a reservation model in a models folder in a reservation

25
00:02:12.620 --> 00:02:18.100
file, but that's a file you would have to create, and that's a model you would have

26
00:02:18.020 --> 00:02:18.940
to create as well.

27
00:02:20.260 --> 00:02:22.820
It does not exist here in this project.

28
00:02:23.140 --> 00:02:28.680
So it assumes that this is there, and that this then will store the data in the database.

29
00:02:29.940 --> 00:02:34.320
So if you just apply this code and run it, it simply won't work.

30
00:02:34.500 --> 00:02:39.560
It also assumes that the express validator package is installed, which is also not the

31
00:02:39.560 --> 00:02:39.840
case.

32
00:02:41.680 --> 00:02:47.820
So as you can tell, here it generated some code, which wouldn't work, which would require

33
00:02:47.760 --> 00:02:51.660
a couple of extra steps that are not mentioned here in the response.

34
00:02:52.320 --> 00:03:00.240
And that's why you want to avoid unspecific, complex, multi-problem prompts like this typically.

35
00:03:02.460 --> 00:03:11.940
Instead you can open a new chat, or use the inline chat here actually, and select this

36
00:03:12.160 --> 00:03:14.800
code here, because ultimately that's what I want to validate.

37
00:03:16.100 --> 00:03:20.720
And then just say add code to validate this input.

38
00:03:22.400 --> 00:03:25.660
Don't use an external library.

39
00:03:27.720 --> 00:03:34.540
Number of people should be between 1 and 6, let's say.

40
00:03:35.800 --> 00:03:46.260
Time should be between 5 p.m. and let's say 11 p.m., only every 30 minutes.

41
00:03:47.920 --> 00:03:51.360
Date should be today or in the future.

42
00:03:53.100 --> 00:03:58.320
And now I'll actually add some extra examples regarding the time, because what I want to

43
00:03:58.240 --> 00:04:06.700
allow is that people can book 5 p.m. or 5.30, 6 p.m. or 6.30, but not quarter past five

44
00:04:06.700 --> 00:04:08.740
or 5.10 or anything like that.

45
00:04:10.160 --> 00:04:12.920
So I'll add some extra examples regarding the time.

46
00:04:14.240 --> 00:04:30.440
People should be allowed to book 5, 5.30, 6, 6.30, and so on, but not 5.10, 5.15, etc.

47
00:04:32.039 --> 00:04:37.760
So I'm adding some examples here to add more context in the end to the prompt to hopefully

48
00:04:38.400 --> 00:04:40.820
get exactly the code I'm looking for.

49
00:04:42.960 --> 00:04:48.500
So let's hit enter, and this is a rather complex task now, so let's see what it generates.

50
00:04:49.560 --> 00:04:55.100
Generates a bunch of code and looks like it's done.

51
00:04:56.879 --> 00:05:00.000
So what it's doing here is still extracting.

52
00:05:00.000 --> 00:05:05.140
the data from the body, then it's checking the number of people, if it's

53
00:05:05.140 --> 00:05:09.100
not a number or if it's a number smaller than one or greater than six in

54
00:05:09.100 --> 00:05:16.660
which case it returns an error response, then it validates the time and here it

55
00:05:16.660 --> 00:05:21.040
simply hardcodes the available time slots which I guess makes sense because

56
00:05:21.040 --> 00:05:28.000
it really isn't that many 5 p.m. till 11 p.m. so it does that in the 24-hour

57
00:05:27.920 --> 00:05:33.400
format which is fine by me and then it checks whether the valid times array

58
00:05:33.400 --> 00:05:37.700
includes the time that was submitted with the request and if that's not the

59
00:05:37.700 --> 00:05:44.420
case it will return an error response and for the date it gets the current

60
00:05:44.420 --> 00:05:51.400
date and converts the received date to a date object and then it sets the hours

61
00:05:51.320 --> 00:05:58.220
of today to the start of the day and then checks if the timestamp in

62
00:05:58.220 --> 00:06:04.540
milliseconds of the input date is maybe not a number or if it's smaller than

63
00:06:04.540 --> 00:06:08.600
today if the input data is smaller than today and in either case it sends back a

64
00:06:08.600 --> 00:06:14.900
response. Now we should definitely test this code to make sure it really works

65
00:06:14.900 --> 00:06:19.420
the way it should but it looks good to me so I'll accept this and this shows

66
00:06:19.360 --> 00:06:25.780
you how now we got a vastly different code than what I had before in the chat

67
00:06:25.780 --> 00:06:31.320
so this is what it generated before it just assumed that there was some

68
00:06:31.320 --> 00:06:35.960
validation library and it also ran different kinds of validation now we get

69
00:06:35.960 --> 00:06:41.020
a much better result because we were more specific we added specific useful

70
00:06:41.020 --> 00:06:48.140
context and we added examples and that's why prompt engineering matters once you

71
00:06:48.080 --> 00:06:54.700
know it it's obvious but it's easy to forget or to not even be aware of the

72
00:06:54.700 --> 00:06:58.880
importance of being specific of providing examples and of really

73
00:06:58.880 --> 00:07:03.820
controlling which kinds of results the AI will generate for you

