1
00:00:00,000 --> 00:00:00,000
Hello guys.

2
00:00:00,000 --> 00:00:06,000
So we are going to continue the discussion with respect to creating this amazing end to end search engine,

3
00:00:06,000 --> 00:00:09,000
an AI application, with the help of tools and agents.

4
00:00:09,000 --> 00:00:14,000
Already in our previous video, we have seen that how we can use Lang chain in order to create tools

5
00:00:14,000 --> 00:00:17,000
and how we can execute it with the help of agents.

6
00:00:17,000 --> 00:00:22,000
And uh, in our previous video, we have already seen about creating your own custom tools.

7
00:00:22,000 --> 00:00:27,000
Along with that, we have also seen how to use the inbuilt tools that are supported by Lang Chain.

8
00:00:27,000 --> 00:00:30,000
Now let's go ahead and quickly start our project.

9
00:00:30,000 --> 00:00:36,000
So here in my search engine folder you will be able to see that I have created my app Dot Pi project.

10
00:00:36,000 --> 00:00:40,000
Uh, so folder by folder I am trying to execute this specific project.

11
00:00:40,000 --> 00:00:42,000
So let's go ahead without wasting any time.

12
00:00:42,000 --> 00:00:48,000
So first of all we will go ahead and import Streamlit as st along with this.

13
00:00:48,000 --> 00:00:52,000
Uh, what we are basically going to do is that we are also going to import all the other things that

14
00:00:52,000 --> 00:00:53,000
we require.

15
00:00:53,000 --> 00:00:56,000
Okay, so I'll just remove this.

16
00:00:56,000 --> 00:01:00,000
I don't know why this suggestion usually comes, but can't help.

17
00:01:00,000 --> 00:01:08,000
Then uh, quickly I will go ahead and use something called as lang chain underscore grok.

18
00:01:08,000 --> 00:01:12,000
We are going to use grok over here to access the open source models.

19
00:01:12,000 --> 00:01:14,000
So I'm just going to go ahead and write Chad Grok.

20
00:01:14,000 --> 00:01:22,000
And then from this I'm also be using lang chain underscore uh, community dot utils.

21
00:01:22,000 --> 00:01:23,000
Okay.

22
00:01:23,000 --> 00:01:28,000
I've already shown you how to probably go ahead and create your wrappers.

23
00:01:28,000 --> 00:01:28,000
Right.

24
00:01:28,000 --> 00:01:31,000
So here also we are going to use the same wrappers.

25
00:01:31,000 --> 00:01:33,000
So I'll go ahead and write utilities import.

26
00:01:33,000 --> 00:01:35,000
One is the RCF wrapper.

27
00:01:35,000 --> 00:01:38,000
And then I'm going to use the Wikipedia wrapper.

28
00:01:38,000 --> 00:01:42,000
So let's go ahead and use this two wrappers for right now.

29
00:01:42,000 --> 00:01:44,000
And again you can go ahead and explore other tools.

30
00:01:44,000 --> 00:01:47,000
Also in this I will also add one search engine tool.

31
00:01:47,000 --> 00:01:48,000
Okay.

32
00:01:48,000 --> 00:01:49,000
Let let's see that also.

33
00:01:49,000 --> 00:01:50,000
Okay.

34
00:01:50,000 --> 00:01:56,000
Along with this you will be seeing that I will go ahead and import from lang chain underscore community

35
00:01:56,000 --> 00:01:57,000
dot tools.

36
00:01:57,000 --> 00:02:02,000
Inside the tools we will go ahead and import our chef query.

37
00:02:02,000 --> 00:02:06,000
And then I'll also have this uh Wikipedia query run.

38
00:02:06,000 --> 00:02:06,000
Okay.

39
00:02:06,000 --> 00:02:10,000
So our query run, and then I'll also be having this Wikipedia query run.

40
00:02:10,000 --> 00:02:16,000
Along with this I will also add one like capabilities to search from the internet.

41
00:02:16,000 --> 00:02:16,000
Right.

42
00:02:16,000 --> 00:02:22,000
So for that I have this duck duck duck duck duck go search run okay.

43
00:02:22,000 --> 00:02:28,000
So I'll be using this also which will actually help you to search anything in the internet.

44
00:02:28,000 --> 00:02:28,000
Right.

45
00:02:28,000 --> 00:02:34,000
So all these, uh, are the important imports that we are specifically going to do now, I will also

46
00:02:34,000 --> 00:02:37,000
be importing something called as from Lang Chain.

47
00:02:37,000 --> 00:02:40,000
I will be importing something called as agents.

48
00:02:40,000 --> 00:02:45,000
So let's first of all go ahead and initialize the agent over here.

49
00:02:45,000 --> 00:02:50,000
Along with this there is an option of putting something called as agent type which I will be discussing.

50
00:02:50,000 --> 00:02:51,000
What is the importance of this?

51
00:02:51,000 --> 00:02:54,000
I will go ahead and discuss about this also along with this.

52
00:02:54,000 --> 00:02:57,000
So let's go ahead and import our next library.

53
00:02:57,000 --> 00:03:01,000
So here we are also going to use something called as lang sched dot callbacks.

54
00:03:01,000 --> 00:03:06,000
And I'm going to import something called as streamlet callback handler.

55
00:03:06,000 --> 00:03:11,000
And this is important because this will allow you to communicate with all this kind of tools within

56
00:03:11,000 --> 00:03:12,000
themselves.

57
00:03:12,000 --> 00:03:12,000
Right.

58
00:03:12,000 --> 00:03:19,000
So all this libraries will be using initially right now uh streamlet has also been imported.

59
00:03:19,000 --> 00:03:23,000
I will go ahead and import OS if I want over here.

