1
00:00:00,000 --> 00:00:03,000
So guys, we will be continuing with respect to our end to end project.

2
00:00:03,000 --> 00:00:07,000
Already we have developed all these things where we have configured our LLM.

3
00:00:07,000 --> 00:00:11,000
We have configured our entire database, uh, which database to connect when.

4
00:00:11,000 --> 00:00:13,000
Now let's go ahead and run this.

5
00:00:13,000 --> 00:00:16,000
You know, I also want to probably check whether this is running fine or not.

6
00:00:16,000 --> 00:00:21,000
So I will go ahead and write Streamlit run App.py just to verify.

7
00:00:21,000 --> 00:00:22,000
Is everything fine.

8
00:00:22,000 --> 00:00:27,000
So here you can actually see my page getting loaded.

9
00:00:27,000 --> 00:00:31,000
So here you can see both the options are over here right to select this.

10
00:00:31,000 --> 00:00:35,000
And if I select I'm able to see all my other details.

11
00:00:35,000 --> 00:00:38,000
And it is asking for grok API key.

12
00:00:38,000 --> 00:00:40,000
So that is what I am going to provide.

13
00:00:40,000 --> 00:00:42,000
Uh oh I have already provided a field over here.

14
00:00:42,000 --> 00:00:47,000
Now, uh, as soon as I put the information I am able to configure that part.

15
00:00:47,000 --> 00:00:48,000
Also, I have actually done it.

16
00:00:48,000 --> 00:00:55,000
Now, the thing is that I need to probably create a text box this side and whenever I fill up all this

17
00:00:55,000 --> 00:00:58,000
information, I should be able to interact with my database.

18
00:00:58,000 --> 00:01:00,000
So that is what is basically remaining.

19
00:01:00,000 --> 00:01:03,000
And for this we really need to work with something called as toolkit.

20
00:01:03,000 --> 00:01:03,000
Okay.

21
00:01:03,000 --> 00:01:07,000
So that is what we are going to design in this particular video okay.

22
00:01:07,000 --> 00:01:11,000
So let's go ahead and let's quickly start working on this.

23
00:01:11,000 --> 00:01:14,000
So first of all I will go ahead and create my toolkit.

24
00:01:14,000 --> 00:01:15,000
And this will be nothing.

25
00:01:15,000 --> 00:01:18,000
But it will be a SQL database toolkit.

26
00:01:18,000 --> 00:01:22,000
I'll use my DB is equal to db whatever db I have.

27
00:01:22,000 --> 00:01:24,000
Actually, uh, I'm getting from configuring it.

28
00:01:25,000 --> 00:01:29,000
So once I call this particular function, I'll be able to get the DB and my LM model, which I'm going

29
00:01:29,000 --> 00:01:31,000
to assign with my chart grok API.

30
00:01:31,000 --> 00:01:32,000
Right.

31
00:01:32,000 --> 00:01:33,000
So this is done.

32
00:01:33,000 --> 00:01:37,000
Now what I'm actually going to do quickly go ahead and create my agent.

33
00:01:37,000 --> 00:01:40,000
And here I'm going to use my create SQL agent okay.

34
00:01:40,000 --> 00:01:47,000
Now inside this I have to probably pass my LM model which will be required for creating my SQL agent.

35
00:01:47,000 --> 00:01:52,000
Along with this, I will go ahead and provide my toolkit details what toolkit I really want.

36
00:01:52,000 --> 00:01:57,000
I'll also make sure that to keep this parameter verbose is equal to true, because I really want to

37
00:01:57,000 --> 00:02:00,000
see all the interaction and each and everything.

38
00:02:00,000 --> 00:02:02,000
And finally we will go ahead and set up our agent type.

39
00:02:02,000 --> 00:02:05,000
The agent type will be nothing but this same agent type.

40
00:02:05,000 --> 00:02:12,000
And this I will also go ahead and use zero shot react description, which I've already told in my previous

41
00:02:12,000 --> 00:02:15,000
video itself in the previous project that we have developed.

42
00:02:15,000 --> 00:02:22,000
Okay, now, uh, quickly, uh, what I will do is that I will go ahead and make my session state like

43
00:02:22,000 --> 00:02:26,000
how we did it, because we also need to maintain our chat history.

44
00:02:26,000 --> 00:02:32,000
So here you can see if message not in session state dot uh session underscore state or state or sidebar

45
00:02:32,000 --> 00:02:34,000
button, clear message history.

46
00:02:34,000 --> 00:02:36,000
I also will have a specific button.

