1
00:00:00,000 --> 00:00:00,000
Hello guys.

2
00:00:00,000 --> 00:00:04,000
So we are going to continue the discussion with respect to creating this chat bot.

3
00:00:04,000 --> 00:00:09,000
So already we have seen about the message history and how we can remember the context.

4
00:00:09,000 --> 00:00:11,000
Now let's go ahead and use this prompt templates okay.

5
00:00:11,000 --> 00:00:18,000
Now prompt templates helps to turn raw user information into a format that NLM can work with in case

6
00:00:18,000 --> 00:00:22,000
the raw user input is just a message, which we are passing to the LM.

7
00:00:22,000 --> 00:00:24,000
Let's now make that a bit more complicated.

8
00:00:24,000 --> 00:00:28,000
First, let's add in the system message and add some custom instruction.

9
00:00:28,000 --> 00:00:31,000
Till now we were just passing the list of messages, right?

10
00:00:31,000 --> 00:00:34,000
Now let's go ahead and work with this particular prompt template.

11
00:00:34,000 --> 00:00:38,000
Now for working with Prompt template I will go ahead and write from long chain.

12
00:00:39,000 --> 00:00:45,000
Uh from long chain underscore core dot prompts.

13
00:00:45,000 --> 00:00:51,000
Okay I'm going to import my chat prompt template.

14
00:00:51,000 --> 00:00:51,000
Okay.

15
00:00:51,000 --> 00:00:55,000
Chat Chart prompt or prompts.

16
00:00:55,000 --> 00:00:56,000
It should be prompts okay.

17
00:00:57,000 --> 00:01:00,000
So chart prompt template okay.

18
00:01:00,000 --> 00:01:05,000
Along with this I will also use a message placeholder before we used to give the messages right directly.

19
00:01:05,000 --> 00:01:09,000
If you see over here like human message and all, we are just giving it right in the form of list of

20
00:01:09,000 --> 00:01:10,000
messages.

21
00:01:10,000 --> 00:01:12,000
But here, uh, we will just go ahead and use this.

22
00:01:12,000 --> 00:01:15,000
Now quickly, let's go ahead and create my prompt.

23
00:01:15,000 --> 00:01:17,000
Uh, here I'm just going to write chat prompt template is equal to.

24
00:01:18,000 --> 00:01:21,000
And uh with respect to this here I'm going to give a list of information.

25
00:01:21,000 --> 00:01:27,000
The first information that we are interested in in providing system information.

26
00:01:27,000 --> 00:01:36,000
So I will go ahead and write system I'll say hey you are uh, helpful assistant okay.

27
00:01:36,000 --> 00:01:47,000
And I will just go ahead and say, hey, answer all the questions to the best, to the best of your

28
00:01:48,000 --> 00:01:50,000
your ability.

29
00:01:50,000 --> 00:01:50,000
Right?

30
00:01:51,000 --> 00:01:52,000
Something like this.

31
00:01:52,000 --> 00:01:58,000
So once I do this, I will go ahead and create, uh, my next field.

32
00:01:58,000 --> 00:02:03,000
Now in this case, uh, the next field that I have to probably go ahead and create it is nothing but

33
00:02:03,000 --> 00:02:04,000
message folder.

34
00:02:04,000 --> 00:02:04,000
Okay.

35
00:02:04,000 --> 00:02:05,000
So message placeholder.

36
00:02:05,000 --> 00:02:11,000
So message placeholder here I will just go ahead and create a variable name called as messages.

37
00:02:11,000 --> 00:02:14,000
And this messages will specifically be used.

38
00:02:14,000 --> 00:02:19,000
Uh I'll talk about this why we are creating this particular variable name just in some time okay.

39
00:02:19,000 --> 00:02:23,000
Now once I go ahead and execute this, uh, let me go ahead and first of all, create my prompt, uh,

40
00:02:23,000 --> 00:02:23,000
chain.

41
00:02:23,000 --> 00:02:26,000
So I will write prompt off model.

