1
00:00:00,000 --> 00:00:01,000
Hello guys.

2
00:00:01,000 --> 00:00:04,000
So we are going to continue the discussion with respect to gravity with Liang Chen.

3
00:00:04,000 --> 00:00:09,000
Already in our previous video, we have seen how to insert this specific data right now.

4
00:00:09,000 --> 00:00:12,000
Let's go ahead and see that how we can play with our LM model.

5
00:00:12,000 --> 00:00:17,000
So first of all, uh, again in this we are going to use uh grok API.

6
00:00:17,000 --> 00:00:20,000
So first of all I will go ahead and write import OS.

7
00:00:21,000 --> 00:00:28,000
And along with this I will also say from dot env import load underscore dot env.

8
00:00:28,000 --> 00:00:31,000
And we will go ahead and initialize this.

9
00:00:32,000 --> 00:00:35,000
Now quickly I will go ahead and write grok underscore API.

10
00:00:35,000 --> 00:00:44,000
And let me go ahead and use get OS dot get env with respect to our grok underscore API underscore key.

11
00:00:46,000 --> 00:00:50,000
Now uh once I get this grok API key.

12
00:00:50,000 --> 00:00:50,000
Okay.

13
00:00:50,000 --> 00:00:55,000
So grok API key over here I will let me let me just create this variable as grok API key.

14
00:00:57,000 --> 00:01:02,000
Now we will just go ahead and import because we need to load our model right.

15
00:01:02,000 --> 00:01:03,000
LM models.

16
00:01:03,000 --> 00:01:10,000
So I'll say hey from lang chain underscore grok import chat grok.

17
00:01:10,000 --> 00:01:10,000
Okay.

18
00:01:11,000 --> 00:01:14,000
Now let's go ahead and create my LM model.

19
00:01:14,000 --> 00:01:16,000
And here I'm just going to go ahead and write chat grok.

20
00:01:17,000 --> 00:01:22,000
And first my I have to initialize my grok API key itself.

21
00:01:25,000 --> 00:01:27,000
Is equal to grok API key.

22
00:01:28,000 --> 00:01:35,000
And then my model underscore name is equal to gamma.

23
00:01:35,000 --> 00:01:38,000
Let's say I will uh grok API key.

24
00:01:38,000 --> 00:01:40,000
Why this is highlighted in this way.

25
00:01:40,000 --> 00:01:41,000
It's okay.

26
00:01:41,000 --> 00:01:43,000
We'll run learn run this okay.

27
00:01:43,000 --> 00:01:48,000
So nine b and I'm just going to use this specific model, the gamma two model which is the new model

28
00:01:48,000 --> 00:01:48,000
over there.

29
00:01:48,000 --> 00:01:49,000
Right.

30
00:01:49,000 --> 00:01:54,000
And once I initialize this uh, this will basically be my LM model.

31
00:01:54,000 --> 00:01:55,000
So yeah.

32
00:01:55,000 --> 00:01:58,000
Uh, my entire LM model is ready.

33
00:01:59,000 --> 00:02:04,000
It has this it is using this model called as gamma two, which is an open source model with this particular

34
00:02:04,000 --> 00:02:04,000
secret key.

35
00:02:04,000 --> 00:02:05,000
Okay.

36
00:02:05,000 --> 00:02:06,000
Perfect.

37
00:02:06,000 --> 00:02:06,000
Till here.

38
00:02:06,000 --> 00:02:08,000
Everything looks good.

39
00:02:08,000 --> 00:02:12,000
Now it's time that, uh, you know, see what?

40
00:02:12,000 --> 00:02:14,000
What our plan was.

41
00:02:14,000 --> 00:02:15,000
Our plan was like.

42
00:02:15,000 --> 00:02:19,000
Whenever user probably writes a query, it should probably go to the LM model.

43
00:02:19,000 --> 00:02:21,000
This LM model should create my Cypher query.