47
00:02:36,000 --> 00:02:40,000
If I clear clear click on that it will remove the entire history.

48
00:02:40,000 --> 00:02:40,000
Okay.

49
00:02:40,000 --> 00:02:44,000
So here you'll be able to see that SD dot session underscore state of message.

50
00:02:44,000 --> 00:02:46,000
I'm first of all adding this role and assistant.

51
00:02:46,000 --> 00:02:49,000
And I can say just how can I help you in the content okay.

52
00:02:49,000 --> 00:02:51,000
So this is the default message.

53
00:02:51,000 --> 00:02:56,000
Now what I'm actually going to do is that for every session message right.

54
00:02:56,000 --> 00:03:01,000
I have to make sure that I have to integrate this, like how we did it in a previous project.

55
00:03:01,000 --> 00:03:03,000
So I will just go ahead and copy paste over here.

56
00:03:03,000 --> 00:03:08,000
So for message in St dot session underscore state dot messages, I'm saying I'm appending everything

57
00:03:08,000 --> 00:03:12,000
inside this chat underscore message so that it has all the information.

58
00:03:12,000 --> 00:03:17,000
So finally I will go ahead and create my user underscore query.

59
00:03:17,000 --> 00:03:22,000
And here I will go ahead and write st dot chat underscore input.

60
00:03:22,000 --> 00:03:23,000
Okay.

61
00:03:23,000 --> 00:03:26,000
So let me just go ahead and write chat underscore input.

62
00:03:26,000 --> 00:03:36,000
And inside this I will go ahead and put a placeholder and ask anything from the database okay.

63
00:03:36,000 --> 00:03:39,000
So I'm going to put this entire information over here.

64
00:03:39,000 --> 00:03:43,000
If I go ahead and put my user query okay.

65
00:03:43,000 --> 00:03:49,000
The next thing what I really need to do is that I need to append my session state with that specific

66
00:03:49,000 --> 00:03:51,000
message from the user, right?

67
00:03:51,000 --> 00:03:55,000
So for that, what I will do, I will quickly go ahead and add like this HD dot session underscore state

68
00:03:55,000 --> 00:04:01,000
dot messages dot append where I'm going to give the role as user and content whatever user query is

69
00:04:01,000 --> 00:04:06,000
basically getting added right along with this, what I will say is that I will also make sure I to add

70
00:04:06,000 --> 00:04:08,000
it over here in SD dot chat message.

71
00:04:08,000 --> 00:04:11,000
So SD dot chat message of user dot write user query.

72
00:04:11,000 --> 00:04:17,000
So we are going to write it over there with respect to the uh whatever the user query is there in the

73
00:04:17,000 --> 00:04:17,000
screen.

74
00:04:17,000 --> 00:04:17,000
Okay.

75
00:04:18,000 --> 00:04:23,000
Now we will go ahead and write further st dot chat underscore message.

76
00:04:24,000 --> 00:04:29,000
And here we are specifically going to use assistant okay.

77
00:04:29,000 --> 00:04:34,000
And again in this I will go ahead and create my callback okay.

78
00:04:34,000 --> 00:04:42,000
So I will write Streamlit underscore callback is equal to Streamlit callback handler.

79
00:04:42,000 --> 00:04:45,000
And here I'm going to write s t dot container.

80
00:04:48,000 --> 00:04:54,000
Once I write this this will be the callback which will be responsible in showing what are the chain

81
00:04:54,000 --> 00:04:54,000
of thoughts you know.

82
00:04:54,000 --> 00:04:56,000
And that will also be getting displayed.

83
00:04:56,000 --> 00:05:02,000
Finally I'm going to go ahead and create my response where I will be saying, agent Dot, we will be

84
00:05:02,000 --> 00:05:05,000
running this entire thing by taking the user query.

85
00:05:06,000 --> 00:05:11,000
Along with that, I'm also going to give my callbacks, which will be nothing, but it will be the same

86
00:05:11,000 --> 00:05:13,000
Streamlit callback which we are using.

87
00:05:13,000 --> 00:05:13,000
Okay.

88
00:05:14,000 --> 00:05:21,000
And finally, what I will do is that after this, let's see, I will just close it over here itself

89
00:05:21,000 --> 00:05:28,000
And here in the next message I will go ahead and write SD dot session underscore state dot messages.

90
00:05:28,000 --> 00:05:31,000
We need to append once we get the specific response.

91
00:05:31,000 --> 00:05:34,000
So that is the reason we are going to write dot append.

