1
00:00:03,730 --> 00:00:07,360
How do we create prompts with long chain?

2
00:00:08,340 --> 00:00:17,760
If you remember, prompts are simply what we tell a language model, and we know that this input will

3
00:00:17,760 --> 00:00:21,150
guide how this language model responds.

4
00:00:21,540 --> 00:00:29,910
We know as well that there are many types of prompts, and in fact, long chain has a repository of

5
00:00:29,910 --> 00:00:32,610
useful recipes for prompts.

6
00:00:32,729 --> 00:00:36,960
Here you have a link, uh, to see that it's interesting.

7
00:00:36,960 --> 00:00:45,660
It's not super fantastic, but well, it's a good reference to use when you have to create a complex

8
00:00:45,660 --> 00:00:45,990
problem.

9
00:00:45,990 --> 00:00:48,090
So you have a lot of examples there.

10
00:00:48,090 --> 00:00:50,580
It's interesting to pay a visit at least.

11
00:00:50,940 --> 00:00:52,740
What are prompt templates.

12
00:00:52,740 --> 00:01:00,810
So prompt templates are very frequently used when we create applications with long chain.

13
00:01:00,960 --> 00:01:08,670
And the goal of the prompt templates is to, uh, let's say to complete 90% of the final problem.

14
00:01:09,300 --> 00:01:17,040
So we as a LM application developers are going to build most of the prompt like you have here.

15
00:01:17,040 --> 00:01:19,710
Tell me a joke about.

16
00:01:20,390 --> 00:01:21,560
Something, right?

17
00:01:21,560 --> 00:01:26,210
So we are not a completing the prompt.

18
00:01:26,210 --> 00:01:33,710
We are just, uh, entering some information and we are going to ask the user to fill the gaps.

19
00:01:33,710 --> 00:01:34,430
Right.

20
00:01:34,430 --> 00:01:36,320
So these are prompt template.

21
00:01:36,620 --> 00:01:45,110
Uh, in this exercise we are going to create a prompt, uh, for an LM model and also a prompt for a

22
00:01:45,110 --> 00:01:45,830
chat model.

23
00:01:45,830 --> 00:01:48,350
You will see the process is very similar.

24
00:01:48,350 --> 00:01:52,760
The case of the chat model has a couple of different things.

25
00:01:52,760 --> 00:01:56,750
A little bit more sophisticated than than the regular LM model.

26
00:01:56,750 --> 00:02:06,980
So a in the first case we of course, you know, we we connect with the dot m file, uh, in order to

27
00:02:06,980 --> 00:02:10,789
get the credentials for the OpenAI API.

28
00:02:10,789 --> 00:02:20,120
And then what we do is we load the OpenAI module, we create a new instance of the LM a and then we

29
00:02:20,120 --> 00:02:22,550
import the prompt template module.

30
00:02:23,100 --> 00:02:28,950
And there you see, how do we create the final product.

31
00:02:28,980 --> 00:02:36,900
So our final product is going to be the result of combining the initial template with the user input.

32
00:02:36,900 --> 00:02:44,730
In this case, the user is interested in having a joke about French people and he wants to it to be

33
00:02:44,730 --> 00:02:45,210
funny.

34
00:02:45,210 --> 00:02:45,990
Just funny.

35
00:02:45,990 --> 00:02:46,530
Right?

36
00:02:46,530 --> 00:02:51,390
So we are going to combine these user input with the template we have.

37
00:02:51,390 --> 00:02:57,690
So the final problem is going to be tell me a funny joke about a topic.

38
00:02:57,690 --> 00:03:03,570
So as you can see in this template we are including a couple of variables.

39
00:03:03,570 --> 00:03:06,300
We can name our variables whatever we want.

40
00:03:06,300 --> 00:03:09,990
In this case we have called adjective and topic.

41
00:03:09,990 --> 00:03:10,560
Right.

42
00:03:10,560 --> 00:03:21,210
So once we have this template, we need to build a prompt template according to long chain standards.

43
00:03:21,210 --> 00:03:27,480
And in order to do that we have to tell okay we are going to use the prompt module, the prompt template

44
00:03:27,480 --> 00:03:27,990
module.

45
00:03:27,990 --> 00:03:33,150
And here we are going to say okay you need to use this template.

46
00:03:33,150 --> 00:03:36,090
And this template has these two variables.

47
00:03:36,090 --> 00:03:38,490
So we have to be explicit about that.

48
00:03:38,880 --> 00:03:44,340
And then we need to combine this prompt template with this user input.

49
00:03:44,340 --> 00:03:48,210
And we do that in order to create the final prompt.

50
00:03:48,210 --> 00:03:54,600
So the final prompt is going to be a combination of the prompt template with the user input.

51
00:03:54,600 --> 00:03:55,290
Okay.

52
00:03:55,290 --> 00:03:59,100
So uh this is the final prompt.

53
00:03:59,100 --> 00:04:01,560
We get to the language model.

54
00:04:01,560 --> 00:04:07,740
And if we print the response we are going to see here it is the joke about French.

55
00:04:08,400 --> 00:04:11,850
So we can do the same for a chat model.

56
00:04:11,850 --> 00:04:18,300
In this case it's going to be a little bit different because as you remember we are going to need chat

57
00:04:18,300 --> 00:04:21,209
OpenAI instead of OpenAI a module.

58
00:04:21,209 --> 00:04:23,280
And then we have a couple of modules.

59
00:04:23,280 --> 00:04:25,680
Modules that are specific for chats.

60
00:04:25,680 --> 00:04:27,780
But the process is very similar.

61
00:04:27,780 --> 00:04:36,030
We have the user input and we have the chat prompt template, and we combine both of them with the,

62
00:04:36,030 --> 00:04:39,210
in this case the format messages function.

63
00:04:39,210 --> 00:04:43,620
If you remember, in the LM we were using format.

64
00:04:43,620 --> 00:04:47,460
And in the chat model we are using format messages.

65
00:04:47,460 --> 00:04:48,030
Okay.

66
00:04:48,030 --> 00:04:51,330
That that's that's the main difference.

67
00:04:51,990 --> 00:05:00,180
So we will see that uh most LM applications build with lang chain.

68
00:05:00,180 --> 00:05:04,410
Make some use of prompt templates or chat prompt templates.

