1
00:00:00,000 --> 00:00:05,000
So guys now let's continue and let's start building our LLM application okay.

2
00:00:05,000 --> 00:00:12,000
So uh see if I want to probably interact see whenever you user gives any kind of query, building an

3
00:00:12,000 --> 00:00:17,000
LLM application basically means let's say if I'm giving any query, uh, to my model, my model should

4
00:00:17,000 --> 00:00:19,000
be able to give some response.

5
00:00:19,000 --> 00:00:19,000
Okay.

6
00:00:19,000 --> 00:00:27,000
But you should understand some very key libraries that are specifically used in long chain, which we

7
00:00:27,000 --> 00:00:28,000
also see it as Runnables.

8
00:00:28,000 --> 00:00:29,000
Okay.

9
00:00:29,000 --> 00:00:31,000
so we'll be discussing more about it as we go ahead.

10
00:00:31,000 --> 00:00:36,000
But just to give you an idea like which are the common libraries that we specifically use, like let's

11
00:00:36,000 --> 00:00:42,000
say if the LM model is getting some kind of message, uh, if I want to tell the LM model to behave

12
00:00:42,000 --> 00:00:47,000
in a certain way, how do I probably mention that all those things also will go ahead and discuss?

13
00:00:47,000 --> 00:00:52,000
So first of all, what I will do is that quickly I will go ahead and install one more library which

14
00:00:52,000 --> 00:00:55,000
is called as lang chain underscore core.

15
00:00:55,000 --> 00:00:56,000
Okay.

16
00:00:56,000 --> 00:01:01,000
Now this particular library is important because I will be discussing about some of the libraries that

17
00:01:01,000 --> 00:01:04,000
I'm actually going to use from this particular library itself.

18
00:01:04,000 --> 00:01:05,000
Right.

19
00:01:05,000 --> 00:01:06,000
Some of the important components.

20
00:01:06,000 --> 00:01:10,000
So once I install this you can also see that the requirement is already satisfied.

21
00:01:10,000 --> 00:01:13,000
I will go ahead and update in the requirement dot txt.

22
00:01:13,000 --> 00:01:18,000
Now I will go ahead and write from lang chain okay.

23
00:01:18,000 --> 00:01:23,000
Underscore core underscore core okay.

24
00:01:23,000 --> 00:01:29,000
Dot messages I'm going to import one is called as human message.

25
00:01:29,000 --> 00:01:33,000
And the other one is something called as system message.

26
00:01:33,000 --> 00:01:33,000
Okay.

27
00:01:34,000 --> 00:01:37,000
Now why this human message and system message is required.

28
00:01:37,000 --> 00:01:43,000
See whenever we chat or whenever we provide any messages to our LM model, we should specify our LM

29
00:01:43,000 --> 00:01:50,000
model, which message is basically provided by the human being, and which message is a kind of instruction

30
00:01:50,000 --> 00:01:51,000
to the LM model.

31
00:01:51,000 --> 00:01:57,000
So the system message that you have, this is just like an instruction that how the LM model should

32
00:01:57,000 --> 00:02:03,000
basically work like okay, so here what I will do, I will just go ahead and create a list of messages

33
00:02:03,000 --> 00:02:03,000
okay.

34
00:02:04,000 --> 00:02:07,000
And this list of messages I'm going to pass to my LM model okay.

35
00:02:08,000 --> 00:02:14,000
Now inside this list of messages I have to first of all say okay, how the LM model should behave like.

36
00:02:14,000 --> 00:02:16,000
So here I'm just going to use my system message.

37
00:02:16,000 --> 00:02:19,000
And I'm going to say that, hey, let's create this particular content.

38
00:02:19,000 --> 00:02:34,000
The content will be I will say hey translate the following following from English to French.

39
00:02:34,000 --> 00:02:36,000
Okay, French.

40
00:02:37,000 --> 00:02:41,000
So this is what I'm actually telling my LM model to basically do.

41
00:02:41,000 --> 00:02:46,000
The second message will be that whatever human is basically asking what sentence it really needs to

42
00:02:46,000 --> 00:02:49,000
convert, we can go ahead and write human message is equal to.

43
00:02:50,000 --> 00:02:53,000
And here let's say I will go ahead and write content as.

44
00:02:53,000 --> 00:02:53,000
Hello.