60
00:03:23,000 --> 00:03:31,000
Along with this, I will go ahead and write import OS, then from dot env import load underscore dot

61
00:03:31,000 --> 00:03:32,000
env.

62
00:03:32,000 --> 00:03:34,000
I'm also going to use this okay.

63
00:03:34,000 --> 00:03:37,000
Uh, if you remember in our chatbot also right.

64
00:03:37,000 --> 00:03:42,000
We specifically did not even have to call any APIs.

65
00:03:42,000 --> 00:03:42,000
Right.

66
00:03:42,000 --> 00:03:47,000
I was directly copying and pasting in the, uh, web application itself.

67
00:03:47,000 --> 00:03:49,000
So I will try to also develop in that specific way.

68
00:03:49,000 --> 00:03:56,000
So if I go ahead and open this OpenAI chat bot here, you'll be able to see I had created this all slide

69
00:03:56,000 --> 00:03:56,000
bars.

70
00:03:56,000 --> 00:03:56,000
Right.

71
00:03:56,000 --> 00:03:59,000
So here I will also use one of the slide bar okay.

72
00:03:59,000 --> 00:04:03,000
And I will keep this handy when I will be using it okay.

73
00:04:03,000 --> 00:04:10,000
So I'll just paste it over here to keep this sidebar settings and I'll say hey, enter your grok API

74
00:04:10,000 --> 00:04:11,000
key okay.

75
00:04:11,000 --> 00:04:14,000
So I will go ahead and enter the grok API key.

76
00:04:14,000 --> 00:04:20,000
So I'll keep this also handy so that I don't have to even call my load underscore dot EMV right for

77
00:04:20,000 --> 00:04:21,000
the same thing.

78
00:04:21,000 --> 00:04:27,000
Now, the next thing, uh, after this, what I am actually going to do is that after importing all

79
00:04:27,000 --> 00:04:31,000
these things, let's also, you know, take this entire things.

80
00:04:31,000 --> 00:04:38,000
And first of all, I will go ahead and, you know, create my RCF wrapper, API wrapper and uh, the

81
00:04:38,000 --> 00:04:39,000
Wikipedia API wrapper.

82
00:04:39,000 --> 00:04:41,000
And already I have actually shown you how to do that.

83
00:04:41,000 --> 00:04:49,000
This is for my RCF tools, which I had actually shown you in my previous video, Agip and Wikipedia

84
00:04:49,000 --> 00:04:49,000
tools.

85
00:04:49,000 --> 00:04:50,000
Right.

86
00:04:50,000 --> 00:04:56,000
So here we have initialized it, uh, along with this, as I said that I'm also going to use, uh,

87
00:04:56,000 --> 00:04:57,000
a duck.

88
00:04:57,000 --> 00:04:58,000
Duck go search.

89
00:04:58,000 --> 00:05:00,000
So that is what I'm actually going to do.

90
00:05:00,000 --> 00:05:05,000
In order to use that particular tool, I will go ahead and create a variable which is called as search

91
00:05:05,000 --> 00:05:08,000
is equal to duck, duck, go, search, run.

92
00:05:08,000 --> 00:05:13,000
And here the kind of task that I'm telling it to do, or the name that I'm actually going to give,

93
00:05:13,000 --> 00:05:15,000
this is something called as search.

94
00:05:15,000 --> 00:05:18,000
So here the name will be Wikipedia.

95
00:05:18,000 --> 00:05:23,000
Here the name will be RCF and And this will be my search functionality, which I really need to search

96
00:05:23,000 --> 00:05:25,000
from the internet itself.

97
00:05:25,000 --> 00:05:25,000
Right.

98
00:05:25,000 --> 00:05:31,000
And uh, after doing all these things now let's go ahead and create my Streamlit app.

99
00:05:31,000 --> 00:05:33,000
So first of all, I will go quickly.

100
00:05:33,000 --> 00:05:35,000
Go ahead and write s t dot title.

101
00:05:35,000 --> 00:05:39,000
I'll just go ahead and write link chain with chat with search.

102
00:05:39,000 --> 00:05:40,000
Okay.

103
00:05:40,000 --> 00:05:47,000
Um, let me just give a simple reminder or a comment over here saying that, hey, in this example,

104
00:05:47,000 --> 00:05:55,000
we are using something called as Streamlet callback handler to display the thoughts and action of the

105
00:05:55,000 --> 00:05:57,000
agent in an interactive Streamlet app.

106
00:05:57,000 --> 00:06:02,000
Okay, so this will actually help you to, uh, this Streamlet callback handler will actually help you

107
00:06:02,000 --> 00:06:06,000
to understand, like what thoughts and action of the agents will be when they are executing all this

108
00:06:06,000 --> 00:06:09,000
kind of tools, or when they are interacting with the tools.

109
00:06:09,000 --> 00:06:13,000
Okay then, I have imported this specifically for my grok API.

110
00:06:13,000 --> 00:06:14,000
Okay.

111
00:06:14,000 --> 00:06:19,000
Now what I'm actually going to do, since I also need to make sure that now my entire conversation over

112
00:06:19,000 --> 00:06:22,000
here should happen along with the chat history.

113
00:06:22,000 --> 00:06:25,000
So I will go ahead and create one simple.

114
00:06:25,000 --> 00:06:30,000
I'll just say, hey, if message is I'll, I'll basically create my session state.

115
00:06:30,000 --> 00:06:34,000
So I'll go ahead and write session underscore state over here.

116
00:06:34,000 --> 00:06:40,000
And along with this I'll write hey s t dot session state of messages okay.

117
00:06:40,000 --> 00:06:43,000
So I'm just going to go ahead and create this messages equal to.

118
00:06:43,000 --> 00:06:50,000
And here I'll just go ahead and give some of the important uh, message, uh roles that I'm actually

