1
00:00:00,000 --> 00:00:00,000
Hello guys.

2
00:00:00,000 --> 00:00:03,000
So we are going to continue the Langton series.

3
00:00:03,000 --> 00:00:07,000
Uh, in our previous video, we have already done the setup of Lang Chain and Lang Smith.

4
00:00:07,000 --> 00:00:10,000
We have also seen how to properly extract the Lang Chain API key.

5
00:00:10,000 --> 00:00:13,000
Along with that, we also saw how to get the OpenAI API key.

6
00:00:13,000 --> 00:00:16,000
And we have set up that entire thing in our environment variable.

7
00:00:16,000 --> 00:00:22,000
Now let's go ahead and probably start this particular coding where we will be using some basics and

8
00:00:22,000 --> 00:00:25,000
common components of lang chain, uh, like uh, prompt templates and all.

9
00:00:25,000 --> 00:00:27,000
But before that, let me do one thing.

10
00:00:27,000 --> 00:00:34,000
Let me clearly show you that how you can go ahead and export all these environment variables that we

11
00:00:34,000 --> 00:00:34,000
have.

12
00:00:34,000 --> 00:00:34,000
Right.

13
00:00:34,000 --> 00:00:36,000
We really need to have that first.

14
00:00:36,000 --> 00:00:40,000
So first of all, what I'm actually going to do, I'm going to go ahead and write import OS.

15
00:00:40,000 --> 00:00:40,000
Right.

16
00:00:40,000 --> 00:00:42,000
OS is one of the library in Python.

17
00:00:42,000 --> 00:00:48,000
Uh, which will be um, you which we will be specifically using to set up our environment variable.

18
00:00:48,000 --> 00:00:55,000
Then if you remember, we had also imported from dot env import load underscore dot env.

19
00:00:55,000 --> 00:01:02,000
Okay so this load underscore dot env will be specifically used to, you know, import all the environment

20
00:01:02,000 --> 00:01:05,000
variables that are available in this dot env file.

21
00:01:05,000 --> 00:01:08,000
And already you know that we have imported this Python dot env.

22
00:01:08,000 --> 00:01:11,000
And from here only this particular library is getting imported.

23
00:01:11,000 --> 00:01:11,000
Okay.

24
00:01:11,000 --> 00:01:16,000
Now the first thing what I'm actually going to do, I'm just going to write OS dot environ.

25
00:01:16,000 --> 00:01:22,000
And here I'm going to set up my open ai API key open underscore AI.

26
00:01:22,000 --> 00:01:26,000
Sorry apo open AI underscore API underscore key okay.

27
00:01:26,000 --> 00:01:32,000
And in order to call that particular environment variable I will just go ahead and write OS dot get

28
00:01:32,000 --> 00:01:33,000
env.

29
00:01:33,000 --> 00:01:39,000
And here we are again going to use the open AI underscore API underscore key okay.

30
00:01:39,000 --> 00:01:44,000
So from the environment variable, uh, the key name that I've actually created is OpenAI underscore

31
00:01:44,000 --> 00:01:48,000
API key that will get uh, set up with this specific environment.

32
00:01:49,000 --> 00:01:52,000
Uh, this was the basic setup.

33
00:01:52,000 --> 00:01:52,000
Okay.

34
00:01:52,000 --> 00:01:58,000
Again, uh, if you, if you probably go ahead and see that we also had created something like Lang

35
00:01:58,000 --> 00:01:59,000
chain API key.

36
00:01:59,000 --> 00:02:00,000
Right.

37
00:02:00,000 --> 00:02:01,000
So that also we'll go ahead and do the setup.

38
00:02:01,000 --> 00:02:06,000
So here I'm going to write OS dot environment environ okay.

39
00:02:06,000 --> 00:02:14,000
And here we are basically going to set up our lang chain underscore API underscore key okay.

40
00:02:14,000 --> 00:02:22,000
And this will be nothing but OS dot get env again with the same name lang chain underscore API underscore

41
00:02:22,000 --> 00:02:22,000
key.

42
00:02:22,000 --> 00:02:27,000
Because this is what we have actually created in our environment variable along with this uh, and this

43
00:02:27,000 --> 00:02:30,000
is specifically used for Lang Smith tracking.

44
00:02:30,000 --> 00:02:31,000
Okay.

45
00:02:31,000 --> 00:02:33,000
We'll discuss about it as we go ahead.

46
00:02:33,000 --> 00:02:37,000
More, uh, and, uh, so this is nothing but Lang Smith tracking.

47
00:02:37,000 --> 00:02:42,000
Okay, uh, along with this, what I am actually going to do, uh, I'm also going to make sure that

48
00:02:42,000 --> 00:02:44,000
I'll go ahead and write OS dot environ.

49
00:02:45,000 --> 00:02:45,000
Okay.

50
00:02:46,000 --> 00:02:51,000
And here no, we will be also setting up our lang chain tracing okay.

51
00:02:51,000 --> 00:02:55,000
So we have to make sure that we set up this particular value.

52
00:02:55,000 --> 00:02:58,000
Also long chain tracing underscore v2.

53
00:02:58,000 --> 00:03:01,000
That is the requirement for long chain to true okay.

54
00:03:01,000 --> 00:03:04,000
So this will basically be set up to true okay.

55
00:03:04,000 --> 00:03:06,000
So till here everything looks perfect.