92
00:05:34,000 --> 00:05:40,000
And here again we are going to use a role since it is probably coming from the assistant itself.

93
00:05:40,000 --> 00:05:45,000
So I will be giving the role as assistant assistant.

94
00:05:45,000 --> 00:05:51,000
And finally you'll also be seeing that I will be giving my content inside this content.

95
00:05:51,000 --> 00:05:55,000
It will basically have the response, okay, that's it.

96
00:05:55,000 --> 00:05:59,000
And let's go ahead and write this particular response so that we'll be able to see in the page.

97
00:05:59,000 --> 00:05:59,000
Okay.

98
00:06:00,000 --> 00:06:02,000
So this is the same thing.

99
00:06:02,000 --> 00:06:07,000
See if you remember already in my search engine I had actually told you about the same thing.

100
00:06:07,000 --> 00:06:07,000
Right.

101
00:06:07,000 --> 00:06:12,000
So this was the Streamlit callback, the same thing I have copied and pasted over there.

102
00:06:12,000 --> 00:06:14,000
So that is what we are going to use it.

103
00:06:14,000 --> 00:06:17,000
And that is how the entire interaction is going to happen.

104
00:06:17,000 --> 00:06:20,000
So let's go ahead and uh, run this.

105
00:06:20,000 --> 00:06:25,000
So first of all I'll go ahead and write Streamlit run App.py.

106
00:06:25,000 --> 00:06:26,000
Let's go ahead and run it.

107
00:06:27,000 --> 00:06:28,000
I think it will open it.

108
00:06:28,000 --> 00:06:29,000
Okay.

109
00:06:29,000 --> 00:06:30,000
Now, quickly.

110
00:06:30,000 --> 00:06:35,000
First of all, let's go ahead and interact with our SQLite three database student DB.

111
00:06:35,000 --> 00:06:37,000
So for that I really require a grok API.

112
00:06:37,000 --> 00:06:44,000
So I will quickly open this go to my environment variable, use this grok API which I have actually

113
00:06:44,000 --> 00:06:46,000
used it right.

114
00:06:46,000 --> 00:06:49,000
So I will go ahead and paste it over here.

115
00:06:49,000 --> 00:06:50,000
Press enter okay.

116
00:06:50,000 --> 00:06:53,000
So there is an option see clear message history.

117
00:06:53,000 --> 00:06:56,000
If I click on this all the message history will go.

118
00:06:56,000 --> 00:07:03,000
Now I will go ahead and say hey tell me how many records are or show me all the records from the table.

119
00:07:03,000 --> 00:07:08,000
Show me all the records from the table.

120
00:07:09,000 --> 00:07:13,000
Now I think the interaction should start right.

121
00:07:13,000 --> 00:07:16,000
So here you'll be able to see that everything is happening.

122
00:07:16,000 --> 00:07:17,000
Empty string complete.

123
00:07:17,000 --> 00:07:19,000
Select star from table.

124
00:07:19,000 --> 00:07:20,000
Select star from student.

125
00:07:20,000 --> 00:07:22,000
See over here it says.

126
00:07:22,000 --> 00:07:24,000
I did not even say that.

127
00:07:25,000 --> 00:07:27,000
Which table it is students table or not.

128
00:07:27,000 --> 00:07:28,000
Right.

129
00:07:28,000 --> 00:07:33,000
So automatically see over here it's it went and searched for select star from table right.

130
00:07:33,000 --> 00:07:35,000
And it gave us an operational error.

131
00:07:35,000 --> 00:07:39,000
So it again went back and it started seeing form select star from student.

132
00:07:39,000 --> 00:07:40,000
Right.

133
00:07:40,000 --> 00:07:42,000
Then there was a syntax error.

134
00:07:42,000 --> 00:07:46,000
Select start from database dot student name then student right.

135
00:07:46,000 --> 00:07:48,000
Let's continue from where you left off.

136
00:07:48,000 --> 00:07:49,000
Let's look like a query.

137
00:07:49,000 --> 00:07:50,000
I tried to execute the result.

138
00:07:50,000 --> 00:07:53,000
And finally here you can see all the data is basically getting displayed.

139
00:07:53,000 --> 00:07:56,000
So definitely watch this entire interaction.

140
00:07:56,000 --> 00:08:00,000
This is all possible because of the SQL toolkit from long chain.

141
00:08:00,000 --> 00:08:04,000
Long chain is quite powerful with respect to creating all these things.

142
00:08:04,000 --> 00:08:06,000
And that is the reason we basically use this.