119
00:06:50,000 --> 00:06:51,000
going to provide.

120
00:06:51,000 --> 00:06:55,000
So first one information that I really need to put is something about role.

121
00:06:55,000 --> 00:06:57,000
So role will be nothing but assistant.

122
00:06:58,000 --> 00:07:01,000
And then I will say, hey, this is my content.

123
00:07:01,000 --> 00:07:03,000
So let me just go ahead and write the content.

124
00:07:03,000 --> 00:07:15,000
It will be again colon I'll say, hi, I am a chat bot who can search the web.

125
00:07:15,000 --> 00:07:16,000
Okay.

126
00:07:17,000 --> 00:07:19,000
Uh, or I'll also put one message.

127
00:07:19,000 --> 00:07:20,000
How can I help you?

128
00:07:20,000 --> 00:07:26,000
Okay, so this will be the default assistant, uh, information that you have.

129
00:07:27,000 --> 00:07:28,000
So this.

130
00:07:28,000 --> 00:07:30,000
I'm saving it in the session state.

131
00:07:30,000 --> 00:07:31,000
Okay.

132
00:07:31,000 --> 00:07:35,000
Then I will go ahead and say for every messages, we will go ahead and traverse it.

133
00:07:35,000 --> 00:07:45,000
So I'll write for message in s t dot session state session s t dot session.

134
00:07:46,000 --> 00:07:49,000
Underscore state dot messages.

135
00:07:49,000 --> 00:07:50,000
Okay.

136
00:07:50,000 --> 00:07:55,000
And here I'm just going to use state dot chat underscore message.

137
00:07:55,000 --> 00:08:00,000
I'm basically going to give my message role.

138
00:08:02,000 --> 00:08:03,000
Okay.

139
00:08:04,000 --> 00:08:12,000
Now inside this message role I'm just going to go ahead and write dot write right dot right over here

140
00:08:12,000 --> 00:08:14,000
as my message content.

141
00:08:14,000 --> 00:08:20,000
So with respect to any conversation that I get because I'm going to put all this specific role information

142
00:08:20,000 --> 00:08:24,000
like how I put over here inside my session state as we go ahead.

143
00:08:24,000 --> 00:08:24,000
Right.

144
00:08:24,000 --> 00:08:27,000
So right now in this key value pairs I will keep on adding it.

145
00:08:27,000 --> 00:08:32,000
And we will be making sure that we add all these values in our session state.

146
00:08:32,000 --> 00:08:33,000
Okay.

147
00:08:33,000 --> 00:08:36,000
Now, uh, let's go ahead and do one thing.

148
00:08:36,000 --> 00:08:39,000
Let's go ahead and create my prompt.

149
00:08:39,000 --> 00:08:40,000
Okay.

150
00:08:40,000 --> 00:08:45,000
Now prompt is something, uh, you know, by default some text message will be there.

151
00:08:45,000 --> 00:08:54,000
So I'll write from prompt colon equal to okay I'll go ahead and say TX dot chat underscore input okay.

152
00:08:54,000 --> 00:08:57,000
And here I'm going to just go ahead and see chat.

153
00:08:57,000 --> 00:09:02,000
Underscore input is also one very important uh component in Streamlit.

154
00:09:02,000 --> 00:09:05,000
And here we are just going to go ahead and put our placeholder.

155
00:09:05,000 --> 00:09:07,000
So I will go ahead and write my placeholder.

156
00:09:07,000 --> 00:09:10,000
And I'll say hey what is machine learning.

157
00:09:10,000 --> 00:09:14,000
I'm just going to put a simple basic message, okay.

158
00:09:15,000 --> 00:09:17,000
Uh, regarding this chat underscore input.

159
00:09:17,000 --> 00:09:22,000
Now this prompt by default will be having this specific placeholder.

160
00:09:22,000 --> 00:09:24,000
Now I will go inside this.

161
00:09:24,000 --> 00:09:28,000
If this particular prompt is specifically written, I will go ahead and say, hey, let's go ahead and

162
00:09:28,000 --> 00:09:33,000
create this SD dot session state session underscore state.

163
00:09:33,000 --> 00:09:35,000
And I'm going to take this messages.

164
00:09:35,000 --> 00:09:37,000
Um let's see.

165
00:09:37,000 --> 00:09:41,000
Yes messages dot I'm going to append some role.

166
00:09:41,000 --> 00:09:41,000
Right.

167
00:09:41,000 --> 00:09:48,000
And initially whenever I try to put any if I try to ask any query the role, you know what it should

168
00:09:48,000 --> 00:09:49,000
be added.

169
00:09:49,000 --> 00:09:50,000
It should be added as a user.

170
00:09:50,000 --> 00:09:52,000
So this will be my role.

171
00:09:52,000 --> 00:09:52,000
Okay.

172
00:09:52,000 --> 00:09:57,000
And the content that I'm actually going to add is nothing but my prompt.

173
00:09:57,000 --> 00:09:57,000
Okay.

174
00:09:57,000 --> 00:10:01,000
So here I'm going to probably go ahead and create my prompt.

175
00:10:01,000 --> 00:10:02,000
Perfect.

176
00:10:04,000 --> 00:10:11,000
So once we add this then the next step will be that I will go ahead and say TT dot chat underscore message.

177
00:10:12,000 --> 00:10:15,000
And here I'm going to basically use user.

178
00:10:15,000 --> 00:10:22,000
And we are just going to write this prompt dot right of prompt.

179
00:10:22,000 --> 00:10:23,000
Okay.

180
00:10:23,000 --> 00:10:28,000
So what we are basically doing is that whenever we write any prompt, it is going to get appended in

181
00:10:28,000 --> 00:10:30,000
this particular message so that we will be able to read this.