44
00:02:21,000 --> 00:02:27,000
And further, by using the Cypher query, I should be able to query from my graph database and get the

45
00:02:27,000 --> 00:02:28,000
output.

46
00:02:28,000 --> 00:02:30,000
And along with the output, I should be able to get the back the response.

47
00:02:30,000 --> 00:02:33,000
Okay, this entire thing is I really want to create.

48
00:02:33,000 --> 00:02:34,000
Now for this.

49
00:02:34,000 --> 00:02:38,000
What I will do, I will quickly go ahead and first of all create a chain.

50
00:02:38,000 --> 00:02:49,000
So I will say hey, from line chain dot chains I'm going to import graph graph queue and a chain graph

51
00:02:49,000 --> 00:02:50,000
cypher queue a chain.

52
00:02:50,000 --> 00:02:50,000
Right.

53
00:02:50,000 --> 00:02:55,000
So I will just go ahead and use this cypher queue chain which will actually help us to work with this.

54
00:02:55,000 --> 00:02:55,000
Okay.

55
00:02:55,000 --> 00:03:01,000
Then inside this chain I'm going to give or I'm going to initialize this graph cipher chain.

56
00:03:01,000 --> 00:03:04,000
And here we really need to pass some information.

57
00:03:04,000 --> 00:03:06,000
And there is a function which is called as from lm okay.

58
00:03:07,000 --> 00:03:13,000
Now when you are using this graph cipher key chain, the first parameter that we need to pass is our

59
00:03:13,000 --> 00:03:13,000
graph.

60
00:03:14,000 --> 00:03:14,000
Right.

61
00:03:14,000 --> 00:03:16,000
So graph obviously this information is over here.

62
00:03:17,000 --> 00:03:20,000
This is my graph right with respect to this entire schema.

63
00:03:20,000 --> 00:03:23,000
And because I need to query this graph itself right.

64
00:03:23,000 --> 00:03:26,000
Then I have my LM model.

65
00:03:26,000 --> 00:03:26,000
Okay.

66
00:03:28,000 --> 00:03:28,000
LM model.

67
00:03:28,000 --> 00:03:30,000
Then finally I will also go ahead and write.

68
00:03:30,000 --> 00:03:36,000
Verbose is equal to true, so that I will be able to see that how the conversation is basically happening.

69
00:03:36,000 --> 00:03:36,000
Okay.

70
00:03:36,000 --> 00:03:40,000
So uh, this in short, is about the chain.

71
00:03:40,000 --> 00:03:42,000
Now if I go ahead and display the chain.

72
00:03:42,000 --> 00:03:44,000
So here you will be able to see this particular chain.

73
00:03:44,000 --> 00:03:44,000
Right.

74
00:03:45,000 --> 00:03:52,000
So uh, prompt template over here by default you can see right this graph Cypher Q and a chain I do

75
00:03:52,000 --> 00:03:56,000
not have to separately specify my prompt template because if you go forward right there is a prompt

76
00:03:56,000 --> 00:03:57,000
template.

77
00:03:57,000 --> 00:03:59,000
It is internally using this LM chain.

78
00:03:59,000 --> 00:04:04,000
And here you can see prompt template is the input variable is question and schema I need to pass question

79
00:04:04,000 --> 00:04:07,000
and schema schema is getting passed through this particular graph.

80
00:04:07,000 --> 00:04:07,000
Right.

81
00:04:08,000 --> 00:04:14,000
And then uh the task is nothing but generate Cypher statement to query a graph database, right?

82
00:04:14,000 --> 00:04:19,000
Use only the provided relationship types and properties in the schema.

83
00:04:19,000 --> 00:04:22,000
Do not use any other relationship type or properties that are.

84
00:04:22,000 --> 00:04:28,000
So this is the default uh uh, prompt that is created with this cypher Q and a chain.

85
00:04:28,000 --> 00:04:28,000
Right.

86
00:04:28,000 --> 00:04:31,000
So this work has already been done by Lang chain itself.