143
00:08:06,000 --> 00:08:10,000
If you see in this code what all things, we have actually used it, right.

144
00:08:10,000 --> 00:08:15,000
So here after configuring we are making sure that we add this.

145
00:08:15,000 --> 00:08:18,000
And because of the Streamlit callback handler right.

146
00:08:18,000 --> 00:08:21,000
This is making sure that it is interacting in such a way.

147
00:08:21,000 --> 00:08:26,000
And the features or functionalities of the toolkit is making sure that all the information is basically

148
00:08:26,000 --> 00:08:27,000
getting displayed.

149
00:08:27,000 --> 00:08:27,000
Right.

150
00:08:27,000 --> 00:08:31,000
So if I go back again, let's, uh, see some more thing.

151
00:08:31,000 --> 00:08:32,000
Okay.

152
00:08:33,000 --> 00:08:37,000
Um, display all the records.

153
00:08:38,000 --> 00:08:48,000
from the student table whose marks is greater than 45.

154
00:08:48,000 --> 00:08:48,000
Okay.

155
00:08:49,000 --> 00:08:50,000
Greater than 45.

156
00:08:51,000 --> 00:08:53,000
So I'll just go ahead and press enter.

157
00:08:53,000 --> 00:08:54,000
Let's see how this will work.

158
00:08:54,000 --> 00:08:57,000
Now quickly it is trying to get all the information.

159
00:08:57,000 --> 00:09:00,000
See see see this is beautiful right?

160
00:09:00,000 --> 00:09:01,000
I'm not doing anything.

161
00:09:01,000 --> 00:09:04,000
It's just like 3 to 4 people are working for me.

162
00:09:04,000 --> 00:09:07,000
And finally, you should be definitely able to get the answer.

163
00:09:07,000 --> 00:09:10,000
The final answer is that data science is greater than 45.

164
00:09:10,000 --> 00:09:11,000
And this right.

165
00:09:11,000 --> 00:09:16,000
If you see from the query select star from student where max is greater than 2045, right.

166
00:09:16,000 --> 00:09:19,000
All this specific information is going okay, let let me do one thing.

167
00:09:19,000 --> 00:09:19,000
Okay.

168
00:09:20,000 --> 00:09:29,000
I'll say display all the records whose max is greater than 35 and less than 60.

169
00:09:29,000 --> 00:09:33,000
If I go ahead and write like this, I should also be able to get this right.

170
00:09:34,000 --> 00:09:35,000
So, see?

171
00:09:36,000 --> 00:09:42,000
So automatically the query is basically getting generated which is quite amazing over here right.

172
00:09:43,000 --> 00:09:46,000
And finally you'll be able to see the students thinking thinking thinking right.

173
00:09:46,000 --> 00:09:49,000
This is the thought of chain that is probably happening.

174
00:09:49,000 --> 00:09:52,000
And here I can probably see that I'm actually getting one record.

175
00:09:52,000 --> 00:09:58,000
Okay, now the second one that I you can actually do is connect to my SQL database.

176
00:09:58,000 --> 00:10:01,000
Uh, now see, uh, connecting to my SQL database is very simple.

177
00:10:01,000 --> 00:10:03,000
Uh, let's say that I'll close this connection.

178
00:10:03,000 --> 00:10:03,000
Okay.

179
00:10:04,000 --> 00:10:06,000
You can see there are two connections that I have opened.

180
00:10:06,000 --> 00:10:07,000
So if I double click this right.

181
00:10:07,000 --> 00:10:11,000
So over here you can see localhost 3306.

182
00:10:11,000 --> 00:10:11,000
Right.

183
00:10:11,000 --> 00:10:14,000
And if I go back over here right.

184
00:10:14,000 --> 00:10:18,000
First of all, my SQL host is nothing but that local host, right.

185
00:10:18,000 --> 00:10:19,000
If I go ahead and write this one.

186
00:10:19,000 --> 00:10:19,000
Right.

187
00:10:19,000 --> 00:10:20,000
So this is the same thing.

188
00:10:20,000 --> 00:10:21,000
Right.

189
00:10:21,000 --> 00:10:23,000
And I will just go ahead and remove this.

190
00:10:23,000 --> 00:10:27,000
And along with the port I'll just go ahead and write localhost 3306.

191
00:10:27,000 --> 00:10:28,000
Right.

192
00:10:28,000 --> 00:10:35,000
And over here you'll be able to see that when I use route and use the password 12345, which is the