45
00:02:54,000 --> 00:02:55,000
How are you?

46
00:02:55,000 --> 00:03:02,000
Okay, so this is the content that I really want to send to the system that is my LLM and get the response.

47
00:03:02,000 --> 00:03:02,000
Okay.

48
00:03:02,000 --> 00:03:07,000
So we have created this list of messages in the form of system message and human message.

49
00:03:07,000 --> 00:03:12,000
Again, repeating what the system message basically does is that it instructs the LLM model like how

50
00:03:12,000 --> 00:03:15,000
it really needs to behave or work like right.

51
00:03:16,000 --> 00:03:20,000
In this particular case, it needs to work like a translator which will be converting from English to

52
00:03:20,000 --> 00:03:21,000
French.

53
00:03:21,000 --> 00:03:25,000
Then I'm also giving the human message like what sentence I really need to convert.

54
00:03:25,000 --> 00:03:32,000
Now if I get this list of messages now, I can use my model, I can invoke I can invoke this specific

55
00:03:32,000 --> 00:03:33,000
messages.

56
00:03:33,000 --> 00:03:35,000
So let me just go ahead and invoke this.

57
00:03:35,000 --> 00:03:40,000
And once I get and once I execute this here, you'll be able to see some output.

58
00:03:40,000 --> 00:03:43,000
And this output starts with something called as a message.

59
00:03:43,000 --> 00:03:46,000
And the output over here is Bonjour.

60
00:03:46,000 --> 00:03:52,000
Whenever I get an, uh, output which says of I message, this basically means it is a response from

61
00:03:52,000 --> 00:03:53,000
my LM model.

62
00:03:53,000 --> 00:03:55,000
Okay, so here it shows.

63
00:03:55,000 --> 00:03:56,000
Hey, content is bonjour.

64
00:03:56,000 --> 00:03:57,000
And that is what we basically say.

65
00:03:57,000 --> 00:03:59,000
Hello, how are you in French?

66
00:03:59,000 --> 00:04:04,000
If we try to convert this we basically say Bonjour, comment allez vous.

67
00:04:04,000 --> 00:04:09,000
Okay, I don't know this one, but at least I know bonjour and I think it is correct itself.

68
00:04:09,000 --> 00:04:12,000
It cannot be wrong because we are working with powerful LM models.

69
00:04:12,000 --> 00:04:17,000
Then, uh, along with that you'll also be able to see some response metadata, like how much tokens

70
00:04:17,000 --> 00:04:21,000
it has basically created, how much prompt tokens are there total tokens.

71
00:04:21,000 --> 00:04:22,000
Completion time.

72
00:04:22,000 --> 00:04:23,000
Prompt time.

73
00:04:23,000 --> 00:04:23,000
Right.

74
00:04:23,000 --> 00:04:24,000
Uh, total time.

75
00:04:24,000 --> 00:04:27,000
Along with that, which model name we have basically used.

76
00:04:27,000 --> 00:04:31,000
And these are my metadata information that you'll be able to see at the last.

77
00:04:31,000 --> 00:04:34,000
You'll also be able to see that how many were input tokens.

78
00:04:34,000 --> 00:04:37,000
So input tokens were 26 output tokens I got as 11.

79
00:04:38,000 --> 00:04:39,000
So total tokens is 27.

80
00:04:39,000 --> 00:04:44,000
By seeing all this particular information, you get to know that how much cost is basically involved,

81
00:04:44,000 --> 00:04:46,000
uh, with respect to each request.

82
00:04:46,000 --> 00:04:46,000
Mm.

83
00:04:47,000 --> 00:04:50,000
Now when I'm getting the output as I message okay.

84
00:04:50,000 --> 00:04:54,000
That basically means we are getting the response from the, uh, LM model.

85
00:04:54,000 --> 00:04:54,000
Okay.

86
00:04:54,000 --> 00:04:59,000
Now, there may be scenarios that I just want I'm just interested with this particular content.

87
00:04:59,000 --> 00:05:01,000
Now for that, what do I do?

88
00:05:02,000 --> 00:05:07,000
Along with this invoke function, you know, whatever response I specifically get, whatever results

89
00:05:07,000 --> 00:05:14,000
I actually get, let me just go ahead and save this in one kind of, uh, result or response.

