1
00:00:00,000 --> 00:00:03,000
So guys the requirement dot txt has now been installed.

2
00:00:03,000 --> 00:00:06,000
Uh, now in this video we are going to develop our Streamlit web app.

3
00:00:06,000 --> 00:00:09,000
And then we will develop our entire application.

4
00:00:09,000 --> 00:00:12,000
So let me quickly close all these things and let me start okay.

5
00:00:13,000 --> 00:00:17,000
So here uh, the first of all, what I'm actually going to do is that I'm going to import, uh, some

6
00:00:17,000 --> 00:00:20,000
of the libraries like import Streamlit.

7
00:00:20,000 --> 00:00:21,000
Okay.

8
00:00:21,000 --> 00:00:29,000
As s t uh, over here and here you can also see my conda environment is there perfect Perfect.

9
00:00:29,000 --> 00:00:31,000
Import Streamlit as st.

10
00:00:31,000 --> 00:00:34,000
Along with that we will also go ahead and import OpenAI.

11
00:00:34,000 --> 00:00:41,000
And then from lang chain underscore OpenAI I see since we are working with OpenAI in the first project,

12
00:00:41,000 --> 00:00:43,000
in the upcoming project we'll discuss with Olimar.

13
00:00:43,000 --> 00:00:43,000
Right.

14
00:00:43,000 --> 00:00:48,000
So right now, if you really want to work with OpenAI along with Lang Chain integration, and I feel

15
00:00:48,000 --> 00:00:53,000
everybody should start working in Lang chain, don't work independently with different different libraries,

16
00:00:53,000 --> 00:00:58,000
because Lang Chain is a framework which is created in such a way that it can interact with OpenAI APIs,

17
00:00:58,000 --> 00:01:01,000
it can interact with open source LLM models, it can interact with Huggingface.

18
00:01:01,000 --> 00:01:02,000
Right.

19
00:01:02,000 --> 00:01:04,000
All these things will specifically be included.

20
00:01:04,000 --> 00:01:09,000
So here I'm going to quickly go ahead and import chat OpenAI okay.

21
00:01:10,000 --> 00:01:19,000
And then along with this I will also go ahead and write lang chain underscore core dot output parser.

22
00:01:21,000 --> 00:01:30,000
Import str output str output parser.

23
00:01:31,000 --> 00:01:32,000
Okay.

24
00:01:32,000 --> 00:01:33,000
Then.

25
00:01:33,000 --> 00:01:45,000
Uh from lang chain underscore core dot prompts I'm going to import chat prompt template.

26
00:01:45,000 --> 00:01:50,000
Okay, so all these libraries will be the basic requirement that we really need to have.

27
00:01:50,000 --> 00:01:52,000
Then I will go ahead and import OS.

28
00:01:52,000 --> 00:01:59,000
And then from dot env I'm going to import load underscore dot env.

29
00:02:00,000 --> 00:02:02,000
This is just to load all the environment variable.

30
00:02:02,000 --> 00:02:07,000
We will go ahead and initialize this load underscore dot env okay.

31
00:02:07,000 --> 00:02:10,000
Just to check everything is working fine.

32
00:02:10,000 --> 00:02:15,000
What I will do I'll just go ahead inside this particular project folder I'll go ahead and write Streamlit

33
00:02:15,000 --> 00:02:18,000
run uh app.py.

34
00:02:18,000 --> 00:02:21,000
And here I'll go ahead and execute it okay.

35
00:02:21,000 --> 00:02:23,000
So this works absolutely fine.

36
00:02:23,000 --> 00:02:25,000
Here you can actually see this right.

37
00:02:26,000 --> 00:02:28,000
So everything is working fine.

38
00:02:28,000 --> 00:02:32,000
Nothing is getting displayed, I know that, but till here, everything looks good.

39
00:02:32,000 --> 00:02:35,000
Okay, so I will just press Ctrl c.

40
00:02:35,000 --> 00:02:35,000
Perfect.

41
00:02:36,000 --> 00:02:39,000
Now, now next step.

42
00:02:39,000 --> 00:02:48,000
Uh, what we are really going to do is that we are going to implement our language tracking Lamb-smith