42
00:02:26,000 --> 00:02:28,000
And this should be my chain right.

43
00:02:28,000 --> 00:02:33,000
So and it takes exactly how many parameters one positional argument two are given.

44
00:02:33,000 --> 00:02:35,000
Let's see why two are actually given over here.

45
00:02:36,000 --> 00:02:38,000
Uh this is my prompt template.

46
00:02:38,000 --> 00:02:40,000
And here I have used the message player.

47
00:02:40,000 --> 00:02:44,000
This should be the system over here or system comma.

48
00:02:44,000 --> 00:02:49,000
This right with respect to the key value pairs like this.

49
00:02:49,000 --> 00:02:55,000
And uh one more thing that we can just do is remove this.

50
00:02:55,000 --> 00:02:56,000
Just a second.

51
00:02:56,000 --> 00:02:56,000
Okay?

52
00:02:56,000 --> 00:02:58,000
Now I think it should be right.

53
00:02:59,000 --> 00:02:59,000
Okay.

54
00:03:00,000 --> 00:03:04,000
Let's execute this and let's remove this okay.

55
00:03:04,000 --> 00:03:11,000
So it says uh, and it takes exactly one positional argument.

56
00:03:11,000 --> 00:03:12,000
Why.

57
00:03:12,000 --> 00:03:15,000
Let's see chat prompt template okay.

58
00:03:15,000 --> 00:03:17,000
That was not the issue okay.

59
00:03:18,000 --> 00:03:20,000
The issue was something else.

60
00:03:20,000 --> 00:03:22,000
I will try to fix this issue.

61
00:03:22,000 --> 00:03:26,000
We have to use a function called as from underscore messages.

62
00:03:26,000 --> 00:03:27,000
Okay.

63
00:03:27,000 --> 00:03:31,000
I'm not going to editing this part because you have to definitely see all the errors and then try to

64
00:03:31,000 --> 00:03:33,000
fix it okay.

65
00:03:33,000 --> 00:03:34,000
So here you have this.

66
00:03:34,000 --> 00:03:35,000
And this is my chain.

67
00:03:35,000 --> 00:03:42,000
Now let me quickly go ahead and uh, you know uh provide this entire or invoke this chain.

68
00:03:42,000 --> 00:03:48,000
Now Understand one thing, guys, whatever human message we specifically give, it needs to be given

69
00:03:48,000 --> 00:03:52,000
in a key value pair where the key names should be messages.

70
00:03:52,000 --> 00:03:56,000
And that is the reason we are giving a message placeholder over here.

71
00:03:56,000 --> 00:03:59,000
Right before we were not using any message placeholder.

72
00:03:59,000 --> 00:04:03,000
So over there we were giving in the form of list of messages like human message, AI message system

73
00:04:03,000 --> 00:04:04,000
message like this.

74
00:04:04,000 --> 00:04:04,000
Right.

75
00:04:04,000 --> 00:04:09,000
But here I've told that, hey, we are going to use a message placeholder called as variable name as

76
00:04:09,000 --> 00:04:10,000
messages.

77
00:04:10,000 --> 00:04:15,000
And inside this, whatever information you definitely require from the human side, it will be given

78
00:04:15,000 --> 00:04:15,000
in that.

79
00:04:15,000 --> 00:04:16,000
So how do I call it.

80
00:04:16,000 --> 00:04:18,000
So here I have created my chain.

81
00:04:18,000 --> 00:04:22,000
So let me quickly go ahead and write chain dot invoke okay.

82
00:04:22,000 --> 00:04:28,000
And inside this I'm going to pass my messages okay.

83
00:04:28,000 --> 00:04:29,000
Messages.

84
00:04:29,000 --> 00:04:30,000
This will be my key right.

85
00:04:30,000 --> 00:04:32,000
This will basically be my key.

86
00:04:32,000 --> 00:04:33,000
And here I can give.

87
00:04:33,000 --> 00:04:38,000
Hey, whether I want to give a human message over here and let's say I will go ahead and write content.