56
00:03:06,000 --> 00:03:13,000
Uh along with this uh there is one more very much important thing is that is with respect to the, uh,

57
00:03:13,000 --> 00:03:14,000
long chain project.

58
00:03:14,000 --> 00:03:20,000
So here what I'm actually going to do again, we will go ahead and set up OS dot environment.

59
00:03:20,000 --> 00:03:21,000
Okay.

60
00:03:21,000 --> 00:03:24,000
This is just for Lang Smith tracking that is required.

61
00:03:25,000 --> 00:03:31,000
And here I'll just go ahead and call my OS dot get env again.

62
00:03:31,000 --> 00:03:33,000
The name will be nothing but Lang chan project.

63
00:03:33,000 --> 00:03:38,000
Okay so this are my three important keys that I'll be able to set up over here.

64
00:03:38,000 --> 00:03:41,000
And by default, uh, here, you will be able to see that.

65
00:03:41,000 --> 00:03:43,000
what all things I am actually doing.

66
00:03:43,000 --> 00:03:43,000
Right.

67
00:03:43,000 --> 00:03:46,000
So this is my OpenAI API key.

68
00:03:46,000 --> 00:03:47,000
This is my OS dot environment.

69
00:03:47,000 --> 00:03:50,000
Uh, with respect to lang chain API key lang chain tracing needs to be enabled.

70
00:03:50,000 --> 00:03:51,000
So it is set to true.

71
00:03:51,000 --> 00:03:55,000
And then finally we have this uh, lang chain underscore project.

72
00:03:55,000 --> 00:03:56,000
Okay.

73
00:03:56,000 --> 00:03:58,000
So all this, uh, setup is specifically done.

74
00:03:58,000 --> 00:04:02,000
We have also done the installation of, uh, Lam Lang chain.

75
00:04:02,000 --> 00:04:06,000
Now, uh, since we are using luncheon with OpenAI.

76
00:04:06,000 --> 00:04:11,000
So there is one very important library that we have to probably go ahead and do the installation.

77
00:04:11,000 --> 00:04:14,000
That is nothing but lang chain dash OpenAI.

78
00:04:14,000 --> 00:04:16,000
Okay, so open AI.

79
00:04:16,000 --> 00:04:20,000
The reason we have to do this because all the inbuilt function that is required with the integration

80
00:04:20,000 --> 00:04:23,000
of OpenAI, we really need to use this particular library.

81
00:04:23,000 --> 00:04:27,000
So let me quickly go ahead and open my terminal okay.

82
00:04:27,000 --> 00:04:31,000
And here I will just go ahead and run add pip install minus our requirement dot txt.

83
00:04:31,000 --> 00:04:33,000
So the installation will happen.

84
00:04:33,000 --> 00:04:37,000
And now it will also start the installation for Langshan dash OpenAI.

85
00:04:38,000 --> 00:04:38,000
Right.

86
00:04:38,000 --> 00:04:42,000
So it is going to take some time based on the requirements.

87
00:04:42,000 --> 00:04:45,000
So here you can see the installation has basically happened.

88
00:04:45,000 --> 00:04:45,000
Perfect.

89
00:04:45,000 --> 00:04:47,000
So this is good enough.

90
00:04:47,000 --> 00:04:48,000
Uh we are good to go okay.

91
00:04:49,000 --> 00:04:50,000
So I'm just going to close this up.

92
00:04:50,000 --> 00:04:57,000
And now uh, the next step is that how do I probably, um, you know, create or work with chat open

93
00:04:57,000 --> 00:04:57,000
API.

94
00:04:57,000 --> 00:04:58,000
Okay.

95
00:04:58,000 --> 00:05:02,000
Now, since I want to use open AI API key along with that.

96
00:05:02,000 --> 00:05:04,000
So there is a library which is called as Chat open API.

97
00:05:04,000 --> 00:05:10,000
So I will go ahead and write from long chain underscore okay open API.

98
00:05:10,000 --> 00:05:14,000
I'm just going to import something called as open AI.

99
00:05:14,000 --> 00:05:14,000
Right.

100
00:05:14,000 --> 00:05:16,000
So this is this will definitely be there.

101
00:05:16,000 --> 00:05:23,000
And this open OpenAI will specifically be responsible in, you know, creating your object.

102
00:05:23,000 --> 00:05:25,000
But I'll not use OpenAI directly over here.

103
00:05:25,000 --> 00:05:29,000
Instead, let's go ahead and use chat OpenAI because I really want to create a chat bot.

104
00:05:29,000 --> 00:05:29,000
Okay.

105
00:05:29,000 --> 00:05:32,000
Now I will go ahead and create my LLM okay.

106
00:05:32,000 --> 00:05:35,000
And here I'll say, hey, use this chat open API.

107
00:05:35,000 --> 00:05:38,000
And here I'm going to set my API key to nothing.

108
00:05:38,000 --> 00:05:43,000
But it will be the same value that we are going to set it up right.

109
00:05:43,000 --> 00:05:46,000
C API key is nothing but OpenAI underscore API key.

110
00:05:46,000 --> 00:05:52,000
But since I have already made sure that I have created my environment variable, I don't even have to

111
00:05:52,000 --> 00:05:53,000
specify the API key.

112
00:05:53,000 --> 00:05:58,000
Okay, so if I go ahead and execute this and let's go ahead and print my LLM right.