87
00:04:31,000 --> 00:04:33,000
Now I will just go ahead and write.

88
00:04:33,000 --> 00:04:34,000
Response is equal to.

89
00:04:35,000 --> 00:04:39,000
and use this chain and we will go ahead and invoke.

90
00:04:39,000 --> 00:04:41,000
Now once we are invoking over here.

91
00:04:41,000 --> 00:04:41,000
Right.

92
00:04:41,000 --> 00:04:46,000
I will just go ahead and write query and let me give the query over here.

93
00:04:46,000 --> 00:04:58,000
I'll say what was the Or I'll say who was the director director of the movie.

94
00:05:00,000 --> 00:05:01,000
Of the movie casino.

95
00:05:02,000 --> 00:05:04,000
Okay, so this is what I really want to check.

96
00:05:04,000 --> 00:05:06,000
Now let's go ahead and see the response.

97
00:05:06,000 --> 00:05:13,000
So once I execute it okay I'm getting an error response.

98
00:05:15,000 --> 00:05:16,000
Let's see.

99
00:05:16,000 --> 00:05:22,000
So over here it shows who is the director of the movie casino Martin Scorsese okay.

100
00:05:22,000 --> 00:05:25,000
So I hope this is absolutely right.

101
00:05:25,000 --> 00:05:27,000
So let's see.

102
00:05:27,000 --> 00:05:29,000
First of all, I'll go ahead and click on movies.

103
00:05:30,000 --> 00:05:41,000
So I will say hey n is equal to movie colon or movie is equal to I will go ahead and write casino.

104
00:05:45,000 --> 00:05:48,000
Or movie colon.

105
00:05:48,000 --> 00:05:50,000
It should be a but let's see.

106
00:05:51,000 --> 00:05:53,000
Uh, this query is wrong.

107
00:05:53,000 --> 00:05:54,000
Let me just see this.

108
00:05:54,000 --> 00:05:55,000
Okay.

109
00:05:55,000 --> 00:06:00,000
So acted in somewhere.

110
00:06:00,000 --> 00:06:01,000
Casino.

111
00:06:01,000 --> 00:06:01,000
Casino.

112
00:06:01,000 --> 00:06:01,000
Casino.

113
00:06:01,000 --> 00:06:02,000
Casino.

114
00:06:02,000 --> 00:06:03,000
Casino.

115
00:06:06,000 --> 00:06:07,000
Casino.

116
00:06:07,000 --> 00:06:08,000
Casino.

117
00:06:08,000 --> 00:06:10,000
Oh, let me just directly see from this.

118
00:06:11,000 --> 00:06:12,000
So if I go ahead and write.

119
00:06:12,000 --> 00:06:18,000
So here you can see this information right Martin Scorsese okay.

120
00:06:18,000 --> 00:06:22,000
So this is the director specifically for the casino movie.

121
00:06:22,000 --> 00:06:23,000
Okay.

122
00:06:23,000 --> 00:06:31,000
And if you say again, I don't want to become a proficient in probably seeing how this or learning this

123
00:06:31,000 --> 00:06:31,000
particular queries.

124
00:06:31,000 --> 00:06:32,000
Okay.

125
00:06:32,000 --> 00:06:33,000
But I would definitely be seeing that.

126
00:06:33,000 --> 00:06:34,000
Okay.

127
00:06:34,000 --> 00:06:38,000
Is my LM model able to generate the query and is am I able to get the answer?

128
00:06:38,000 --> 00:06:40,000
The answer is very much simply yes.

129
00:06:40,000 --> 00:06:40,000
Right.

130
00:06:41,000 --> 00:06:43,000
So uh, this is the query that has got created.

131
00:06:43,000 --> 00:06:44,000
Okay.

132
00:06:44,000 --> 00:06:45,000
Here I have the answer.

133
00:06:45,000 --> 00:06:46,000
Okay.