90
00:05:14,000 --> 00:05:16,000
So here I will say, hey, this will basically be my result.

91
00:05:16,000 --> 00:05:17,000
Okay.

92
00:05:17,000 --> 00:05:25,000
Now what I will do there is something called as string output parser because see here we know that this

93
00:05:25,000 --> 00:05:28,000
result is nothing, but it is a I message.

94
00:05:28,000 --> 00:05:28,000
Okay.

95
00:05:28,000 --> 00:05:31,000
But I want to only retrieve this particular output.

96
00:05:31,000 --> 00:05:31,000
Right.

97
00:05:31,000 --> 00:05:39,000
So for that in uh lang chain, if I go ahead and say in lang chain underscore core okay.

98
00:05:39,000 --> 00:05:43,000
Underscore core, we have something called as output parser.

99
00:05:43,000 --> 00:05:50,000
This output parser will be responsible to basically display the message that is coming out side as the

100
00:05:50,000 --> 00:05:52,000
response from the LM model.

101
00:05:52,000 --> 00:05:52,000
Okay.

102
00:05:52,000 --> 00:05:55,000
So here we will go ahead and import string output parser.

103
00:05:56,000 --> 00:05:58,000
And I will just go ahead and create my parser.

104
00:05:58,000 --> 00:06:01,000
So let's go ahead and initialize this string output parser.

105
00:06:01,000 --> 00:06:07,000
What this string output parser is going to do is that it is just going to display my content message

106
00:06:07,000 --> 00:06:07,000
out, right?

107
00:06:07,000 --> 00:06:08,000
So this is the default.

108
00:06:08,000 --> 00:06:12,000
You can also go ahead and create your own custom string output parser if you want.

109
00:06:12,000 --> 00:06:15,000
So uh from this particular result.

110
00:06:15,000 --> 00:06:17,000
So this is the result that I have.

111
00:06:17,000 --> 00:06:22,000
If I say parser dot invoke okay.

112
00:06:23,000 --> 00:06:27,000
And I invoke this or I give this particular result value from this.

113
00:06:27,000 --> 00:06:32,000
So what it is going to do is that this string output parser is going to take the content, uh, from

114
00:06:32,000 --> 00:06:35,000
that particular message, from that I message, and it is just going to display it.

115
00:06:35,000 --> 00:06:38,000
So here you can see Bonjour comment always was okay.

116
00:06:38,000 --> 00:06:41,000
So here you'll be able to see the entire output okay.

117
00:06:41,000 --> 00:06:48,000
Now there is I already told you something called as LCL okay.

118
00:06:48,000 --> 00:06:49,000
In the initial stages.

119
00:06:49,000 --> 00:06:50,000
Right?

120
00:06:50,000 --> 00:06:55,000
I told you about language, expression, uh, language.

121
00:06:55,000 --> 00:06:55,000
Right.

122
00:06:55,000 --> 00:06:55,000
Sorry.

123
00:06:55,000 --> 00:06:56,000
Language and expression.

124
00:06:56,000 --> 00:06:58,000
Language to chain components together.

125
00:06:58,000 --> 00:07:01,000
Now, you know that I have two components over here.

126
00:07:01,000 --> 00:07:03,000
One is my model.

127
00:07:03,000 --> 00:07:03,000
Okay.

128
00:07:03,000 --> 00:07:05,000
Model dot invoke, which is specifically doing.

129
00:07:05,000 --> 00:07:07,000
And the second is my string output parser.

130
00:07:07,000 --> 00:07:15,000
So here using LCL, using LCL, we can chain the components okay.

131
00:07:16,000 --> 00:07:18,000
So we can chain the components.

132
00:07:18,000 --> 00:07:20,000
Chaining basically means one after the other.

133
00:07:20,000 --> 00:07:26,000
So for this I'll create my variable I'll say hey model slash parser okay so here what I'm saying.

134
00:07:26,000 --> 00:07:28,000
So I'm creating a chain of events right.

135
00:07:28,000 --> 00:07:29,000
First of all I'm adding model.

136
00:07:29,000 --> 00:07:30,000
Then I'm adding parser.

137
00:07:30,000 --> 00:07:37,000
Now whenever I invoke I say hey dot invoke and I give my messages parameter.