43
00:02:49,000 --> 00:02:50,000
tracking.

44
00:02:50,000 --> 00:02:50,000
Okay.

45
00:02:50,000 --> 00:02:55,000
Now, inside this lamb-smith tracking, uh, I will quickly go ahead and write OS dot environ.

46
00:02:56,000 --> 00:03:00,000
And I will just go ahead and call the environment variable.

47
00:03:00,000 --> 00:03:03,000
That is nothing but lang chain API key.

48
00:03:05,000 --> 00:03:08,000
So quickly let's go ahead and write this lang chain API key.

49
00:03:08,000 --> 00:03:12,000
And let me go ahead and write GA uh os dot get env.

50
00:03:13,000 --> 00:03:19,000
Along with this I will go ahead and call my lang chain API key okay, which is present in the environment

51
00:03:19,000 --> 00:03:20,000
variable.

52
00:03:20,000 --> 00:03:23,000
So for the Lang Smith tracking I need to set this one value.

53
00:03:23,000 --> 00:03:27,000
The other value that we really need to set is something called as lang chain tracing.

54
00:03:28,000 --> 00:03:28,000
Okay.

55
00:03:28,000 --> 00:03:30,000
So this needs to be set to true.

56
00:03:31,000 --> 00:03:35,000
And finally my project name which is my Lang chain project name.

57
00:03:35,000 --> 00:03:40,000
So I will try to go ahead and create this key which says Lang chain underscore project is equal to simple

58
00:03:40,000 --> 00:03:41,000
Q&A chatbot with OpenAI.

59
00:03:41,000 --> 00:03:42,000
Okay.

60
00:03:42,000 --> 00:03:45,000
Or I'll just go ahead and write Q&A chatbot with OpenAI.

61
00:03:46,000 --> 00:03:46,000
Perfect.

62
00:03:46,000 --> 00:03:49,000
So till here, everything looks good.

63
00:03:49,000 --> 00:03:50,000
Uh, we are good to go.

64
00:03:50,000 --> 00:03:51,000
Uh, with respect to the implementation.

65
00:03:52,000 --> 00:03:56,000
Now, before we start, uh, we have to go ahead and use Streamlit.

66
00:03:56,000 --> 00:03:57,000
Okay.

67
00:03:57,000 --> 00:03:57,000
Sorry.

68
00:03:57,000 --> 00:04:00,000
Since we are using Streamlit, first of all, we'll go ahead and define our prompt template.

69
00:04:00,000 --> 00:04:04,000
So let me quickly define our prompt template.

70
00:04:04,000 --> 00:04:08,000
Now for defining the prompt template we are just going to use.

71
00:04:08,000 --> 00:04:10,000
Prompt is equal to chat prompt template.

72
00:04:11,000 --> 00:04:18,000
And here I will just go ahead and write dot from underscore message messages okay.

73
00:04:18,000 --> 00:04:22,000
And with respect to this I will just go ahead and create two brackets.

74
00:04:22,000 --> 00:04:28,000
One is with the system like what information I need to give to the system.

75
00:04:29,000 --> 00:04:31,000
Uh, some prompt message I need to give to the system.

76
00:04:31,000 --> 00:04:32,000
How the system should behave.

77
00:04:32,000 --> 00:04:35,000
System basically means all the LM models that we are interacting with.

78
00:04:35,000 --> 00:04:40,000
And the second brackets that we are specifically going to use is something called as user.

79
00:04:40,000 --> 00:04:46,000
Now inside this user I will go ahead and write my question.

80
00:04:46,000 --> 00:04:49,000
And here you will basically be having a question.

81
00:04:49,000 --> 00:04:56,000
So I'm saying hey uh c just by seeing this, it is a simple Q&A chat, but I have to probably give the

82
00:04:56,000 --> 00:05:00,000
question, and, uh, the system should be giving me the answer, right?

83
00:05:00,000 --> 00:05:06,000
So I'll say, hey, you are a helpful assistant, okay?

84
00:05:07,000 --> 00:05:10,000
Please, please.

85
00:05:10,000 --> 00:05:14,000
Response to the user queries.

86
00:05:14,000 --> 00:05:15,000
That's it.