88
00:04:38,000 --> 00:04:42,000
Hi, my name is Krish.

89
00:04:42,000 --> 00:04:43,000
Okay.

90
00:04:43,000 --> 00:04:46,000
So this is my message that I'm specifically giving over here, right?

91
00:04:46,000 --> 00:04:49,000
So once I execute it automatically will be able to see that.

92
00:04:49,000 --> 00:04:51,000
Now the message placeholder is messages.

93
00:04:51,000 --> 00:04:57,000
So in inside this it will try to understand okay Okay, here is what I will get my entire messages or

94
00:04:57,000 --> 00:04:59,000
all the list of messages that I'm actually going to get.

95
00:04:59,000 --> 00:05:02,000
And this will basically go ahead and interact with the chain.

96
00:05:02,000 --> 00:05:08,000
Um, so whatever information I'm giving it over here, it will be going and it will get displayed over

97
00:05:08,000 --> 00:05:08,000
here.

98
00:05:08,000 --> 00:05:09,000
Right.

99
00:05:09,000 --> 00:05:17,000
So this entirely basically talks about, uh, how you can actually include the along with the prompt

100
00:05:17,000 --> 00:05:17,000
template itself.

101
00:05:17,000 --> 00:05:19,000
And here I can get the answer that.

102
00:05:19,000 --> 00:05:21,000
Hi Chris, it is nice to meet you.

103
00:05:21,000 --> 00:05:27,000
And all the information is specifically over here, but how to invoke with respect to the chat message

104
00:05:27,000 --> 00:05:28,000
history.

105
00:05:28,000 --> 00:05:29,000
Right with the chat message history.

106
00:05:29,000 --> 00:05:32,000
Now let me just go ahead and create a variable over here.

107
00:05:32,000 --> 00:05:35,000
So I will say hey with message history let me create a new one.

108
00:05:35,000 --> 00:05:38,000
And here I will say hey runnable with message history.

109
00:05:38,000 --> 00:05:41,000
Now two important information needs to be given.

110
00:05:41,000 --> 00:05:43,000
One is chain and one is the get session history.

111
00:05:43,000 --> 00:05:46,000
If you remember the get session history that I've actually created, right.

112
00:05:47,000 --> 00:05:51,000
So once I give this two information now see how I will be able to invoke this okay.

113
00:05:51,000 --> 00:05:55,000
So this is why with message industry here I'm just giving the chain.

114
00:05:55,000 --> 00:05:58,000
Chain is nothing but this entire prompt and model.

115
00:05:58,000 --> 00:06:00,000
And this is my get session history over here.

116
00:06:00,000 --> 00:06:02,000
Now I will go ahead and create my config.

117
00:06:02,000 --> 00:06:04,000
So let me go ahead and create my config.

118
00:06:04,000 --> 00:06:09,000
And this is my chat three okay I'm just going to write a session ID over here.

119
00:06:09,000 --> 00:06:10,000
Chat three.

120
00:06:10,000 --> 00:06:13,000
And I'm going to probably go ahead and create my response.

121
00:06:13,000 --> 00:06:19,000
And again we will go ahead and use this with messages three dot invoke dot invoke.

122
00:06:19,000 --> 00:06:26,000
Now when I am specifically invoking um, when I'm actually taking this entire chain and all, I can

123
00:06:26,000 --> 00:06:29,000
give the same information like how I gave it over here, right?

124
00:06:29,000 --> 00:06:30,000
Something like this.

125
00:06:30,000 --> 00:06:33,000
So I will say, hey, this is my human message.

126
00:06:34,000 --> 00:06:36,000
I will go and paste it over here.

127
00:06:37,000 --> 00:06:37,000
Okay?

128
00:06:37,000 --> 00:06:42,000
Along with this, the next thing that I am going to give is my config.

129
00:06:42,000 --> 00:06:43,000
Okay?

130
00:06:43,000 --> 00:06:47,000
So once I get the response I should be able to display the response.