138
00:07:37,000 --> 00:07:43,000
Over here in this messages we have that list of message of human message and uh, the system message

139
00:07:43,000 --> 00:07:49,000
Once I do this invoke, what it is going to do is that first of all, it is going to go to this particular

140
00:07:49,000 --> 00:07:49,000
model.

141
00:07:49,000 --> 00:07:51,000
It is going to send both those messages to the model.

142
00:07:51,000 --> 00:07:55,000
The model is going to give you the output as a message over here, like how it is given.

143
00:07:55,000 --> 00:07:58,000
Then this particular output is going to go to the parser.

144
00:07:58,000 --> 00:08:01,000
And finally I'll be able to get this particular output okay.

145
00:08:01,000 --> 00:08:03,000
And that is what you'll be able to see over here.

146
00:08:03,000 --> 00:08:05,000
See finally we get this Bonjour command.

147
00:08:05,000 --> 00:08:07,000
Otherwise right.

148
00:08:07,000 --> 00:08:12,000
So this is one way of for creating, uh, agents with LM or.

149
00:08:12,000 --> 00:08:13,000
Sorry.

150
00:08:13,000 --> 00:08:14,000
Uh, not agents.

151
00:08:14,000 --> 00:08:15,000
Sorry.

152
00:08:15,000 --> 00:08:20,000
Uh, creating our, uh, or using our LCL to chain the components.

153
00:08:20,000 --> 00:08:20,000
Okay.

154
00:08:21,000 --> 00:08:24,000
Now, uh, we have discussed about output parser over here.

155
00:08:24,000 --> 00:08:31,000
We have discussed about, uh, the prompt, uh, the LCL chaining the components right now instead of

156
00:08:31,000 --> 00:08:31,000
given.

157
00:08:31,000 --> 00:08:33,000
See, C instead of giving like this.

158
00:08:33,000 --> 00:08:33,000
Right?

159
00:08:33,000 --> 00:08:37,000
Right now we are passing every time list of messages, right?

160
00:08:37,000 --> 00:08:41,000
Instead of this, we can use one more efficient technique and that is nothing.

161
00:08:41,000 --> 00:08:44,000
But it is called as prompt templates.

162
00:08:44,000 --> 00:08:45,000
Okay.

163
00:08:45,000 --> 00:08:50,000
Now with respect to the prompt templates what I will do is that again let's go ahead and do this.

164
00:08:50,000 --> 00:08:56,000
So I'll say instead of just giving the list of message, I will try to, uh, you know, take a combination

165
00:08:56,000 --> 00:09:02,000
of user input and some application logic, you know, uh, where I am also able to give the instruction,

166
00:09:02,000 --> 00:09:04,000
I'm able to take the user input over there.

167
00:09:04,000 --> 00:09:05,000
Okay.

168
00:09:05,000 --> 00:09:10,000
And, uh, this application logic, which I'm actually talking about, is usually takes the raw user

169
00:09:10,000 --> 00:09:14,000
input and transforms into a list of message ready to be passed to the language models.

170
00:09:14,000 --> 00:09:16,000
Now how actually it is done.

171
00:09:16,000 --> 00:09:19,000
I have already told many things over here, so let me just go ahead and write.

172
00:09:19,000 --> 00:09:25,000
Langston underscore so code or prompts and I will go ahead and import chat prompt template okay.

173
00:09:25,000 --> 00:09:27,000
So here I'm going to use this chat prompt template.

174
00:09:27,000 --> 00:09:31,000
Uh again it is available in action underscore core okay.

175
00:09:32,000 --> 00:09:43,000
So first of all I will define my generic underscore template okay I will say hey uh translate the following

176
00:09:43,000 --> 00:09:48,000
into this particular language and this language, I will give it as a parameter okay.

177
00:09:48,000 --> 00:09:49,000
This particular language okay.

178
00:09:49,000 --> 00:09:54,000
And I will give this entire into like this language will be passed as an parameter.

179
00:09:54,000 --> 00:09:55,000
Okay.

180
00:09:55,000 --> 00:09:59,000
Now once I take this particular generic template I will create my prompt okay.

181
00:09:59,000 --> 00:10:04,000
And this prompt will be assigned to this particular prompt template that is chat prompt template.

182
00:10:04,000 --> 00:10:08,000
And here I'm just going to say dot from underscore messages.