113
00:05:58,000 --> 00:06:01,000
So this will be my LLM model okay.

114
00:06:01,000 --> 00:06:06,000
So here you can see uh install kernel change kernel okay let's do this one thing.

115
00:06:06,000 --> 00:06:11,000
So here you can actually see that I have not installed, uh, IP kernel.

116
00:06:11,000 --> 00:06:16,000
So let me just go ahead and do that pip install IP kernel okay.

117
00:06:16,000 --> 00:06:20,000
Because I really require IP kernel for this.

118
00:06:20,000 --> 00:06:22,000
And I've not even executed this.

119
00:06:22,000 --> 00:06:26,000
So let me quickly install this okay.

120
00:06:26,000 --> 00:06:30,000
So here you can see uh pip install Ipykernel Okay.

121
00:06:30,000 --> 00:06:31,000
Run cells with this.

122
00:06:31,000 --> 00:06:33,000
Uh, let me do one thing.

123
00:06:33,000 --> 00:06:36,000
I'll just go ahead and update over here.

124
00:06:36,000 --> 00:06:37,000
Ipykernel.

125
00:06:37,000 --> 00:06:37,000
Okay.

126
00:06:38,000 --> 00:06:39,000
Ipykernel.

127
00:06:39,000 --> 00:06:42,000
Because for the first time, I think we have to do it from here itself, from the terminal.

128
00:06:42,000 --> 00:06:49,000
So I will just go ahead and open my terminal pip install r requirements.txt quickly, do the installation

129
00:06:49,000 --> 00:06:52,000
of ipykernel, and then I will go ahead and select my kernel over here.

130
00:06:52,000 --> 00:06:54,000
So no need to go ahead and execute it again.

131
00:06:55,000 --> 00:06:55,000
Okay.

132
00:06:56,000 --> 00:06:56,000
Okay.

133
00:06:56,000 --> 00:06:58,000
Right now it is getting installed.

134
00:06:58,000 --> 00:06:59,000
Let's wait for some time.

135
00:06:59,000 --> 00:07:00,000
Okay.

136
00:07:00,000 --> 00:07:04,000
And then you will be able to see that this all errors will probably go but you have to install pip install

137
00:07:04,000 --> 00:07:05,000
ipykernel.

138
00:07:05,000 --> 00:07:06,000
Okay.

139
00:07:06,000 --> 00:07:09,000
So uh, this error that you are seeing I will keep it like that.

140
00:07:09,000 --> 00:07:14,000
I'll not cut it because the simple reason that I really need to show you that where all things you will

141
00:07:14,000 --> 00:07:16,000
be specifically getting an error.

142
00:07:16,000 --> 00:07:20,000
Okay, so Ipykernel is basically getting installed and then only you will be able to attach this particular

143
00:07:20,000 --> 00:07:21,000
kernel.

144
00:07:21,000 --> 00:07:21,000
Okay.

145
00:07:21,000 --> 00:07:23,000
So let's wait for some time.

146
00:07:23,000 --> 00:07:27,000
And uh, it is again, depending on your internet connection it will take how much time to install a

147
00:07:27,000 --> 00:07:28,000
package.

148
00:07:28,000 --> 00:07:29,000
So now the installation is done.

149
00:07:30,000 --> 00:07:32,000
Uh, now let's go ahead and execute this.

150
00:07:32,000 --> 00:07:33,000
So here you can see connecting to a kernel.

151
00:07:33,000 --> 00:07:35,000
And this has got executed okay.

152
00:07:35,000 --> 00:07:37,000
Ipykernel is definitely required.

153
00:07:37,000 --> 00:07:43,000
Now let me just go ahead and execute this LM now here you will be able to see that I have actually got

154
00:07:43,000 --> 00:07:46,000
this particular lm, uh, model, uh, over here.

155
00:07:46,000 --> 00:07:48,000
This is my OpenAI secret key.

156
00:07:48,000 --> 00:07:49,000
Everything is basically there.

157
00:07:49,000 --> 00:07:50,000
Okay, perfect.

158
00:07:50,000 --> 00:07:51,000
This is good.

159
00:07:51,000 --> 00:07:59,000
Uh, now, again, uh, with respect to if whenever we specifically work with, uh, LM models, uh,

160
00:07:59,000 --> 00:08:03,000
one thing that you really need to worry about is, like, what?

161
00:08:03,000 --> 00:08:05,000
All different kind of models are definitely there, right?

162
00:08:05,000 --> 00:08:13,000
And, uh, in in open AI right now, the most famous model that you will probably be seeing is GPT four.

163
00:08:13,000 --> 00:08:14,000
Right.

164
00:08:14,000 --> 00:08:19,000
And how to call that particular model, we'll be seeing how how simply, easily you can basically call

165
00:08:19,000 --> 00:08:19,000
it.

166
00:08:19,000 --> 00:08:22,000
So here what I will do inside this chat open AI.

167
00:08:23,000 --> 00:08:28,000
And for our entire course we'll use the best model instead of using variant different variants model

168
00:08:28,000 --> 00:08:30,000
that is GPT four right.

169
00:08:30,000 --> 00:08:33,000
So here you just need to write model equal to GPT four.

170
00:08:33,000 --> 00:08:33,000
Right.

171
00:08:33,000 --> 00:08:35,000
And now I will go ahead and print my LLM.