87
00:05:15,000 --> 00:05:15,000
Right.

88
00:05:15,000 --> 00:05:16,000
We're good to go.

89
00:05:16,000 --> 00:05:17,000
Yes.

90
00:05:17,000 --> 00:05:20,000
Now, once we are able to do this, you know what?

91
00:05:20,000 --> 00:05:25,000
What exactly happens over here is that it's very simple.

92
00:05:25,000 --> 00:05:28,000
A system gets a message that, hey, you are a helpful assistance.

93
00:05:28,000 --> 00:05:29,000
Please response.

94
00:05:29,000 --> 00:05:34,000
Let me make this spelling write response to the user queries.

95
00:05:34,000 --> 00:05:37,000
And the queries are basically coming from this particular placeholder.

96
00:05:37,000 --> 00:05:38,000
Right.

97
00:05:38,000 --> 00:05:40,000
And this will be the format.

98
00:05:40,000 --> 00:05:43,000
So this is how you go ahead and write a prompt.

99
00:05:43,000 --> 00:05:48,000
I will write more complicated prompt prompt as we go ahead when we work with Rag application.

100
00:05:48,000 --> 00:05:53,000
Now let me just go ahead and create a Jeff function which is called as generate response.

101
00:05:53,000 --> 00:05:59,000
Now inside this generate response this function is basically whatever user query comes right.

102
00:05:59,000 --> 00:06:02,000
We need to interact with the OpenAI model LM models.

103
00:06:02,000 --> 00:06:05,000
And it should give me the response from here.

104
00:06:05,000 --> 00:06:06,000
Right.

105
00:06:06,000 --> 00:06:08,000
This is what this particular function basically does.

106
00:06:08,000 --> 00:06:13,000
So over here you'll be able to see that I will give my first parameter which is called as over here.

107
00:06:13,000 --> 00:06:19,000
So let's say this is my first parameter that I really want to give over here is nothing but my question.

108
00:06:19,000 --> 00:06:21,000
What is the query that is actually coming?

109
00:06:21,000 --> 00:06:27,000
The second parameter that I'll give is my API key, because I need to pass my API key during the runtime

110
00:06:27,000 --> 00:06:29,000
so that it will get validated.

111
00:06:29,000 --> 00:06:35,000
Okay, I don't want to put my API key in my environment variable, um, and uh, directly my application

112
00:06:35,000 --> 00:06:40,000
will be able to, uh, probably interact then will give my engines.

113
00:06:40,000 --> 00:06:44,000
Engine basically means let's go ahead and give my LM model, which LM model I really want to interact

114
00:06:44,000 --> 00:06:44,000
with.

115
00:06:44,000 --> 00:06:47,000
Then you have something called as temperature.

116
00:06:48,000 --> 00:06:48,000
Okay.

117
00:06:48,000 --> 00:06:51,000
And finally you have something called as max tokens.

118
00:06:51,000 --> 00:06:51,000
Right.

119
00:06:51,000 --> 00:06:53,000
How many maximum number of tokens are there.

120
00:06:53,000 --> 00:06:55,000
What exactly is this temperature value?

121
00:06:55,000 --> 00:06:57,000
See, every LM model.

122
00:06:57,000 --> 00:07:00,000
Uh, we do set this temperature value between 0 to 1 zero.

123
00:07:00,000 --> 00:07:05,000
Basically means, uh, the model is not going to be much more creative with respect to the answers.

124
00:07:05,000 --> 00:07:09,000
Let's say if I'm asking a question, if I ask that same question multiple times, it is just going to

125
00:07:09,000 --> 00:07:11,000
give me the same type of output.

126
00:07:11,000 --> 00:07:16,000
If I go ahead and keep the temperature value near to one, it is just going to be much more creative

127
00:07:16,000 --> 00:07:18,000
and it will give you some different, different types of values every time.

128
00:07:18,000 --> 00:07:23,000
Okay, so this is what the temperature value is for right now.

129
00:07:23,000 --> 00:07:28,000
In the second, as soon as I go inside this, I will first of all go ahead and use this open AI and

130
00:07:28,000 --> 00:07:30,000
I'll set my API key.