182
00:10:30,000 --> 00:10:30,000
And.

183
00:10:30,000 --> 00:10:31,000
All right.

184
00:10:31,000 --> 00:10:33,000
Uh, so this is also done.

185
00:10:33,000 --> 00:10:38,000
Uh, now the next step will be that, uh, inside this right inside this prompt itself, we will go

186
00:10:38,000 --> 00:10:40,000
ahead and create our LM.

187
00:10:40,000 --> 00:10:42,000
So I'll write chat grok.

188
00:10:42,000 --> 00:10:42,000
And.

189
00:10:45,000 --> 00:10:51,000
I will go ahead and use chat grok underscore API underscore key okay.

190
00:10:51,000 --> 00:10:56,000
Which will be equal to I think I've written right chat grok.

191
00:10:56,000 --> 00:10:59,000
And here have I imported chat grok or not.

192
00:10:59,000 --> 00:11:01,000
Yes I have imported Chat Grok.

193
00:11:01,000 --> 00:11:04,000
So here I will be using my grok API key.

194
00:11:04,000 --> 00:11:04,000
So let's see.

195
00:11:05,000 --> 00:11:07,000
The grok API key has been imported or not.

196
00:11:07,000 --> 00:11:08,000
It's okay.

197
00:11:08,000 --> 00:11:14,000
So we are going to get this grok API key from our uh parameters right.

198
00:11:14,000 --> 00:11:16,000
Which we will be getting it through from the input itself.

199
00:11:16,000 --> 00:11:17,000
Right.

200
00:11:17,000 --> 00:11:23,000
So here what I will do, I will just use this API key that I'm actually going to use it over here okay.

201
00:11:23,000 --> 00:11:26,000
So once this is done, uh, this will basically be my model.

202
00:11:26,000 --> 00:11:29,000
And here I'm just going to use my model underscore name.

203
00:11:29,000 --> 00:11:35,000
You can use any model for now I'm using llama three 8 billion parameter.

204
00:11:35,000 --> 00:11:37,000
And this will be with 8912 okay.

205
00:11:37,000 --> 00:11:38,000
So this will be my model.

206
00:11:38,000 --> 00:11:42,000
And here I'm also going to keep my parameter as streaming is equal to true.

207
00:11:42,000 --> 00:11:44,000
So let me just go ahead and write it over here.

208
00:11:44,000 --> 00:11:47,000
And streaming will be equal to true okay.

209
00:11:47,000 --> 00:11:47,000
Okay.

210
00:11:49,000 --> 00:11:53,000
So this basically becomes my LM model altogether.

211
00:11:53,000 --> 00:11:59,000
Um, I have initialized all the all the tools, whichever I really want to use it.

212
00:11:59,000 --> 00:12:00,000
Okay.

213
00:12:00,000 --> 00:12:02,000
And these are the tools that I initialized.

214
00:12:02,000 --> 00:12:03,000
Right.

215
00:12:03,000 --> 00:12:07,000
Uh, one is uh, the wiki, one is RCF and one is search.

216
00:12:07,000 --> 00:12:10,000
So I will go ahead and create a variable called as tools.

217
00:12:11,000 --> 00:12:14,000
And I will initialize all these tools over here.

218
00:12:14,000 --> 00:12:14,000
Okay.

219
00:12:14,000 --> 00:12:16,000
So let's say I will go ahead and write.

220
00:12:17,000 --> 00:12:19,000
One is search.

221
00:12:19,000 --> 00:12:20,000
Then one is are safe.

222
00:12:20,000 --> 00:12:21,000
Then one is wiki.

223
00:12:22,000 --> 00:12:22,000
Okay.

224
00:12:22,000 --> 00:12:24,000
All these tools is specifically been added.

225
00:12:24,000 --> 00:12:30,000
Now I need to convert this entire tools into an agent so that I will be able to, you know, invoke

226
00:12:30,000 --> 00:12:31,000
this specific agent.

227
00:12:31,000 --> 00:12:33,000
So I will say, hey, this is my search agent.

228
00:12:33,000 --> 00:12:38,000
And here I'm going to basically use this initialize agent function.

229
00:12:38,000 --> 00:12:43,000
And along with this I will be using my uh my tools will be going over here.

230
00:12:43,000 --> 00:12:44,000
So this will be my tools.

231
00:12:44,000 --> 00:12:49,000
This tools will be in the form of list that you have over here.

232
00:12:49,000 --> 00:12:53,000
So all the search search Ar7 wiki we are going to specifically use over here.

233
00:12:53,000 --> 00:12:58,000
And along with this the second parameter will be my LM which I'm actually going to use.

234
00:12:58,000 --> 00:13:01,000
The third will be something called as agent.

235
00:13:01,000 --> 00:13:06,000
So the agent that we are going to basically initialize over here is my agent type dot.

236
00:13:06,000 --> 00:13:10,000
There will be something called as zero short react description.

237
00:13:10,000 --> 00:13:14,000
And there is also something called as chat zero short react description.

238
00:13:14,000 --> 00:13:17,000
And there is one more something called as structured chat zero short react description.

239
00:13:17,000 --> 00:13:22,000
You can definitely see the documentation what exactly this means, but let me give you a brief idea.

240
00:13:22,000 --> 00:13:28,000
What is the main difference between zero shot react description and zero shot react description?

241
00:13:28,000 --> 00:13:36,000
It basically lies in how they handle our context and memory, how they generate prompts for the language

242
00:13:36,000 --> 00:13:36,000
model.

243
00:13:36,000 --> 00:13:42,000
See in the case of zero shot, zero shot, uh, react description, they don't rely on the chat history,

244
00:13:42,000 --> 00:13:43,000
right?

245
00:13:43,000 --> 00:13:48,000
Uh, it makes a decision based on the current input only without considering any previous action.