193
00:10:35,000 --> 00:10:37,000
default one that I've actually set.

194
00:10:37,000 --> 00:10:39,000
You know, while installing it, I'll just say okay, right.

195
00:10:39,000 --> 00:10:41,000
It goes back to this particular page.

196
00:10:41,000 --> 00:10:44,000
Now my SQL user is nothing but root, okay.

197
00:10:44,000 --> 00:10:47,000
My SQL password is 12345.

198
00:10:47,000 --> 00:10:50,000
My SQL database is nothing but student, right?

199
00:10:50,000 --> 00:10:55,000
So once I do this, once I press enter, you'll be able to see that uh, no module named my SQL.

200
00:10:55,000 --> 00:10:59,000
Okay, we really require this my SQL uh, library.

201
00:10:59,000 --> 00:11:01,000
Uh, that is the thing that I did not do it.

202
00:11:01,000 --> 00:11:02,000
So let me do one thing.

203
00:11:02,000 --> 00:11:03,000
Okay.

204
00:11:03,000 --> 00:11:04,000
Let me go back over here.

205
00:11:04,000 --> 00:11:08,000
Go to requirement dot txt and I need to import two important libraries.

206
00:11:08,000 --> 00:11:14,000
One is SQL alchemy and my sequel connector Python.

207
00:11:14,000 --> 00:11:16,000
And that is what we basically require right.

208
00:11:16,000 --> 00:11:21,000
So let me just go ahead and write uh or create another command prompt.

209
00:11:21,000 --> 00:11:21,000
Okay.

210
00:11:21,000 --> 00:11:29,000
So now I will go ahead and install pip install minus r requirements.txt SQLite is working fine, but

211
00:11:29,000 --> 00:11:31,000
this is giving us some error.

212
00:11:31,000 --> 00:11:34,000
Let's see why it is giving some error because of this package.

213
00:11:34,000 --> 00:11:38,000
And now once this package gets installed, I think it should be fine to run it right.

214
00:11:38,000 --> 00:11:40,000
So now let's go ahead and run this.

215
00:11:42,000 --> 00:11:48,000
I will go back to my command prompt over here and let's run this okay.

216
00:11:48,000 --> 00:11:50,000
Now here you can see I will close this one.

217
00:11:50,000 --> 00:11:51,000
I'll close this one okay.

218
00:11:51,000 --> 00:11:53,000
So I will connect it to my database.

219
00:11:53,000 --> 00:11:57,000
So first of all I require this entire information from env.

220
00:11:57,000 --> 00:12:02,000
I will go ahead and take my grok API key and go back to my.

221
00:12:02,000 --> 00:12:03,000
So.

222
00:12:04,000 --> 00:12:07,000
So first of all I will go ahead and write my localhost.

223
00:12:07,000 --> 00:12:11,000
And this is my localhost or sequel host that I want.

224
00:12:11,000 --> 00:12:14,000
My sequel user is nothing but root.

225
00:12:14,000 --> 00:12:21,000
My password is 12345 And my database is nothing but student and grok API is this one.

226
00:12:21,000 --> 00:12:23,000
I'll go ahead and press enter.

227
00:12:23,000 --> 00:12:24,000
This looks fine.

228
00:12:24,000 --> 00:12:31,000
Display all the records from student table.

229
00:12:31,000 --> 00:12:34,000
Okay I'll just go ahead and write this.

230
00:12:35,000 --> 00:12:38,000
So automatically select star from student.

231
00:12:38,000 --> 00:12:41,000
Everything is happening thinking thinking right.

232
00:12:41,000 --> 00:12:44,000
And here you can see all the results is basically getting displayed.

233
00:12:44,000 --> 00:12:47,000
So this is how you can probably go ahead and create it.

234
00:12:47,000 --> 00:12:52,000
And this will just not support the simple queries, more complicated queries in our loops, in our in

235
00:12:52,000 --> 00:12:53,000
our nested functions and all.

236
00:12:54,000 --> 00:12:57,000
Uh, in a nested queries you can definitely go ahead and try it out.

237
00:12:57,000 --> 00:13:00,000
Okay, so I hope you like this particular video.

238
00:13:01,000 --> 00:13:02,000
Uh, this was it for my side.

239
00:13:02,000 --> 00:13:05,000
Uh, I will see you all in the next video.

240
00:13:05,000 --> 00:13:05,000
Thank you.

241
00:13:05,000 --> 00:13:06,000
Have a great day.

242
00:13:06,000 --> 00:13:07,000
Bye bye.