172
00:08:35,000 --> 00:08:40,000
So we will be using this particular model because this is the most efficient model that is available

173
00:08:40,000 --> 00:08:41,000
in OpenAI API.

174
00:08:41,000 --> 00:08:42,000
Okay.

175
00:08:42,000 --> 00:08:45,000
So perfect till here you have actually done this.

176
00:08:45,000 --> 00:08:46,000
Everything as such.

177
00:08:46,000 --> 00:08:49,000
So this is how you can load your LLM model okay.

178
00:08:49,000 --> 00:08:54,000
Now with respect to LLM if I want to ask any question.

179
00:08:54,000 --> 00:08:58,000
So let's provide some input and get response from LM okay.

180
00:08:58,000 --> 00:09:04,000
And again, as I said, uh, the reason I'm able to connect it because I have my open API key, uh,

181
00:09:04,000 --> 00:09:06,000
loaded in my environment variable.

182
00:09:06,000 --> 00:09:06,000
Okay.

183
00:09:06,000 --> 00:09:06,000
Sorry.

184
00:09:06,000 --> 00:09:09,000
In my, uh, in as an environment variable.

185
00:09:09,000 --> 00:09:10,000
I have loaded it over here.

186
00:09:10,000 --> 00:09:17,000
Now, in order to give any input to this LM, I will just go ahead and call LM invoke.

187
00:09:17,000 --> 00:09:24,000
And here we will go ahead and write, let's say, uh, how uh, what is generative AI.

188
00:09:24,000 --> 00:09:27,000
So this is my question that I'm asking this LM model okay.

189
00:09:27,000 --> 00:09:29,000
So once I probably go ahead and execute it.

190
00:09:29,000 --> 00:09:33,000
So here you will be able to see that I will be able to get the response, uh, through the API key.

191
00:09:33,000 --> 00:09:33,000
Okay.

192
00:09:34,000 --> 00:09:37,000
Again, uh, this depends on how much time it is going to take.

193
00:09:37,000 --> 00:09:37,000
Okay.

194
00:09:37,000 --> 00:09:40,000
And the best thing why it is taking so much of time, right.

195
00:09:40,000 --> 00:09:41,000
That also you really need to understand.

196
00:09:41,000 --> 00:09:47,000
So here you can see I have actually got this AI message content uh is equal to generative AI, something

197
00:09:47,000 --> 00:09:48,000
like this.

198
00:09:48,000 --> 00:09:48,000
Right.

199
00:09:48,000 --> 00:09:49,000
So let me do one thing.

200
00:09:49,000 --> 00:09:51,000
Let me store this in my result variable.

201
00:09:51,000 --> 00:09:56,000
And now I will just go ahead and print my result okay.

202
00:09:56,000 --> 00:09:57,000
Result okay.

203
00:09:57,000 --> 00:09:59,000
So let's go ahead and print this result.

204
00:09:59,000 --> 00:10:00,000
So it is going to take some time.

205
00:10:00,000 --> 00:10:04,000
The reason it is taking time um why eight seconds has basically taken time.

206
00:10:04,000 --> 00:10:10,000
Because because of this with the help of this long chain API key, we are going to record all these

207
00:10:10,000 --> 00:10:13,000
things, all these events that are specifically happening in the length.

208
00:10:13,000 --> 00:10:14,000
Smith okay.

209
00:10:14,000 --> 00:10:16,000
So if I go ahead and print the result.

210
00:10:16,000 --> 00:10:21,000
So this is what I'm actually getting to get the content, I can just go ahead and write result of content.

211
00:10:21,000 --> 00:10:21,000
Okay.

212
00:10:21,000 --> 00:10:24,000
So here is my output okay.

213
00:10:24,000 --> 00:10:26,000
Uh I message is not susceptible.

214
00:10:26,000 --> 00:10:29,000
Let's see what is the error result.

215
00:10:29,000 --> 00:10:32,000
Uh content is equal to generative AI.

216
00:10:32,000 --> 00:10:35,000
So here is my entire output that I am able to get.

217
00:10:35,000 --> 00:10:36,000
Okay.

218
00:10:37,000 --> 00:10:42,000
Uh, let's see, uh, we will try to I'll also say why we are getting this error, but just in some

219
00:10:42,000 --> 00:10:45,000
time, because I really need to show you some very, very important thing.

220
00:10:45,000 --> 00:10:46,000
So let me do one thing.

221
00:10:46,000 --> 00:10:48,000
Let me just go back to my browser.

222
00:10:49,000 --> 00:10:52,000
Uh, let me show you this.

223
00:10:52,000 --> 00:10:52,000
Okay.

224
00:10:52,000 --> 00:10:53,000
Just a second.

225
00:10:53,000 --> 00:10:56,000
I will just go to by browser over here.

226
00:10:56,000 --> 00:10:56,000
Okay.

227
00:10:56,000 --> 00:10:59,000
Now, inside this browser, let me just go to my langsamt.

228
00:10:59,000 --> 00:11:00,000
Okay.

229
00:11:00,000 --> 00:11:02,000
Now if I go ahead and click on the project.

230
00:11:02,000 --> 00:11:05,000
So here you can see j'en ai app with open AI right.

231
00:11:05,000 --> 00:11:08,000
And here if you go ahead and see there are two chat open AI request.