183
00:10:09,000 --> 00:10:10,000
Okay.

184
00:10:10,000 --> 00:10:14,000
And here we are just going to give this prompts right.

185
00:10:14,000 --> 00:10:16,000
Like how we give the list of system of messages.

186
00:10:16,000 --> 00:10:17,000
List of messages.

187
00:10:17,000 --> 00:10:18,000
Right.

188
00:10:18,000 --> 00:10:21,000
The first prompt will be in the form of tuple.

189
00:10:21,000 --> 00:10:24,000
Here I'm going to add system comma.

190
00:10:24,000 --> 00:10:29,000
Let's say I'm going to say system comma system template or system comma.

191
00:10:30,000 --> 00:10:33,000
Uh like what is the instruction that you really want to give to the system.

192
00:10:33,000 --> 00:10:36,000
So it will be like a generic template over here okay.

193
00:10:36,000 --> 00:10:40,000
And the next one will be basically with respect to the users.

194
00:10:40,000 --> 00:10:41,000
Right.

195
00:10:41,000 --> 00:10:44,000
So here I instead of just giving the message I'm giving in this way.

196
00:10:44,000 --> 00:10:45,000
So I'll say hey user.

197
00:10:45,000 --> 00:10:49,000
And this will basically be my text okay.

198
00:10:49,000 --> 00:10:50,000
What text I'm actually giving.

199
00:10:50,000 --> 00:10:54,000
So this text we have to give it in the run time okay.

200
00:10:54,000 --> 00:10:55,000
Same thing.

201
00:10:55,000 --> 00:11:00,000
See before we use messages how we are giving this in this particular way here, we are going to give

202
00:11:00,000 --> 00:11:05,000
it in the form of uh chat prompt template where I also have to information system and user.

203
00:11:05,000 --> 00:11:05,000
Okay.

204
00:11:05,000 --> 00:11:08,000
Now this basically becomes my prompt okay.

205
00:11:09,000 --> 00:11:13,000
Now let me quickly go ahead and write something like this prompt.

206
00:11:13,000 --> 00:11:15,000
Or let me just go ahead and execute this.

207
00:11:15,000 --> 00:11:22,000
First of all, now if I go ahead and write prompt dot invoke.

208
00:11:22,000 --> 00:11:22,000
Okay.

209
00:11:22,000 --> 00:11:24,000
If I invoke this okay.

210
00:11:25,000 --> 00:11:27,000
Uh, over here, let's say two parameters I want to give.

211
00:11:27,000 --> 00:11:28,000
Right.

212
00:11:28,000 --> 00:11:29,000
So I'll give it in the form of key value pairs.

213
00:11:29,000 --> 00:11:32,000
One is language will be my input and then it will be text okay.

214
00:11:32,000 --> 00:11:35,000
So first of all we will go ahead and set language.

215
00:11:35,000 --> 00:11:39,000
Let's say language I'm going to set it as French okay.

216
00:11:39,000 --> 00:11:41,000
So it will be French.

217
00:11:41,000 --> 00:11:45,000
And the second parameter that I'm actually going to set it's called as text.

218
00:11:45,000 --> 00:11:46,000
Okay.

219
00:11:46,000 --> 00:11:50,000
So text will be let's say hello I will just say hello okay.

220
00:11:50,000 --> 00:11:55,000
And once I execute this here you'll be able to see that this is what is my entire chat prompt value

221
00:11:55,000 --> 00:12:00,000
and see how beautiful it is converting this into a list of messages.

222
00:12:00,000 --> 00:12:00,000
Right.

223
00:12:00,000 --> 00:12:03,000
So this list of messages that we were getting right.

224
00:12:03,000 --> 00:12:05,000
The same list of messages you will be able to see over here.

225
00:12:05,000 --> 00:12:06,000
Right.

226
00:12:06,000 --> 00:12:10,000
So what this is basically doing this chat prompt template is doing it is converting that into a list

227
00:12:10,000 --> 00:12:10,000
of messages.

228
00:12:10,000 --> 00:12:13,000
So here I have system message translate the following into French.

229
00:12:13,000 --> 00:12:17,000
And then I have my human message content as hello okay.

230
00:12:17,000 --> 00:12:20,000
And this is the power of this prompt right.