246
00:13:48,000 --> 00:13:54,000
Similarly, on the other hand, if I use Chad zero shot react description, it uses a chat history to

247
00:13:54,000 --> 00:13:59,000
remember the context of the chat and the history of the conversation, and it accepts a certain structure

248
00:13:59,000 --> 00:14:02,000
in the chat history and might raise an error if it does not find it.

249
00:14:02,000 --> 00:14:08,000
Okay, so in our case, I will just go ahead and use this zero shot react description.

250
00:14:08,000 --> 00:14:14,000
And here I'm also going to make sure that I give one more additional parameter which is called as handling

251
00:14:14,000 --> 00:14:14,000
pass.

252
00:14:14,000 --> 00:14:21,000
So here I'm going to go ahead and write handling underscore pass is passing.

253
00:14:21,000 --> 00:14:21,000
Sorry.

254
00:14:21,000 --> 00:14:24,000
Passing underscore errors is equal to true.

255
00:14:24,000 --> 00:14:29,000
I'm also saying that if you face any errors please make sure that you also pass those errors okay.

256
00:14:29,000 --> 00:14:34,000
So this are the basic parameters that I specifically require over here.

257
00:14:34,000 --> 00:14:34,000
Right.

258
00:14:34,000 --> 00:14:39,000
So here inside all these things I've actually given this Let me make the spelling right.

259
00:14:39,000 --> 00:14:40,000
Search underscore agent.

260
00:14:40,000 --> 00:14:41,000
Okay.

261
00:14:41,000 --> 00:14:43,000
And this is how we basically create this agent.

262
00:14:44,000 --> 00:14:48,000
Now it's time that we go ahead and have this kind of conversation.

263
00:14:48,000 --> 00:14:49,000
And it should be able to give us an answer.

264
00:14:49,000 --> 00:14:54,000
So I'll try it with s t dot chat underscore message.

265
00:14:54,000 --> 00:14:59,000
And I'm going to give the history over here or sorry message of assistant.

266
00:14:59,000 --> 00:15:00,000
Right.

267
00:15:00,000 --> 00:15:02,000
So I'll go ahead and give like assistant.

268
00:15:02,000 --> 00:15:03,000
Okay.

269
00:15:03,000 --> 00:15:06,000
Whenever the assistant is giving me any kind of response.

270
00:15:06,000 --> 00:15:11,000
So what I'm actually going to do is that I'm also going to call this Streamlit callback handler.

271
00:15:11,000 --> 00:15:16,000
I know there are multiple things that I'm actually showing you, but this is the best way of creating

272
00:15:16,000 --> 00:15:16,000
this, right?

273
00:15:16,000 --> 00:15:22,000
So once I use the Streamlit callback handler, understand what it is doing it is displaying.

274
00:15:22,000 --> 00:15:27,000
It is used to display the thoughts and action of an agent in an interactive Streamlit app.

275
00:15:27,000 --> 00:15:32,000
So now whenever my agent is basically communicating with itself, right?

276
00:15:32,000 --> 00:15:33,000
It should be.

277
00:15:33,000 --> 00:15:37,000
We should be able to see that and that will be able to see once I will execute it.

278
00:15:37,000 --> 00:15:40,000
So here I will be using an SD dot container.

279
00:15:40,000 --> 00:15:42,000
So container over here.

280
00:15:42,000 --> 00:15:47,000
And if you see what exactly this container is it in turn insert a multi element container.

281
00:15:47,000 --> 00:15:52,000
Inserts an invisible container into your app that can be used to hold multiple elements.

282
00:15:52,000 --> 00:15:55,000
This allows you to, for example, insert multiple elements into your app out of order.

283
00:15:55,000 --> 00:15:57,000
Okay, that is the reason we are specifically using.

284
00:15:57,000 --> 00:16:02,000
You'll be seeing will be able to see that block wise.

285
00:16:02,000 --> 00:16:04,000
You'll be having that entire information.

286
00:16:04,000 --> 00:16:10,000
And then we will go ahead and create one more parameter called as expand underscore new underscore thoughts.

287
00:16:10,000 --> 00:16:14,000
And I'll say, please, whatever thoughts you have show me that detailed explanation.

288
00:16:14,000 --> 00:16:19,000
And if I say expand, right, so every thought will probably just get opened.

289
00:16:19,000 --> 00:16:22,000
We can also open this, but right now I'll just keep it to false.

290
00:16:22,000 --> 00:16:29,000
So again this expand new thoughts you'll be able to see once I probably, uh, run my entire application.

291
00:16:29,000 --> 00:16:30,000
You'll be seeing that by default it will be closed.

292
00:16:30,000 --> 00:16:32,000
You can also open it okay.

293
00:16:32,000 --> 00:16:36,000
Now let's go ahead and get the response so quickly I will go ahead and write.

294
00:16:36,000 --> 00:16:42,000
Response is equal to search underscore agent dot run.

295
00:16:42,000 --> 00:16:51,000
I will run this and while running I will also give all my session state dot messages okay.

296
00:16:51,000 --> 00:16:54,000
And I will say hey you can also make a callback.

297
00:16:54,000 --> 00:16:59,000
So there is a parameter which is called as callbacks with whatever callback we have actually created,

298
00:16:59,000 --> 00:16:59,000
right?

299
00:16:59,000 --> 00:17:01,000
Streamlit callback handler.

300
00:17:01,000 --> 00:17:08,000
So I'll go ahead and say TX comma cb okay, once I do this now the next step will be that I will go

301
00:17:08,000 --> 00:17:15,000
ahead and again append it's t dot session, underscore state dot messages dot append.

302
00:17:15,000 --> 00:17:21,000
And here I'm going to specifically use my role as assistant because this will be given by the assistant