232
00:11:08,000 --> 00:11:08,000
Right.

233
00:11:08,000 --> 00:11:11,000
What other question I asked what is generative AI?

234
00:11:11,000 --> 00:11:12,000
So see how beautifully.

235
00:11:12,000 --> 00:11:17,000
As soon as I probably hit the LM model, everything is basically getting tracked in this particular

236
00:11:17,000 --> 00:11:17,000
Lang Smith.

237
00:11:17,000 --> 00:11:18,000
Now.

238
00:11:18,000 --> 00:11:21,000
I hope everybody is able to understand why Lang Smith is super amazing, right?

239
00:11:21,000 --> 00:11:27,000
Because if you see the entire ecosystem, uh, Lang Smith is a uniform DevOps platform for developing,

240
00:11:27,000 --> 00:11:30,000
collaborating, testing, deploying and monitoring LLM application.

241
00:11:30,000 --> 00:11:31,000
That is the most amazing thing.

242
00:11:31,000 --> 00:11:33,000
And right now here you can see right.

243
00:11:33,000 --> 00:11:34,000
And now let's go ahead and do one thing.

244
00:11:34,000 --> 00:11:36,000
Let's click on this request.

245
00:11:36,000 --> 00:11:38,000
So here you will be able to see what is the human feedback that was given.

246
00:11:38,000 --> 00:11:40,000
Then what is the output that we got right.

247
00:11:40,000 --> 00:11:42,000
Everything is basically getting displayed.

248
00:11:42,000 --> 00:11:44,000
How much delay is basically happening?

249
00:11:44,000 --> 00:11:44,000
Right.

250
00:11:44,000 --> 00:11:45,000
Uh, how much delay?

251
00:11:45,000 --> 00:11:46,000
Latency.

252
00:11:46,000 --> 00:11:46,000
Right.

253
00:11:46,000 --> 00:11:47,000
Tokens.

254
00:11:47,000 --> 00:11:52,000
And it also probably suggest you how much cost it is basically taking based on the token size.

255
00:11:52,000 --> 00:11:52,000
Right.

256
00:11:52,000 --> 00:11:54,000
So 364 token, 494 token.

257
00:11:54,000 --> 00:11:57,000
This much cost has basically incurred in my OpenAI.

258
00:11:57,000 --> 00:11:57,000
Right.

259
00:11:57,000 --> 00:12:01,000
And this is how beautifully we are able to develop this entire thing right now.

260
00:12:01,000 --> 00:12:06,000
Coming to the next step over here, you can see that I have actually displayed the results.

261
00:12:06,000 --> 00:12:08,000
Uh, and this is my entire results over here.

262
00:12:08,000 --> 00:12:12,000
Okay, now, uh, let me work along with chat prompt template.

263
00:12:12,000 --> 00:12:15,000
Now, see, uh, there is something called as prompt template.

264
00:12:15,000 --> 00:12:23,000
And uh, again prompt template is like how you want your LM model to behave or what kind of response

265
00:12:23,000 --> 00:12:26,000
or what kind of role you really want to give your LM model.

266
00:12:26,000 --> 00:12:32,000
I can say, hey, act as an AI engineer and provide me suggestion how to develop an amazing AI project.

267
00:12:32,000 --> 00:12:32,000
Right?

268
00:12:32,000 --> 00:12:34,000
So that is a kind of rule.

269
00:12:34,000 --> 00:12:37,000
I'm setting it to my LM app itself, ai lm model itself.

270
00:12:37,000 --> 00:12:41,000
Hey, you have to behave in this specific way and give me the answer, right?

271
00:12:41,000 --> 00:12:46,000
So similarly, um, Lang Chain also supports, uh, different types of chat prompt template also.

272
00:12:46,000 --> 00:12:47,000
Right.

273
00:12:47,000 --> 00:12:49,000
So that is what I'm actually going to show you.

274
00:12:49,000 --> 00:12:51,000
So now we are going to discuss about chat prompt template.

275
00:12:51,000 --> 00:12:56,000
So I have just shown you one way of calling this particular model we'll be discussing as we go ahead.

276
00:12:56,000 --> 00:13:00,000
Right now, uh, what I'm actually going to do over here, I'll just go ahead and write from Lang Chen.

277
00:13:00,000 --> 00:13:01,000
Okay.

278
00:13:01,000 --> 00:13:05,000
Lang Chen underscore core okay.

279
00:13:05,000 --> 00:13:08,000
Dot prompts okay.

280
00:13:08,000 --> 00:13:12,000
Dot prompts I'm just going to import chat prompt template okay.

281
00:13:13,000 --> 00:13:15,000
Now what is this chat prompt template we'll discuss about okay.

282
00:13:16,000 --> 00:13:17,000
Now chat prompt template.

283
00:13:17,000 --> 00:13:20,000
Uh it it is just like I can tell my LM model.

284
00:13:20,000 --> 00:13:23,000
Hey, you you have to behave something like this.

285
00:13:23,000 --> 00:13:26,000
Okay, so let's say I will just go ahead and create my custom prompt.

286
00:13:26,000 --> 00:13:29,000
So here I will go ahead and write prompt is equal to chat prompt template.

287
00:13:29,000 --> 00:13:35,000
Now here uh with respect to this prompt template I will be using one very important function which is

288
00:13:35,000 --> 00:13:36,000
called as from messages.