131
00:07:30,000 --> 00:07:34,000
This API key will be nothing but whatever API key I'm passing over here that it will get to set.

132
00:07:34,000 --> 00:07:37,000
Then we are going to use our LM model.

133
00:07:37,000 --> 00:07:42,000
Now for this LM model, uh, we have already imported chat open AI, so we are just going to use this

134
00:07:42,000 --> 00:07:43,000
chat open AI.

135
00:07:43,000 --> 00:07:49,000
And here you will be able to see that I will go ahead and use my model is equal to LM whatever models

136
00:07:49,000 --> 00:07:51,000
I'm actually going to give now what all models are there.

137
00:07:51,000 --> 00:07:52,000
We'll discuss more about it.

138
00:07:52,000 --> 00:07:55,000
We'll see the documentation page of the OpenAI itself.

139
00:07:55,000 --> 00:07:56,000
Right.

140
00:07:56,000 --> 00:07:58,000
Then I'm just going to create my chain.

141
00:07:58,000 --> 00:08:06,000
The chain will be nothing but prompt or now C chain is something how the interaction is basically going

142
00:08:06,000 --> 00:08:07,000
to happen right now.

143
00:08:07,000 --> 00:08:11,000
For this interaction, I definitely require first of all, I need to have a prompt template.

144
00:08:11,000 --> 00:08:14,000
That prompt template will be combined with my LM model.

145
00:08:14,000 --> 00:08:19,000
And one more thing that I did not mention over here is about our output.

146
00:08:19,000 --> 00:08:21,000
Like how our output should look like.

147
00:08:21,000 --> 00:08:27,000
So I'll just go ahead and create my output parser, which is specifically coming from the, you know,

148
00:08:27,000 --> 00:08:33,000
from, from the, uh, lm and here I will go ahead and initialize this.

149
00:08:33,000 --> 00:08:36,000
Then finally, I can go ahead and see my output parser.

150
00:08:36,000 --> 00:08:38,000
And this is what I am actually able to get.

151
00:08:39,000 --> 00:08:41,000
Then let me just go ahead and find the answer.

152
00:08:41,000 --> 00:08:44,000
So our answer will be nothing but chain dot invoke.

153
00:08:44,000 --> 00:08:45,000
We'll just go ahead and invoke it.

154
00:08:45,000 --> 00:08:50,000
And you know, while we are invoking, we have to make sure that the key name should be same.

155
00:08:50,000 --> 00:08:50,000
Right?

156
00:08:50,000 --> 00:08:57,000
So this will be nothing but question, but But what will be over here with respect to the question that

157
00:08:57,000 --> 00:08:57,000
I am asking.

158
00:08:57,000 --> 00:08:58,000
Right.

159
00:08:58,000 --> 00:09:01,000
So this question is probably coming from this particular key.

160
00:09:01,000 --> 00:09:04,000
It is just going to get assigned as we do chain dot invoke.

161
00:09:04,000 --> 00:09:06,000
Now chain dot invoke is doing nothing.

162
00:09:06,000 --> 00:09:09,000
It is just first of all getting this prompt template, combining it with the LM.

163
00:09:09,000 --> 00:09:13,000
And finally whatever response it is getting, it will just go ahead and give this output parser.

164
00:09:13,000 --> 00:09:17,000
So finally, I'll go ahead and return this answer over here.

165
00:09:17,000 --> 00:09:17,000
Perfect.

166
00:09:17,000 --> 00:09:23,000
So this is my function, uh, which is interacting with my OpenAI LM models.

167
00:09:23,000 --> 00:09:28,000
Okay, now quickly, I will go ahead and play with the Streamlit app.

168
00:09:28,000 --> 00:09:28,000
Okay.

169
00:09:29,000 --> 00:09:35,000
Now, in my next video, uh, what I will show you is that I will show you how you can probably go ahead

170
00:09:35,000 --> 00:09:39,000
and create your entire Streamlit app and how you can call this particular function.

171
00:09:39,000 --> 00:09:41,000
So yes, this was it for my side.

172
00:09:41,000 --> 00:09:43,000
I'll see you all in the next video.

173
00:09:43,000 --> 00:09:43,000
Thank you.