303
00:17:21,000 --> 00:17:23,000
itself okay.

304
00:17:23,000 --> 00:17:30,000
And my whatever response I'm actually specifically getting it will be inserted into the content part.

305
00:17:30,000 --> 00:17:33,000
So here I have this response okay.

306
00:17:33,000 --> 00:17:39,000
Now quickly let's go ahead and write SD dot write response okay.

307
00:17:39,000 --> 00:17:42,000
So this is what it is.

308
00:17:42,000 --> 00:17:45,000
And uh I think we have executed this entire thing.

309
00:17:45,000 --> 00:17:48,000
Uh, let's execute this entire thing and see whether everything is working fine or not.

310
00:17:48,000 --> 00:17:50,000
But I think it should work.

311
00:17:50,000 --> 00:17:53,000
Just to give you a quick revision, we have created all the tools wrapper.

312
00:17:53,000 --> 00:17:57,000
Then we use this tools parameter over here which will be included.

313
00:17:57,000 --> 00:18:04,000
We created our search agent LM agent type this, this this and we are good to go with respect to this

314
00:18:04,000 --> 00:18:04,000
okay.

315
00:18:04,000 --> 00:18:08,000
And this is completely with the open source uh LM models.

316
00:18:08,000 --> 00:18:14,000
Now I will quickly go ahead and write CD which folder it is in five search engine.

317
00:18:14,000 --> 00:18:17,000
So I will go ahead and write right five tab search engine.

318
00:18:17,000 --> 00:18:19,000
Now quickly let's go ahead and run it.

319
00:18:19,000 --> 00:18:21,000
Streamlit run app.py okay.

320
00:18:21,000 --> 00:18:24,000
So once I run this I hope so.

321
00:18:24,000 --> 00:18:26,000
It should get executed.

322
00:18:26,000 --> 00:18:29,000
Okay, so here it is.

323
00:18:29,000 --> 00:18:32,000
Um, HDR object has no attribute.

324
00:18:32,000 --> 00:18:33,000
Let's see.

325
00:18:33,000 --> 00:18:36,000
So it says on line 36 I'm having this particular error.

326
00:18:36,000 --> 00:18:37,000
Let's see okay.

327
00:18:37,000 --> 00:18:41,000
Line 36 I am I'm having this particular error.

328
00:18:41,000 --> 00:18:45,000
Let me go ahead and check to this.

329
00:18:45,000 --> 00:18:47,000
What is exactly the problem over here.

330
00:18:47,000 --> 00:18:55,000
So if I probably see this message 36 it is chat underscore message message dot okay I made one specific

331
00:18:55,000 --> 00:18:56,000
simple mistake.

332
00:18:56,000 --> 00:18:58,000
I should have close the brackets over here.

333
00:18:59,000 --> 00:19:01,000
And no need of this specific brackets.

334
00:19:02,000 --> 00:19:08,000
So whenever you get an error, don't feel afraid of the things that you are seeing.

335
00:19:08,000 --> 00:19:10,000
Instead, just try to fix it.

336
00:19:10,000 --> 00:19:12,000
Now this looks absolutely fabulous, right?

337
00:19:13,000 --> 00:19:17,000
Uh, quickly, let me just go ahead and take my grok key.

338
00:19:17,000 --> 00:19:21,000
I will copy this entire thing over here.

339
00:19:21,000 --> 00:19:26,000
I'll go over here and press enter, and let's go ahead and do.

340
00:19:26,000 --> 00:19:26,000
Okay.

341
00:19:26,000 --> 00:19:28,000
I did not write one more condition over here.

342
00:19:28,000 --> 00:19:28,000
Okay.

343
00:19:29,000 --> 00:19:32,000
Um, and that is the reason it may give us an error.

344
00:19:32,000 --> 00:19:41,000
I'll say if prompt and and write and the API key, I have to probably give this API key.

345
00:19:41,000 --> 00:19:42,000
Okay.

346
00:19:42,000 --> 00:19:43,000
Now I think it should run.

347
00:19:44,000 --> 00:19:46,000
Oh let's go ahead and copy and paste it.

348
00:19:46,000 --> 00:19:47,000
I will press enter.

349
00:19:48,000 --> 00:19:54,000
Now I will go ahead and write what is generative AI?

350
00:19:56,000 --> 00:19:58,000
Oh God, it is getting displayed.

351
00:19:58,000 --> 00:20:00,000
Why it is getting displayed, we'll see to it.

352
00:20:00,000 --> 00:20:04,000
But at least the functionality is working over here, right?

353
00:20:04,000 --> 00:20:05,000
So this is my key.

354
00:20:05,000 --> 00:20:06,000
The key should not get displayed over here.

355
00:20:06,000 --> 00:20:08,000
But it got displayed.

356
00:20:08,000 --> 00:20:08,000
Okay.

357
00:20:08,000 --> 00:20:09,000
Let's see.

358
00:20:09,000 --> 00:20:13,000
Uh, am I printing somewhere the API key?

359
00:20:13,000 --> 00:20:15,000
So API key is over here.

360
00:20:16,000 --> 00:20:16,000
Okay.

361
00:20:16,000 --> 00:20:20,000
It is also getting appended in this specific message okay.

362
00:20:20,000 --> 00:20:22,000
But let's see whether everything is working fine or not.

363
00:20:22,000 --> 00:20:25,000
So here you can see I asked what is machine learning okay.

364
00:20:26,000 --> 00:20:29,000
Um or here you can see what can I search.

365
00:20:29,000 --> 00:20:30,000
Okay.

366
00:20:30,000 --> 00:20:33,000
Let's see I'll ask what is machine learning.

367
00:20:33,000 --> 00:20:35,000
Let's hit one more time okay.