131
00:06:48,000 --> 00:06:51,000
Hello Chris, it's nice to meet to you right now.

132
00:06:51,000 --> 00:06:52,000
This is fine.

133
00:06:52,000 --> 00:06:56,000
See this message history is almost same like how we used to use it before.

134
00:06:56,000 --> 00:06:56,000
Right?

135
00:06:56,000 --> 00:07:02,000
But, uh, let me add some more complexity instead of just one input variable.

136
00:07:02,000 --> 00:07:04,000
Now let me go ahead and add multiple input variable okay.

137
00:07:04,000 --> 00:07:08,000
So I will be taking one type of prompt over here.

138
00:07:08,000 --> 00:07:09,000
So this is my prompt.

139
00:07:09,000 --> 00:07:14,000
See over here I'm using chat prompt template dot underscore from messages.

140
00:07:14,000 --> 00:07:17,000
So I'm going to add some more complexity okay.

141
00:07:18,000 --> 00:07:22,000
Add more complexity okay.

142
00:07:22,000 --> 00:07:26,000
So here you can see I'm having chat prompt template dot from underscore message.

143
00:07:26,000 --> 00:07:27,000
Here is my system.

144
00:07:27,000 --> 00:07:28,000
You are a helpful assistant.

145
00:07:28,000 --> 00:07:33,000
Answer all the questions to your ability in this language whatever language I have right.

146
00:07:33,000 --> 00:07:37,000
So this basically becomes my new input that I'm actually going to give okay.

147
00:07:37,000 --> 00:07:41,000
So I'm saying hey system you are such a helpful assistant.

148
00:07:41,000 --> 00:07:46,000
And you are have to probably answer all the questions based on your ability in this particular language.

149
00:07:46,000 --> 00:07:47,000
The language will be passed as a keyword.

150
00:07:47,000 --> 00:07:50,000
Okay then this is my message folder.

151
00:07:50,000 --> 00:07:54,000
Um, sorry message placeholder where I am giving the variable as message and this is my chin.

152
00:07:54,000 --> 00:07:55,000
Okay.

153
00:07:55,000 --> 00:07:55,000
So this is fine.

154
00:07:56,000 --> 00:08:00,000
Now over here, you'll be able to see that whenever I need to invoke this chain.

155
00:08:00,000 --> 00:08:04,000
So if I go ahead and write response is equal to chain dot invoke.

156
00:08:05,000 --> 00:08:09,000
Here there are multiple parameters that I really need to give.

157
00:08:09,000 --> 00:08:15,000
One is messages and this will be nothing but human message.

158
00:08:15,000 --> 00:08:23,000
And here I'm just going to write my content where I'll say, hey, hi my name is Krish okay.

159
00:08:24,000 --> 00:08:31,000
And along with this, the second parameter that I need to give see very important thing in this messages.

160
00:08:31,000 --> 00:08:33,000
This will be a key value pair right.

161
00:08:33,000 --> 00:08:36,000
So one parameter I'm actually giving it over here.

162
00:08:36,000 --> 00:08:42,000
The second parameter I will again go ahead and add a key which is called as language okay.

163
00:08:42,000 --> 00:08:46,000
And let's say language over here I'm just going to write it as Hindi okay.

164
00:08:46,000 --> 00:08:48,000
So this is the second parameter I need to give.

165
00:08:48,000 --> 00:08:51,000
So first I'm passing it as a human message content.

166
00:08:52,000 --> 00:08:54,000
Uh this is basically there in the key called as message.

167
00:08:54,000 --> 00:08:59,000
And the second key that I'm actually passing is for this particular input that is this particular language.

168
00:08:59,000 --> 00:08:59,000
Okay.

169
00:08:59,000 --> 00:09:04,000
Now once I could probably get the response I can go ahead and display the response dot content okay.

170
00:09:04,000 --> 00:09:09,000
So once I go ahead and see Namaste to Krishna Nagar.

171
00:09:09,000 --> 00:09:16,000
So here you can see that I am able to probably give this uh again in this message key and in this language