134
00:06:46,000 --> 00:06:48,000
I don't even have to probably work on this.

135
00:06:48,000 --> 00:06:50,000
So let's execute this.

136
00:06:50,000 --> 00:06:51,000
So here you have this.

137
00:06:52,000 --> 00:06:56,000
And here is the answer right Martin Scorsese okay.

138
00:06:56,000 --> 00:06:58,000
So my entire query has been generated.

139
00:06:58,000 --> 00:07:01,000
So this was what I had to write okay I forgot it.

140
00:07:01,000 --> 00:07:01,000
Right.

141
00:07:01,000 --> 00:07:04,000
So I need to write title Colon Casino.

142
00:07:04,000 --> 00:07:05,000
I need to use this property keys.

143
00:07:05,000 --> 00:07:08,000
And I am writing directed with respect to p dot person.

144
00:07:08,000 --> 00:07:09,000
And we are returning the name.

145
00:07:09,000 --> 00:07:10,000
Okay.

146
00:07:10,000 --> 00:07:15,000
So yeah, uh, this was a very simple way of basically executing this.

147
00:07:15,000 --> 00:07:15,000
Okay.

148
00:07:16,000 --> 00:07:18,000
Um, let's ask some more question.

149
00:07:18,000 --> 00:07:25,000
I will go ahead and say, hey, uh, what was the entire cast?

150
00:07:25,000 --> 00:07:27,000
I will just go ahead and ask this question.

151
00:07:27,000 --> 00:07:28,000
Okay.

152
00:07:28,000 --> 00:07:29,000
All right.

153
00:07:29,000 --> 00:07:35,000
What was the entire or who were the actors?

154
00:07:37,000 --> 00:07:38,000
Actors.

155
00:07:38,000 --> 00:07:38,000
Okay.

156
00:07:38,000 --> 00:07:39,000
So let's response.

157
00:07:39,000 --> 00:07:44,000
This robot, Robert De Niro, Joe Pesci, Sharon Stone, James Hood.

158
00:07:44,000 --> 00:07:45,000
Right.

159
00:07:45,000 --> 00:07:48,000
And this is the query that has got created.

160
00:07:48,000 --> 00:07:49,000
And here you can see full context.

161
00:07:49,000 --> 00:07:54,000
Also it is able to generate right with all the information that you have and you are able to see this,

162
00:07:54,000 --> 00:07:55,000
right.

163
00:07:55,000 --> 00:07:58,000
This this looks really, really good.

164
00:07:58,000 --> 00:08:05,000
And uh, just by using some line of code, you know, we were able to create all these amazing things,

165
00:08:05,000 --> 00:08:06,000
right?

166
00:08:06,000 --> 00:08:11,000
And, uh, we are also able to probably see the entire schema along with this.

167
00:08:11,000 --> 00:08:12,000
We are also able to query it.

168
00:08:12,000 --> 00:08:13,000
Right.

169
00:08:13,000 --> 00:08:19,000
So whatever the queries that we have specifically used, this we are using with the help of uh, chain

170
00:08:19,000 --> 00:08:22,000
itself, uh, Cypher query, uh graph, Cypher queue and chain.

171
00:08:22,000 --> 00:08:23,000
Okay.

172
00:08:23,000 --> 00:08:27,000
And uh, by just this seeing that, you can see how powerful this is.

173
00:08:27,000 --> 00:08:28,000
Right.

174
00:08:28,000 --> 00:08:31,000
So I hope you like this particular video.

175
00:08:31,000 --> 00:08:33,000
Uh, this was it for my side.

176
00:08:33,000 --> 00:08:37,000
Uh, go ahead and try it out and just try to see whether you are able to get the queries or not, okay?

177
00:08:38,000 --> 00:08:39,000
Yes, this was it for my side.

178
00:08:39,000 --> 00:08:40,000
I will see you all in the next video.

179
00:08:40,000 --> 00:08:40,000
Thank you.