368
00:20:35,000 --> 00:20:37,000
So again this is getting displayed.

369
00:20:37,000 --> 00:20:41,000
How can I help you search okay.

370
00:20:41,000 --> 00:20:42,000
There there is some problem over here.

371
00:20:42,000 --> 00:20:44,000
Let's see some problem.

372
00:20:44,000 --> 00:20:45,000
Some problem.

373
00:20:45,000 --> 00:20:51,000
So whenever I'm hitting a query write prompt, then it is writing the specific prompt.

374
00:20:51,000 --> 00:20:55,000
The simple reason is that because it is considering this as a prompt.

375
00:20:55,000 --> 00:20:56,000
Okay.

376
00:20:56,000 --> 00:21:02,000
So uh, that is the reason you will be able to see that when I'm hitting this and I'm putting this particular

377
00:21:02,000 --> 00:21:03,000
condition.

378
00:21:03,000 --> 00:21:04,000
Okay, let's do one thing.

379
00:21:04,000 --> 00:21:05,000
Let's remove this for now.

380
00:21:05,000 --> 00:21:06,000
Onwards.

381
00:21:06,000 --> 00:21:06,000
Okay.

382
00:21:06,000 --> 00:21:08,000
And let's reload it.

383
00:21:09,000 --> 00:21:10,000
We'll go ahead and reload it.

384
00:21:10,000 --> 00:21:13,000
I will quickly do one thing.

385
00:21:13,000 --> 00:21:15,000
I will put my API key, I'll press enter.

386
00:21:16,000 --> 00:21:20,000
And now I will just go ahead and write what is machine learning.

387
00:21:21,000 --> 00:21:27,000
So now I'm getting the input because the API key was basically getting uh, you know hidden over there.

388
00:21:27,000 --> 00:21:32,000
So now you see, see see the perfect thing As soon as I searched what is machine learning?

389
00:21:32,000 --> 00:21:34,000
It it went to directly to Wikipedia.

390
00:21:34,000 --> 00:21:38,000
Now, see, the interaction is also basically happening right here.

391
00:21:38,000 --> 00:21:41,000
You can see automatically Wikipedia is able to give some more information.

392
00:21:41,000 --> 00:21:42,000
Okay.

393
00:21:42,000 --> 00:21:45,000
Then it automatically took the examples.

394
00:21:45,000 --> 00:21:47,000
Then Wikipedia is saying hey I have more details.

395
00:21:47,000 --> 00:21:48,000
Go ahead and see this.

396
00:21:48,000 --> 00:21:48,000
Right.

397
00:21:49,000 --> 00:21:51,000
Uh, and here you can see, hey, Wikipedia is also there.

398
00:21:51,000 --> 00:21:51,000
Right.

399
00:21:51,000 --> 00:21:55,000
And all the information is here is the response.

400
00:21:55,000 --> 00:21:56,000
All the information is basically coming up.

401
00:21:56,000 --> 00:21:57,000
Right.

402
00:21:57,000 --> 00:21:59,000
And finally this is the output that I'm able to get.

403
00:21:59,000 --> 00:22:02,000
See, so much interaction is basically happening right.

404
00:22:03,000 --> 00:22:06,000
Uh this content is basically getting displayed I'm printing it right.

405
00:22:06,000 --> 00:22:07,000
Action.

406
00:22:07,000 --> 00:22:09,000
Everything is going on okay okay.

407
00:22:09,000 --> 00:22:13,000
Tell me about the research paper.

408
00:22:13,000 --> 00:22:14,000
Okay.

409
00:22:15,000 --> 00:22:18,000
Um, attention is all you need.

410
00:22:19,000 --> 00:22:20,000
and I'll go ahead and press enter.

411
00:22:21,000 --> 00:22:23,000
See, it went to arXiv.

412
00:22:23,000 --> 00:22:24,000
Amazing.

413
00:22:24,000 --> 00:22:24,000
Right.

414
00:22:24,000 --> 00:22:27,000
So here now it is thinking now Wikipedia came into picture.

415
00:22:27,000 --> 00:22:28,000
Okay.

416
00:22:29,000 --> 00:22:31,000
Then suddenly it went to search.

417
00:22:31,000 --> 00:22:33,000
Attention is all you need arXiv paper.

418
00:22:33,000 --> 00:22:34,000
Then again it went to search.

419
00:22:34,000 --> 00:22:37,000
See how the interaction is basically happening, right?

420
00:22:38,000 --> 00:22:43,000
I thought I understood that the user wants to know more about the research paper right over here.

421
00:22:43,000 --> 00:22:44,000
This is the thought.

422
00:22:44,000 --> 00:22:45,000
Here is the continuation.

423
00:22:45,000 --> 00:22:48,000
The Wikipedia search found a relevant way, but it is not a research paper.

424
00:22:48,000 --> 00:22:50,000
See, attention is all you need.

425
00:22:50,000 --> 00:22:51,000
You don't want to know more about this.

426
00:22:51,000 --> 00:22:54,000
Or I say attention is no good or save result was found.

427
00:22:55,000 --> 00:22:56,000
Amazing right?

428
00:22:56,000 --> 00:23:01,000
So this automatically this is like you know you have independent tools who are interacting with the

429
00:23:01,000 --> 00:23:02,000
outside world.

430
00:23:02,000 --> 00:23:07,000
It's like I'm having four people who's probably doing all the search and who is probably, you know,

431
00:23:07,000 --> 00:23:09,000
making sure that all the things basically happen.

432
00:23:09,000 --> 00:23:13,000
And one error is over here handling parsing errors.

433
00:23:13,000 --> 00:23:14,000
Okay.

434
00:23:14,000 --> 00:23:19,000
An output parser, this is error could not pass LM thought I have found multiple research paper okay.