172
00:09:16,000 --> 00:09:17,000
key I'm actually giving.

173
00:09:17,000 --> 00:09:17,000
Okay.

174
00:09:17,000 --> 00:09:20,000
Now there are two keys that are going over here.

175
00:09:20,000 --> 00:09:24,000
So with respect to the chat message history, how it is going to change okay.

176
00:09:24,000 --> 00:09:28,000
So now I will just go ahead and create a markdown and add some information.

177
00:09:28,000 --> 00:09:31,000
Let's now wrap this more complicated chain in a message history class.

178
00:09:31,000 --> 00:09:36,000
This time because there are multiple keys in the input, we need to specify the correct key used to

179
00:09:36,000 --> 00:09:37,000
save the chat history.

180
00:09:37,000 --> 00:09:38,000
Okay.

181
00:09:38,000 --> 00:09:40,000
So let's do this okay.

182
00:09:40,000 --> 00:09:44,000
This time what I will do while I'm creating my with message history okay.

183
00:09:46,000 --> 00:09:49,000
I will use this runnable message history.

184
00:09:49,000 --> 00:09:53,000
Now inside this runnable message history, first parameter is nothing but my chain.

185
00:09:53,000 --> 00:09:54,000
Whatever chain I'm specifically giving.

186
00:09:54,000 --> 00:09:58,000
The second parameter is nothing but my sketch session history function.

187
00:09:58,000 --> 00:10:01,000
Based on the session id it is going to pick up all the information.

188
00:10:01,000 --> 00:10:06,000
Now is the most important one, which is called my input key message input message key.

189
00:10:06,000 --> 00:10:09,000
And here I'm going to give my input as messages.

190
00:10:09,000 --> 00:10:10,000
Okay.

191
00:10:10,000 --> 00:10:13,000
So these are my parameters that I really need to give.

192
00:10:13,000 --> 00:10:14,000
Now see the magic okay.

193
00:10:14,000 --> 00:10:16,000
Based on this particular input message keys.

194
00:10:16,000 --> 00:10:23,000
Now it knows where uh like uh uh, since there are multiple keys, it knows uh, which one to basically

195
00:10:23,000 --> 00:10:27,000
specify to uh, we need to specify C over here.

196
00:10:27,000 --> 00:10:31,000
As soon as we give this particular key, it will be able to understand when we are giving messages and

197
00:10:31,000 --> 00:10:33,000
when we are giving the language input over here Okay.

198
00:10:33,000 --> 00:10:35,000
So let's go ahead and execute it now.

199
00:10:35,000 --> 00:10:38,000
This time I will go ahead and create my next config over here.

200
00:10:38,000 --> 00:10:40,000
So let's take a simple config.

201
00:10:40,000 --> 00:10:44,000
So this time I will go ahead and write chat for message okay.

202
00:10:44,000 --> 00:10:48,000
And here will be my chat for okay.

203
00:10:48,000 --> 00:10:51,000
And along with this we will go ahead and write.

204
00:10:51,000 --> 00:10:56,000
Response is equal to width message history dot invoke.

205
00:10:56,000 --> 00:10:58,000
Now see how I'm going to pass the parameter?

206
00:10:58,000 --> 00:11:06,000
The parameter will be with respect to the messages or messages, which will be my key.

207
00:11:06,000 --> 00:11:14,000
Here I'm going to pass my uh here I'm going to basically pass my human message, human message.

208
00:11:14,000 --> 00:11:20,000
And inside this human message, again, this will be in the form of list, okay, human message.

209
00:11:20,000 --> 00:11:24,000
And inside this human message, I'll say, hey, content will be nothing.

210
00:11:24,000 --> 00:11:24,000
But.

211
00:11:25,000 --> 00:11:28,000
Hi, I am Krish.

212
00:11:28,000 --> 00:11:29,000
Okay?

213
00:11:29,000 --> 00:11:31,000
Now this is fine till here.

214
00:11:31,000 --> 00:11:32,000
We have given this particular information.

