So guys, we will be continuing with respect to our end to end project.
Already we have developed all these things where we have configured our LLM.
We have configured our entire database, uh, which database to connect when.
Now let's go ahead and run this.
You know, I also want to probably check whether this is running fine or not.
So I will go ahead and write Streamlit run App.py just to verify.
Is everything fine.
So here you can actually see my page getting loaded.
So here you can see both the options are over here right to select this.
And if I select I'm able to see all my other details.
And it is asking for grok API key.
So that is what I am going to provide.
Uh oh I have already provided a field over here.
Now, uh, as soon as I put the information I am able to configure that part.
Also, I have actually done it.
Now, the thing is that I need to probably create a text box this side and whenever I fill up all this
information, I should be able to interact with my database.
So that is what is basically remaining.
And for this we really need to work with something called as toolkit.
Okay.
So that is what we are going to design in this particular video okay.
So let's go ahead and let's quickly start working on this.
So first of all I will go ahead and create my toolkit.
And this will be nothing.
But it will be a SQL database toolkit.
I'll use my DB is equal to db whatever db I have.
Actually, uh, I'm getting from configuring it.
So once I call this particular function, I'll be able to get the DB and my LM model, which I'm going
to assign with my chart grok API.
Right.
So this is done.
Now what I'm actually going to do quickly go ahead and create my agent.
And here I'm going to use my create SQL agent okay.
Now inside this I have to probably pass my LM model which will be required for creating my SQL agent.
Along with this, I will go ahead and provide my toolkit details what toolkit I really want.
I'll also make sure that to keep this parameter verbose is equal to true, because I really want to
see all the interaction and each and everything.
And finally we will go ahead and set up our agent type.
The agent type will be nothing but this same agent type.
And this I will also go ahead and use zero shot react description, which I've already told in my previous
video itself in the previous project that we have developed.
Okay, now, uh, quickly, uh, what I will do is that I will go ahead and make my session state like
how we did it, because we also need to maintain our chat history.
So here you can see if message not in session state dot uh session underscore state or state or sidebar
button, clear message history.
I also will have a specific button.
If I clear clear click on that it will remove the entire history.
Okay.
So here you'll be able to see that SD dot session underscore state of message.
I'm first of all adding this role and assistant.
And I can say just how can I help you in the content okay.
So this is the default message.
Now what I'm actually going to do is that for every session message right.
I have to make sure that I have to integrate this, like how we did it in a previous project.
So I will just go ahead and copy paste over here.
So for message in St dot session underscore state dot messages, I'm saying I'm appending everything
inside this chat underscore message so that it has all the information.
So finally I will go ahead and create my user underscore query.
And here I will go ahead and write st dot chat underscore input.
Okay.
So let me just go ahead and write chat underscore input.
And inside this I will go ahead and put a placeholder and ask anything from the database okay.
So I'm going to put this entire information over here.
If I go ahead and put my user query okay.
The next thing what I really need to do is that I need to append my session state with that specific
message from the user, right?
So for that, what I will do, I will quickly go ahead and add like this HD dot session underscore state
dot messages dot append where I'm going to give the role as user and content whatever user query is
basically getting added right along with this, what I will say is that I will also make sure I to add
it over here in SD dot chat message.
So SD dot chat message of user dot write user query.
So we are going to write it over there with respect to the uh whatever the user query is there in the
screen.
Okay.
Now we will go ahead and write further st dot chat underscore message.
And here we are specifically going to use assistant okay.
And again in this I will go ahead and create my callback okay.
So I will write Streamlit underscore callback is equal to Streamlit callback handler.
And here I'm going to write s t dot container.
Once I write this this will be the callback which will be responsible in showing what are the chain
of thoughts you know.
And that will also be getting displayed.
Finally I'm going to go ahead and create my response where I will be saying, agent Dot, we will be
running this entire thing by taking the user query.
Along with that, I'm also going to give my callbacks, which will be nothing, but it will be the same
Streamlit callback which we are using.
Okay.
And finally, what I will do is that after this, let's see, I will just close it over here itself
And here in the next message I will go ahead and write SD dot session underscore state dot messages.
We need to append once we get the specific response.
So that is the reason we are going to write dot append.
And here again we are going to use a role since it is probably coming from the assistant itself.
So I will be giving the role as assistant assistant.
And finally you'll also be seeing that I will be giving my content inside this content.
It will basically have the response, okay, that's it.
And let's go ahead and write this particular response so that we'll be able to see in the page.
Okay.
So this is the same thing.
See if you remember already in my search engine I had actually told you about the same thing.
Right.
So this was the Streamlit callback, the same thing I have copied and pasted over there.
So that is what we are going to use it.
And that is how the entire interaction is going to happen.
So let's go ahead and uh, run this.
So first of all I'll go ahead and write Streamlit run App.py.
Let's go ahead and run it.
I think it will open it.
Okay.
Now, quickly.
First of all, let's go ahead and interact with our SQLite three database student DB.
So for that I really require a grok API.
So I will quickly open this go to my environment variable, use this grok API which I have actually
used it right.
So I will go ahead and paste it over here.
Press enter okay.
So there is an option see clear message history.
If I click on this all the message history will go.
Now I will go ahead and say hey tell me how many records are or show me all the records from the table.
Show me all the records from the table.
Now I think the interaction should start right.
So here you'll be able to see that everything is happening.
Empty string complete.
Select star from table.
Select star from student.
See over here it says.
I did not even say that.
Which table it is students table or not.
Right.
So automatically see over here it's it went and searched for select star from table right.
And it gave us an operational error.
So it again went back and it started seeing form select star from student.
Right.
Then there was a syntax error.
Select start from database dot student name then student right.
Let's continue from where you left off.
Let's look like a query.
I tried to execute the result.
And finally here you can see all the data is basically getting displayed.
So definitely watch this entire interaction.
This is all possible because of the SQL toolkit from long chain.
Long chain is quite powerful with respect to creating all these things.
And that is the reason we basically use this.
If you see in this code what all things, we have actually used it, right.
So here after configuring we are making sure that we add this.
And because of the Streamlit callback handler right.
This is making sure that it is interacting in such a way.
And the features or functionalities of the toolkit is making sure that all the information is basically
getting displayed.
Right.
So if I go back again, let's, uh, see some more thing.
Okay.
Um, display all the records.
from the student table whose marks is greater than 45.
Okay.
Greater than 45.
So I'll just go ahead and press enter.
Let's see how this will work.
Now quickly it is trying to get all the information.
See see see this is beautiful right?
I'm not doing anything.
It's just like 3 to 4 people are working for me.
And finally, you should be definitely able to get the answer.
The final answer is that data science is greater than 45.
And this right.
If you see from the query select star from student where max is greater than 2045, right.
All this specific information is going okay, let let me do one thing.
Okay.
I'll say display all the records whose max is greater than 35 and less than 60.
If I go ahead and write like this, I should also be able to get this right.
So, see?
So automatically the query is basically getting generated which is quite amazing over here right.
And finally you'll be able to see the students thinking thinking thinking right.
This is the thought of chain that is probably happening.
And here I can probably see that I'm actually getting one record.
Okay, now the second one that I you can actually do is connect to my SQL database.
Uh, now see, uh, connecting to my SQL database is very simple.
Uh, let's say that I'll close this connection.
Okay.
You can see there are two connections that I have opened.
So if I double click this right.
So over here you can see localhost 3306.
Right.
And if I go back over here right.
First of all, my SQL host is nothing but that local host, right.
If I go ahead and write this one.
Right.
So this is the same thing.
Right.
And I will just go ahead and remove this.
And along with the port I'll just go ahead and write localhost 3306.
Right.
And over here you'll be able to see that when I use route and use the password 12345, which is the
default one that I've actually set.
You know, while installing it, I'll just say okay, right.
It goes back to this particular page.
Now my SQL user is nothing but root, okay.
My SQL password is 12345.
My SQL database is nothing but student, right?
So once I do this, once I press enter, you'll be able to see that uh, no module named my SQL.
Okay, we really require this my SQL uh, library.
Uh, that is the thing that I did not do it.
So let me do one thing.
Okay.
Let me go back over here.
Go to requirement dot txt and I need to import two important libraries.
One is SQL alchemy and my sequel connector Python.
And that is what we basically require right.
So let me just go ahead and write uh or create another command prompt.
Okay.
So now I will go ahead and install pip install minus r requirements.txt SQLite is working fine, but
this is giving us some error.
Let's see why it is giving some error because of this package.
And now once this package gets installed, I think it should be fine to run it right.
So now let's go ahead and run this.
I will go back to my command prompt over here and let's run this okay.
Now here you can see I will close this one.
I'll close this one okay.
So I will connect it to my database.
So first of all I require this entire information from env.
I will go ahead and take my grok API key and go back to my.
So.
So first of all I will go ahead and write my localhost.
And this is my localhost or sequel host that I want.
My sequel user is nothing but root.
My password is 12345 And my database is nothing but student and grok API is this one.
I'll go ahead and press enter.
This looks fine.
Display all the records from student table.
Okay I'll just go ahead and write this.
So automatically select star from student.
Everything is happening thinking thinking right.
And here you can see all the results is basically getting displayed.
So this is how you can probably go ahead and create it.
And this will just not support the simple queries, more complicated queries in our loops, in our in
our nested functions and all.
Uh, in a nested queries you can definitely go ahead and try it out.
Okay, so I hope you like this particular video.
Uh, this was it for my side.
Uh, I will see you all in the next video.
Thank you.
Have a great day.
Bye bye.