289
00:13:36,000 --> 00:13:42,000
And from this particular messages we will define our entire like what my LM model needs to behave like.

290
00:13:42,000 --> 00:13:42,000
Right.

291
00:13:42,000 --> 00:13:45,000
So here I can probably go ahead and create my list.

292
00:13:45,000 --> 00:13:50,000
Now inside this list I will be giving in the form of tuples my key value pairs.

293
00:13:50,000 --> 00:13:55,000
So first thing when I go ahead and write hey system I'm assigning some role to the system.

294
00:13:55,000 --> 00:13:57,000
System basically means my LM model.

295
00:13:57,000 --> 00:14:04,000
Let's say hey you are an expert AI engineer okay.

296
00:14:05,000 --> 00:14:09,000
Provide me answers based on the question.

297
00:14:11,000 --> 00:14:11,000
Okay.

298
00:14:11,000 --> 00:14:12,000
Something like this.

299
00:14:12,000 --> 00:14:17,000
So this is a very simple role that I'm giving to my system, my LM model saying that, hey, you are

300
00:14:17,000 --> 00:14:19,000
an expert AI engineer okay.

301
00:14:19,000 --> 00:14:23,000
So please go ahead and provide me some answers based on the questions that I have.

302
00:14:23,000 --> 00:14:23,000
Right.

303
00:14:23,000 --> 00:14:25,000
So this is one very important thing.

304
00:14:25,000 --> 00:14:30,000
Now the this is for the system, but what with respect to the users.

305
00:14:30,000 --> 00:14:30,000
Right.

306
00:14:30,000 --> 00:14:33,000
So here I'll go ahead and write user comma.

307
00:14:33,000 --> 00:14:36,000
And here I'll say hey user will provide you some inputs okay.

308
00:14:36,000 --> 00:14:39,000
This input is just like a placeholder okay.

309
00:14:39,000 --> 00:14:43,000
This input is just like a placeholder like user is asking you any question.

310
00:14:43,000 --> 00:14:47,000
Then the system the LLM model is ah, basically an AI engineer.

311
00:14:47,000 --> 00:14:51,000
It should provide me the answer based on the question provided by the user or based on the questions.

312
00:14:51,000 --> 00:14:52,000
Okay.

313
00:14:52,000 --> 00:14:55,000
So the way uh, this is what is a very simple mechanisms.

314
00:14:55,000 --> 00:14:56,000
Okay.

315
00:14:56,000 --> 00:14:59,000
And, uh, this is my entire prompt template that I have actually created.

316
00:14:59,000 --> 00:15:00,000
Okay.

317
00:15:00,000 --> 00:15:03,000
Now if I go ahead and just execute this okay.

318
00:15:03,000 --> 00:15:04,000
And show you.

319
00:15:04,000 --> 00:15:07,000
So this becomes my child prompt template, my input variables is input.

320
00:15:07,000 --> 00:15:10,000
And here you can see system prompt template input variables.

321
00:15:10,000 --> 00:15:13,000
Template is like you are an expert AI engineer.

322
00:15:13,000 --> 00:15:15,000
Provide me the answer based on the questions.

323
00:15:15,000 --> 00:15:15,000
Right.

324
00:15:15,000 --> 00:15:20,000
And it has also said that hey uh, in the template also you have to consider input as your input variable

325
00:15:20,000 --> 00:15:21,000
itself, right.

326
00:15:21,000 --> 00:15:23,000
So all this information is there in my prompt template.

327
00:15:23,000 --> 00:15:26,000
This is very much good to start right now.

328
00:15:26,000 --> 00:15:28,000
What I can actually do.

329
00:15:28,000 --> 00:15:32,000
Right, uh, is that use this particular prompt template along with my LM model.

330
00:15:32,000 --> 00:15:32,000
Right.

331
00:15:32,000 --> 00:15:36,000
So what I will do, I will first of all go ahead and create a chain.

332
00:15:36,000 --> 00:15:42,000
And it is important because see my LM model should know like what it has to behave like.

333
00:15:42,000 --> 00:15:46,000
And that instruction is probably coming from here, from this particular chart from template.

334
00:15:46,000 --> 00:15:49,000
So we will go ahead and create a chain.

335
00:15:49,000 --> 00:15:51,000
So prompt slash LM model.

336
00:15:51,000 --> 00:15:51,000
Right.

337
00:15:51,000 --> 00:15:55,000
So when we do or like this this pipe sign right.

338
00:15:55,000 --> 00:15:59,000
It is basically saying that hey we need to combine this prompt along with my LM and that actually becomes

339
00:15:59,000 --> 00:15:59,000
a chain.

340
00:16:00,000 --> 00:16:05,000
Now whenever I give any input, first of all it will go through the prompt and then it will go to the

341
00:16:05,000 --> 00:16:05,000
LM.

342
00:16:05,000 --> 00:16:10,000
And finally we'll get the response right now in order to call this right chain.

343
00:16:10,000 --> 00:16:12,000
So I'll just go ahead and write chain dot invoke.

344
00:16:12,000 --> 00:16:14,000
Now you know what is my input.

345
00:16:14,000 --> 00:16:15,000
Right.

346
00:16:15,000 --> 00:16:19,000
So this is my key that I really need to pass because that is what I have actually set it over here in

347
00:16:19,000 --> 00:16:20,000
my prompt template.