435
00:23:19,000 --> 00:23:20,000
So let's see.

436
00:23:20,000 --> 00:23:21,000
We'll try to fix this also.

437
00:23:21,000 --> 00:23:27,000
But uh uh I think uh, this is just because uh, they have actually got multiple results, like no one

438
00:23:27,000 --> 00:23:30,000
is coming to the right purpose right over here.

439
00:23:30,000 --> 00:23:31,000
So now let's see.

440
00:23:31,000 --> 00:23:32,000
I'll go ahead and write.

441
00:23:32,000 --> 00:23:34,000
Attention is all you need.

442
00:23:34,000 --> 00:23:34,000
Okay.

443
00:23:34,000 --> 00:23:37,000
And I will just go and search for this research paper.

444
00:23:38,000 --> 00:23:39,000
Okay.

445
00:23:40,000 --> 00:23:41,000
I will say hey.

446
00:23:44,000 --> 00:23:47,000
Provide a summary of.

447
00:23:50,000 --> 00:23:55,000
So here you can see that automatically all this summary will be found out by ourself.

448
00:23:56,000 --> 00:24:01,000
Right here all the information once a summary of attention is all you need.

449
00:24:01,000 --> 00:24:02,000
Then again it is doing this.

450
00:24:02,000 --> 00:24:06,000
It did not have to probably go with or ask any other tools.

451
00:24:06,000 --> 00:24:08,000
The user is asking title this, this this.

452
00:24:08,000 --> 00:24:10,000
All the information is over here.

453
00:24:11,000 --> 00:24:16,000
The user is asking for the summary of the research paper, which is a published paper on arXiv.

454
00:24:18,000 --> 00:24:19,000
Right.

455
00:24:19,000 --> 00:24:22,000
So this is going on and this interaction will keep on going ahead.

456
00:24:22,000 --> 00:24:24,000
And finally you'll be able to see some output.

457
00:24:24,000 --> 00:24:27,000
It will be able to probably provide you okay.

458
00:24:28,000 --> 00:24:35,000
But uh, here I see that it is also going into that entire loop I agent stopped due to iteration limit.

459
00:24:35,000 --> 00:24:36,000
Yes.

460
00:24:36,000 --> 00:24:39,000
So this can also be one type of problem.

461
00:24:39,000 --> 00:24:43,000
Uh, we'll see in the upcoming videos how we can fix this kind of problem also.

462
00:24:43,000 --> 00:24:48,000
Okay, so let me just go ahead and ask, just like this okay, I want.

463
00:24:50,000 --> 00:24:55,000
Tell me about the research paper.

464
00:24:56,000 --> 00:24:57,000
Nothing but this.

465
00:24:58,000 --> 00:25:05,000
So here you can see the user is asking about a specific I have a tool to search for it on arXiv right

466
00:25:05,000 --> 00:25:08,000
then Wikipedia, then all this interaction is coming.

467
00:25:08,000 --> 00:25:10,000
And this paper is this authored by so and so.

468
00:25:10,000 --> 00:25:12,000
All the information is over here.

469
00:25:12,000 --> 00:25:12,000
Right.

470
00:25:12,000 --> 00:25:17,000
Let me just go ahead and search for something like what is generative AI.

471
00:25:17,000 --> 00:25:21,000
Now I think it should probably go with Wikipedia or search.

472
00:25:21,000 --> 00:25:22,000
Right.

473
00:25:22,000 --> 00:25:24,000
So search is duck duck go search right.

474
00:25:24,000 --> 00:25:28,000
Thought the user has multiple ranges ranging from general topics like what is the machine learning to

475
00:25:28,000 --> 00:25:29,000
specifically see.

476
00:25:29,000 --> 00:25:31,000
It is also using the chat history.

477
00:25:31,000 --> 00:25:31,000
Right.

478
00:25:31,000 --> 00:25:33,000
And based on that it is giving you the entire response.

479
00:25:34,000 --> 00:25:34,000
Right?

480
00:25:34,000 --> 00:25:36,000
I've already provided a brief overview.

481
00:25:36,000 --> 00:25:37,000
See, it's saying that again.

482
00:25:37,000 --> 00:25:38,000
I'll not go ahead and provide it.

483
00:25:38,000 --> 00:25:40,000
I've already provided it right.

484
00:25:40,000 --> 00:25:41,000
Generative AI right.

485
00:25:41,000 --> 00:25:43,000
And here are all the answers.

486
00:25:43,000 --> 00:25:46,000
So I hope you are able to understand this.

487
00:25:46,000 --> 00:25:51,000
Uh, again, um, if you want to go ahead and explore more examples, you can go ahead and check it

488
00:25:51,000 --> 00:25:51,000
out over here.

489
00:25:51,000 --> 00:25:52,000
Right.

490
00:25:52,000 --> 00:25:55,000
So yes, this was it about this entire end to end projects.

491
00:25:55,000 --> 00:25:57,000
Uh, we'll see, uh, some more errors that we are getting.

492
00:25:57,000 --> 00:26:01,000
I think I need to have a look why we got that specific error, but I don't think so.

493
00:26:01,000 --> 00:26:04,000
It is a major issue with respect to that.

494
00:26:04,000 --> 00:26:08,000
Unless and until we are having a good interaction between the agents, I think we can work out.

495
00:26:08,000 --> 00:26:14,000
One assignment that I really want to give you is that try to integrate a PDF document Q&A along with

496
00:26:14,000 --> 00:26:18,000
these tools, and try to add it also and try to see that how the interaction will basically happen.

497
00:26:18,000 --> 00:26:20,000
So yes, this was it for my side.

498
00:26:20,000 --> 00:26:21,000
I'll see you all in the next video.

499
00:26:21,000 --> 00:26:21,000
Thank you.