215
00:11:32,000 --> 00:11:35,000
Remember, this will get closed over here, okay?

216
00:11:35,000 --> 00:11:37,000
Or it should get closed over here.

217
00:11:37,000 --> 00:11:40,000
So this will basically be my list of messages.

218
00:11:40,000 --> 00:11:43,000
Now in the next parameter what I give I give my language key.

219
00:11:43,000 --> 00:11:45,000
So this will be nothing but language is equal to.

220
00:11:47,000 --> 00:11:47,000
Hindi.

221
00:11:47,000 --> 00:11:50,000
Okay so these are my information.

222
00:11:50,000 --> 00:11:53,000
Now let's go ahead and probably give my configuration.

223
00:11:54,000 --> 00:11:56,000
And this is how we basically give the entire response.

224
00:11:56,000 --> 00:11:59,000
So finally I can go ahead and print the response dot content.

225
00:11:59,000 --> 00:12:01,000
So once I execute it Namaste.

226
00:12:01,000 --> 00:12:06,000
Crushed uh to make a system to make a whole car madam.

227
00:12:07,000 --> 00:12:09,000
Car okay.

228
00:12:09,000 --> 00:12:10,000
It's somewhat right.

229
00:12:10,000 --> 00:12:11,000
Again, there are some grammatical issues.

230
00:12:11,000 --> 00:12:16,000
Uh, but again, it is an open source model, so we should be happy that we are able to use it completely

231
00:12:16,000 --> 00:12:16,000
for free.

232
00:12:17,000 --> 00:12:20,000
Okay, so here are all my information.

233
00:12:20,000 --> 00:12:24,000
Then again, if I really want to go ahead and ask, hey, what's my name?

234
00:12:24,000 --> 00:12:29,000
And I can go ahead and ask over here and here also I will go ahead and uh, press Hindi.

235
00:12:29,000 --> 00:12:32,000
So here you will be able to see my response dot content.

236
00:12:34,000 --> 00:12:37,000
It shows up here right.

237
00:12:37,000 --> 00:12:40,000
So it is able to understand all this specific things okay.

238
00:12:41,000 --> 00:12:46,000
Uh so this is how you can actually work with chat history where you really need to worry about the message

239
00:12:46,000 --> 00:12:51,000
history class, how you can go ahead and create it, what all input message keys needs to be used.

240
00:12:51,000 --> 00:12:53,000
What is this particular function based on a session ID?

241
00:12:53,000 --> 00:12:55,000
How do you pick up information?

242
00:12:55,000 --> 00:12:58,000
So I hope you are able to understand this particular video.

243
00:12:58,000 --> 00:13:04,000
Now in my next video, I will be showing you how you can manage this entire conversation history.

244
00:13:04,000 --> 00:13:07,000
Because managing this conversation history is very much important.

245
00:13:07,000 --> 00:13:13,000
Yes, you can uh, whenever you are communicating with the LM model here, what we are specifically

246
00:13:13,000 --> 00:13:15,000
doing is that we are giving the entire history itself.

247
00:13:15,000 --> 00:13:21,000
But sometimes this history can become very, very long, you know, and it remains completely unmanaged.

248
00:13:21,000 --> 00:13:26,000
So how we can probably and see there is a limitation with respect to the context window of every LM.

249
00:13:26,000 --> 00:13:30,000
So managing the conversation history is very very much important.

250
00:13:30,000 --> 00:13:39,000
So in my next video what we are going to do is that we are going to see how we can manage the conversation

251
00:13:39,000 --> 00:13:40,000
history.

252
00:13:40,000 --> 00:13:40,000
Okay.

253
00:13:40,000 --> 00:13:43,000
That is what we are going to discuss in the next video.

254
00:13:43,000 --> 00:13:45,000
So yes, uh, this was it for my side.

255
00:13:45,000 --> 00:13:46,000
I will see you all in the next video.

256
00:13:46,000 --> 00:13:47,000
Thank you.

257
00:13:47,000 --> 00:13:47,000
Take care.