348
00:16:20,000 --> 00:16:21,000
Right.

349
00:16:21,000 --> 00:16:30,000
I will go ahead and say, hey, uh, uh, can you tell me, let's say can you tell me about locksmith?

350
00:16:30,000 --> 00:16:30,000
Okay.

351
00:16:30,000 --> 00:16:32,000
What does Lang Smith is useful for?

352
00:16:32,000 --> 00:16:34,000
Like what is Lange Smith useful for?

353
00:16:34,000 --> 00:16:36,000
So I'm just asking a simple question over here.

354
00:16:36,000 --> 00:16:38,000
Let's see what kind of answer we will be able to get.

355
00:16:38,000 --> 00:16:39,000
And let me do one thing.

356
00:16:39,000 --> 00:16:43,000
Let me just go ahead and provide a variable which is called as response.

357
00:16:43,000 --> 00:16:49,000
And then I will just go ahead and print this response, display this response or print this response,

358
00:16:49,000 --> 00:16:51,000
whatever thing I really want.

359
00:16:51,000 --> 00:16:53,000
So I'll just go ahead and print this response.

360
00:16:54,000 --> 00:16:55,000
So if I go ahead and execute it.

361
00:16:55,000 --> 00:17:02,000
So here you'll be able to see that, um, again, uh, the best thing will be that it will, that the

362
00:17:02,000 --> 00:17:08,000
entire thing will also be going towards, uh, the uh, you'll be able to see that every, every thing

363
00:17:08,000 --> 00:17:10,000
is basically getting tracked in the Langsamt portal.

364
00:17:10,000 --> 00:17:11,000
Okay.

365
00:17:11,000 --> 00:17:14,000
So here you can see certainly Lang Center tool designed to enhance the development.

366
00:17:14,000 --> 00:17:19,000
All the answers you are specifically getting, logging, tracing everything, all the answers you are

367
00:17:19,000 --> 00:17:23,000
actually getting over here based on the content that I am actually getting a response as okay, now

368
00:17:23,000 --> 00:17:26,000
this is one basic example of probably creating chain.

369
00:17:26,000 --> 00:17:29,000
So chain basically means you can combine multiple things.

370
00:17:30,000 --> 00:17:34,000
Chain like prompt you can combine LM, you can create your own custom prompt.

371
00:17:34,000 --> 00:17:40,000
And based on that, uh, and it just gives you an idea like how once the input is given by the user,

372
00:17:40,000 --> 00:17:44,000
how the flow is, you know, initially it will go to the prompt template, then it will go to the LM.

373
00:17:44,000 --> 00:17:46,000
And then that is how you will be able to see it.

374
00:17:46,000 --> 00:17:52,000
If I go ahead and see the type of response, you'll be able to see that it is a kind of AI message.

375
00:17:52,000 --> 00:17:56,000
That basically means this response is basically coming from the AI message itself.

376
00:17:56,000 --> 00:17:57,000
Right?

377
00:17:57,000 --> 00:18:00,000
So I hope you are able to understand it very much clearly.

378
00:18:00,000 --> 00:18:01,000
Okay.

379
00:18:01,000 --> 00:18:03,000
Now, uh, let's do one more thing.

380
00:18:03,000 --> 00:18:06,000
See, right now, by default, I'm getting some kind of message.

381
00:18:06,000 --> 00:18:07,000
Okay?

382
00:18:07,000 --> 00:18:14,000
And, uh, I really want to make sure that I probably can use some kind of output parser also to display

383
00:18:14,000 --> 00:18:15,000
my response.

384
00:18:15,000 --> 00:18:20,000
So that is where, uh, one type of output parser, the default output parser that we'll be using is

385
00:18:20,000 --> 00:18:22,000
something called a string output parser.

386
00:18:22,000 --> 00:18:23,000
Okay.

387
00:18:23,000 --> 00:18:25,000
Now string output parser.

388
00:18:25,000 --> 00:18:31,000
Uh, if I really want to give you an example, you know, uh, and you'll be seeing in further sessions,

389
00:18:31,000 --> 00:18:36,000
you know, we will also making sure that our output parser is just like getting the message from the

390
00:18:36,000 --> 00:18:38,000
LLM and how you really want to display it.

391
00:18:38,000 --> 00:18:38,000
Okay.

392
00:18:38,000 --> 00:18:42,000
By default, uh, there is a string output parser class.

393
00:18:42,000 --> 00:18:44,000
Uh, but you can also create your own custom output parser.

394
00:18:44,000 --> 00:18:45,000
Okay.

395
00:18:45,000 --> 00:18:49,000
And so for that, uh, we'll be seeing that how we can basically create this output parser.

396
00:18:49,000 --> 00:18:53,000
So first of all what I will be doing I will be going ahead and importing from Lang chain.

397
00:18:54,000 --> 00:18:58,000
So underscore core okay dot output parsers.

398
00:18:58,000 --> 00:18:59,000
Okay.

399
00:18:59,000 --> 00:19:02,000
And then we are going to import str output parser.

400
00:19:02,000 --> 00:19:02,000
Okay.

401
00:19:02,000 --> 00:19:07,000
Now this output parser will be responsible in displaying my entire output.

402
00:19:07,000 --> 00:19:12,000
So here I'm just going to go ahead and write output parser is equal to str output parser.