231
00:12:20,000 --> 00:12:23,000
This prompt uh whenever we use this chat prompt template okay.

232
00:12:23,000 --> 00:12:29,000
Now this is fine if I just want to get the information like what all messages it is able to convert

233
00:12:29,000 --> 00:12:29,000
to.

234
00:12:29,000 --> 00:12:31,000
So let me just keep this in a variable.

235
00:12:31,000 --> 00:12:33,000
I'll say result is equal to prompt.

236
00:12:33,000 --> 00:12:39,000
And let me just go ahead and write result dot two underscore message okay.

237
00:12:39,000 --> 00:12:40,000
So two underscore message.

238
00:12:40,000 --> 00:12:43,000
Once I do it here you'll be able to see these are my messages that is visible.

239
00:12:43,000 --> 00:12:46,000
And that is the same list of messages that we used to pass earlier.

240
00:12:46,000 --> 00:12:51,000
Now again I will go ahead and try to create a chain.

241
00:12:51,000 --> 00:12:51,000
Right.

242
00:12:51,000 --> 00:12:56,000
So now in this chain, first of all I will go ahead and add my entire prompt.

243
00:12:56,000 --> 00:12:59,000
So so let me just go ahead and add my prompt.

244
00:12:59,000 --> 00:13:01,000
So this will basically be my prompt.

245
00:13:01,000 --> 00:13:06,000
Now after this prompt what will happen is that I will go ahead and give it to my model.

246
00:13:06,000 --> 00:13:08,000
So this will basically be my model.

247
00:13:08,000 --> 00:13:11,000
And finally you'll be able to see that I'll finally get my output.

248
00:13:11,000 --> 00:13:14,000
And this output should also be passed to the parser.

249
00:13:14,000 --> 00:13:14,000
Okay.

250
00:13:14,000 --> 00:13:19,000
So this time using LCL, I've combined three things prompt, model and parser.

251
00:13:21,000 --> 00:13:22,000
Now once I execute it.

252
00:13:22,000 --> 00:13:24,000
So I will go ahead and write chain dot invoke.

253
00:13:25,000 --> 00:13:28,000
And here what are the key parameters that I really want to pass.

254
00:13:28,000 --> 00:13:29,000
One is language.

255
00:13:30,000 --> 00:13:31,000
So let me just go ahead and write.

256
00:13:31,000 --> 00:13:34,000
Language is equal to French.

257
00:13:34,000 --> 00:13:35,000
Okay.

258
00:13:35,000 --> 00:13:41,000
And then text is equal to hello.

259
00:13:41,000 --> 00:13:42,000
Okay.

260
00:13:42,000 --> 00:13:47,000
So once I execute this you'll be able to see that I'm able to get the output as Bonjour.

261
00:13:47,000 --> 00:13:51,000
Okay, so this is how two things we have learned.

262
00:13:51,000 --> 00:13:56,000
One is how to create chain and how to create chain with prompt templates.

263
00:13:56,000 --> 00:13:59,000
So here I'll give this particular comments over here.

264
00:13:59,000 --> 00:14:01,000
Chaining together corporates with LCL.

265
00:14:02,000 --> 00:14:05,000
And here we have combined prompt model and parser.

266
00:14:05,000 --> 00:14:08,000
So I hope you are able to understand this.

267
00:14:08,000 --> 00:14:14,000
Now in the next video, uh what we will do is that we'll try to create, uh, or, you know, uh, let's

268
00:14:14,000 --> 00:14:16,000
say, like, I want to create an end to end project.

269
00:14:16,000 --> 00:14:21,000
I want to make sure that I want to create all these things, all this chain in the form of APIs.

270
00:14:21,000 --> 00:14:22,000
Right?

271
00:14:22,000 --> 00:14:23,000
How do I basically use it?

272
00:14:23,000 --> 00:14:26,000
And for that, we'll be using a new component which is called as Lang sir.

273
00:14:26,000 --> 00:14:29,000
So in the next video we'll be discussing more about the Lang server itself.

274
00:14:29,000 --> 00:14:31,000
So here, uh, this was it from my side.

275
00:14:31,000 --> 00:14:33,000
I hope you liked this particular video.

276
00:14:33,000 --> 00:14:35,000
I will see you all in the next video.

277
00:14:35,000 --> 00:14:35,000
Thank you.

