Hello guys.
So we are going to continue the discussion with respect to gravity with Liang Chen.
Already in our previous video, we have seen how to insert this specific data right now.
Let's go ahead and see that how we can play with our LM model.
So first of all, uh, again in this we are going to use uh grok API.
So first of all I will go ahead and write import OS.
And along with this I will also say from dot env import load underscore dot env.
And we will go ahead and initialize this.
Now quickly I will go ahead and write grok underscore API.
And let me go ahead and use get OS dot get env with respect to our grok underscore API underscore key.
Now uh once I get this grok API key.
Okay.
So grok API key over here I will let me let me just create this variable as grok API key.
Now we will just go ahead and import because we need to load our model right.
LM models.
So I'll say hey from lang chain underscore grok import chat grok.
Okay.
Now let's go ahead and create my LM model.
And here I'm just going to go ahead and write chat grok.
And first my I have to initialize my grok API key itself.
Is equal to grok API key.
And then my model underscore name is equal to gamma.
Let's say I will uh grok API key.
Why this is highlighted in this way.
It's okay.
We'll run learn run this okay.
So nine b and I'm just going to use this specific model, the gamma two model which is the new model
over there.
Right.
And once I initialize this uh, this will basically be my LM model.
So yeah.
Uh, my entire LM model is ready.
It has this it is using this model called as gamma two, which is an open source model with this particular
secret key.
Okay.
Perfect.
Till here.
Everything looks good.
Now it's time that, uh, you know, see what?
What our plan was.
Our plan was like.
Whenever user probably writes a query, it should probably go to the LM model.
This LM model should create my Cypher query.
And further, by using the Cypher query, I should be able to query from my graph database and get the
output.
And along with the output, I should be able to get the back the response.
Okay, this entire thing is I really want to create.
Now for this.
What I will do, I will quickly go ahead and first of all create a chain.
So I will say hey, from line chain dot chains I'm going to import graph graph queue and a chain graph
cypher queue a chain.
Right.
So I will just go ahead and use this cypher queue chain which will actually help us to work with this.
Okay.
Then inside this chain I'm going to give or I'm going to initialize this graph cipher chain.
And here we really need to pass some information.
And there is a function which is called as from lm okay.
Now when you are using this graph cipher key chain, the first parameter that we need to pass is our
graph.
Right.
So graph obviously this information is over here.
This is my graph right with respect to this entire schema.
And because I need to query this graph itself right.
Then I have my LM model.
Okay.
LM model.
Then finally I will also go ahead and write.
Verbose is equal to true, so that I will be able to see that how the conversation is basically happening.
Okay.
So uh, this in short, is about the chain.
Now if I go ahead and display the chain.
So here you will be able to see this particular chain.
Right.
So uh, prompt template over here by default you can see right this graph Cypher Q and a chain I do
not have to separately specify my prompt template because if you go forward right there is a prompt
template.
It is internally using this LM chain.
And here you can see prompt template is the input variable is question and schema I need to pass question
and schema schema is getting passed through this particular graph.
Right.
And then uh the task is nothing but generate Cypher statement to query a graph database, right?
Use only the provided relationship types and properties in the schema.
Do not use any other relationship type or properties that are.
So this is the default uh uh, prompt that is created with this cypher Q and a chain.
Right.
So this work has already been done by Lang chain itself.
Now I will just go ahead and write.
Response is equal to.
and use this chain and we will go ahead and invoke.
Now once we are invoking over here.
Right.
I will just go ahead and write query and let me give the query over here.
I'll say what was the Or I'll say who was the director director of the movie.
Of the movie casino.
Okay, so this is what I really want to check.
Now let's go ahead and see the response.
So once I execute it okay I'm getting an error response.
Let's see.
So over here it shows who is the director of the movie casino Martin Scorsese okay.
So I hope this is absolutely right.
So let's see.
First of all, I'll go ahead and click on movies.
So I will say hey n is equal to movie colon or movie is equal to I will go ahead and write casino.
Or movie colon.
It should be a but let's see.
Uh, this query is wrong.
Let me just see this.
Okay.
So acted in somewhere.
Casino.
Oh, let me just directly see from this.
So if I go ahead and write.
So here you can see this information right Martin Scorsese okay.
So this is the director specifically for the casino movie.
Okay.
And if you say again, I don't want to become a proficient in probably seeing how this or learning this
particular queries.
Okay.
But I would definitely be seeing that.
Okay.
Is my LM model able to generate the query and is am I able to get the answer?
The answer is very much simply yes.
Right.
So uh, this is the query that has got created.
Okay.
Here I have the answer.
Okay.
I don't even have to probably work on this.
So let's execute this.
So here you have this.
And here is the answer right Martin Scorsese okay.
So my entire query has been generated.
So this was what I had to write okay I forgot it.
Right.
So I need to write title Colon Casino.
I need to use this property keys.
And I am writing directed with respect to p dot person.
And we are returning the name.
Okay.
So yeah, uh, this was a very simple way of basically executing this.
Okay.
Um, let's ask some more question.
I will go ahead and say, hey, uh, what was the entire cast?
I will just go ahead and ask this question.
Okay.
All right.
What was the entire or who were the actors?
Actors.
Okay.
So let's response.
This robot, Robert De Niro, Joe Pesci, Sharon Stone, James Hood.
Right.
And this is the query that has got created.
And here you can see full context.
Also it is able to generate right with all the information that you have and you are able to see this,
right.
This this looks really, really good.
And uh, just by using some line of code, you know, we were able to create all these amazing things,
right?
And, uh, we are also able to probably see the entire schema along with this.
We are also able to query it.
Right.
So whatever the queries that we have specifically used, this we are using with the help of uh, chain
itself, uh, Cypher query, uh graph, Cypher queue and chain.
Okay.
And uh, by just this seeing that, you can see how powerful this is.
Right.
So I hope you like this particular video.
Uh, this was it for my side.
Uh, go ahead and try it out and just try to see whether you are able to get the queries or not, okay?
Yes, this was it for my side.
I will see you all in the next video.
Thank you.