403
00:19:12,000 --> 00:19:14,000
And here I'm initializing it.

404
00:19:14,000 --> 00:19:18,000
Now again I have to go ahead and create my chain this time.

405
00:19:18,000 --> 00:19:21,000
First thing that I really want to pass is my prompt.

406
00:19:21,000 --> 00:19:23,000
Then I will pass it to my LM.

407
00:19:23,000 --> 00:19:27,000
Then whatever response LM is basically giving, it will just go through this particular output parser,

408
00:19:27,000 --> 00:19:31,000
which is nothing, but it is my output parser variable that I've actually defined.

409
00:19:31,000 --> 00:19:33,000
Okay, now see the magic?

410
00:19:33,000 --> 00:19:36,000
What will specifically happen once I create this chain?

411
00:19:36,000 --> 00:19:40,000
So here I will go ahead and print my response.

412
00:19:41,000 --> 00:19:42,000
Let us go ahead okay.

413
00:19:42,000 --> 00:19:45,000
So I'm writing same thing chain dot invoke input.

414
00:19:45,000 --> 00:19:48,000
Can you tell me about blacksmith print response.

415
00:19:48,000 --> 00:19:49,000
So let's go ahead and execute it.

416
00:19:49,000 --> 00:19:52,000
And this time you'll be able to see my output parser.

417
00:19:52,000 --> 00:19:55,000
I'm able to get directly I don't have content.

418
00:19:55,000 --> 00:19:57,000
So that is the reason I was showing you right that time.

419
00:19:57,000 --> 00:20:01,000
We are getting an error when I was able to access this particular variable content by default.

420
00:20:01,000 --> 00:20:02,000
String output parser.

421
00:20:02,000 --> 00:20:06,000
Whatever message you are specifically getting that is only going to get displayed right.

422
00:20:06,000 --> 00:20:11,000
So it is always handy to use this string output parser, because based on your likes and dislikes,

423
00:20:11,000 --> 00:20:14,000
you can actually display the output result in the upcoming videos.

424
00:20:14,000 --> 00:20:18,000
We'll also be customizing this entire thing will be, uh, creating this particular class and we'll

425
00:20:18,000 --> 00:20:19,000
be doing more things.

426
00:20:19,000 --> 00:20:20,000
Okay.

427
00:20:20,000 --> 00:20:26,000
So, uh, in short, uh, in this video, we have used the most common and, uh, most basic and common

428
00:20:26,000 --> 00:20:29,000
components of link chain prompt templates, models and output parser.

429
00:20:29,000 --> 00:20:33,000
Now in my next video, we will create, a.

430
00:20:33,000 --> 00:20:37,000
We'll build a simple application with the lamp chain in the same notebook, so that we'll be able to

431
00:20:37,000 --> 00:20:38,000
track things.

432
00:20:38,000 --> 00:20:43,000
Right now, uh, let me just go ahead and see, like how much information has basically been tracked

433
00:20:43,000 --> 00:20:43,000
over here.

434
00:20:43,000 --> 00:20:47,000
So here you can see so many different information has basically been tracked.

435
00:20:47,000 --> 00:20:50,000
And all this information is probably available over here.

436
00:20:50,000 --> 00:20:51,000
Right.

437
00:20:51,000 --> 00:20:53,000
So this was my chat prompt template.

438
00:20:53,000 --> 00:20:54,000
See see chat prompt.

439
00:20:54,000 --> 00:20:56,000
Can you tell me about the blacksmith.

440
00:20:56,000 --> 00:20:59,000
So this is my entire chat prompt template that you'll be seeing I'm setting.

441
00:20:59,000 --> 00:21:02,000
You are an expert engineer based on this.

442
00:21:02,000 --> 00:21:04,000
And then we hit the chat open AI request.

443
00:21:04,000 --> 00:21:07,000
And based on that I got the entire response right.

444
00:21:07,000 --> 00:21:09,000
So step by step you'll be able to explore everything.

445
00:21:09,000 --> 00:21:11,000
See let's let's consider in this case okay.

446
00:21:11,000 --> 00:21:13,000
So this is my runnable sequence.

447
00:21:13,000 --> 00:21:15,000
So first uh my chat prompt template was there.

448
00:21:15,000 --> 00:21:17,000
Then I gave it to my chat open AI.

449
00:21:17,000 --> 00:21:22,000
Then finally I got my string output parser which is probably displaying the entire content that same

450
00:21:22,000 --> 00:21:23,000
chain.

451
00:21:23,000 --> 00:21:26,000
You are able to do it, and this in turn helps us to monitor each and every thing.

452
00:21:26,000 --> 00:21:29,000
And here you can see the token based on a token cost.

453
00:21:29,000 --> 00:21:31,000
You are able to see each and every cost that is there, right?

454
00:21:32,000 --> 00:21:37,000
So, uh, yeah, I hope you were able to understand this particular video.

455
00:21:37,000 --> 00:21:38,000
I hope you liked it.

456
00:21:38,000 --> 00:21:42,000
In the next video, we will try to create a simple generative AI application again with the use of OpenAI.

457
00:21:42,000 --> 00:21:43,000
Right.

458
00:21:43,000 --> 00:21:44,000
So yes, this was it from my side.

459
00:21:44,000 --> 00:21:45,000
I will see you all in the next video.

460
00:21:45,000 --> 00:21:46,000
Thank you.

