So guys the requirement dot txt has now been installed.
Uh, now in this video we are going to develop our Streamlit web app.
And then we will develop our entire application.
So let me quickly close all these things and let me start okay.
So here uh, the first of all, what I'm actually going to do is that I'm going to import, uh, some
of the libraries like import Streamlit.
Okay.
As s t uh, over here and here you can also see my conda environment is there perfect Perfect.
Import Streamlit as st.
Along with that we will also go ahead and import OpenAI.
And then from lang chain underscore OpenAI I see since we are working with OpenAI in the first project,
in the upcoming project we'll discuss with Olimar.
Right.
So right now, if you really want to work with OpenAI along with Lang Chain integration, and I feel
everybody should start working in Lang chain, don't work independently with different different libraries,
because Lang Chain is a framework which is created in such a way that it can interact with OpenAI APIs,
it can interact with open source LLM models, it can interact with Huggingface.
Right.
All these things will specifically be included.
So here I'm going to quickly go ahead and import chat OpenAI okay.
And then along with this I will also go ahead and write lang chain underscore core dot output parser.
Import str output str output parser.
Okay.
Then.
Uh from lang chain underscore core dot prompts I'm going to import chat prompt template.
Okay, so all these libraries will be the basic requirement that we really need to have.
Then I will go ahead and import OS.
And then from dot env I'm going to import load underscore dot env.
This is just to load all the environment variable.
We will go ahead and initialize this load underscore dot env okay.
Just to check everything is working fine.
What I will do I'll just go ahead inside this particular project folder I'll go ahead and write Streamlit
run uh app.py.
And here I'll go ahead and execute it okay.
So this works absolutely fine.
Here you can actually see this right.
So everything is working fine.
Nothing is getting displayed, I know that, but till here, everything looks good.
Okay, so I will just press Ctrl c.
Perfect.
Now, now next step.
Uh, what we are really going to do is that we are going to implement our language tracking Lamb-smith
tracking.
Okay.
Now, inside this lamb-smith tracking, uh, I will quickly go ahead and write OS dot environ.
And I will just go ahead and call the environment variable.
That is nothing but lang chain API key.
So quickly let's go ahead and write this lang chain API key.
And let me go ahead and write GA uh os dot get env.
Along with this I will go ahead and call my lang chain API key okay, which is present in the environment
variable.
So for the Lang Smith tracking I need to set this one value.
The other value that we really need to set is something called as lang chain tracing.
Okay.
So this needs to be set to true.
And finally my project name which is my Lang chain project name.
So I will try to go ahead and create this key which says Lang chain underscore project is equal to simple
Q&A chatbot with OpenAI.
Okay.
Or I'll just go ahead and write Q&A chatbot with OpenAI.
Perfect.
So till here, everything looks good.
Uh, we are good to go.
Uh, with respect to the implementation.
Now, before we start, uh, we have to go ahead and use Streamlit.
Okay.
Sorry.
Since we are using Streamlit, first of all, we'll go ahead and define our prompt template.
So let me quickly define our prompt template.
Now for defining the prompt template we are just going to use.
Prompt is equal to chat prompt template.
And here I will just go ahead and write dot from underscore message messages okay.
And with respect to this I will just go ahead and create two brackets.
One is with the system like what information I need to give to the system.
Uh, some prompt message I need to give to the system.
How the system should behave.
System basically means all the LM models that we are interacting with.
And the second brackets that we are specifically going to use is something called as user.
Now inside this user I will go ahead and write my question.
And here you will basically be having a question.
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
question, and, uh, the system should be giving me the answer, right?
So I'll say, hey, you are a helpful assistant, okay?
Please, please.
Response to the user queries.
That's it.
Right.
We're good to go.
Yes.
Now, once we are able to do this, you know what?
What exactly happens over here is that it's very simple.
A system gets a message that, hey, you are a helpful assistance.
Please response.
Let me make this spelling write response to the user queries.
And the queries are basically coming from this particular placeholder.
Right.
And this will be the format.
So this is how you go ahead and write a prompt.
I will write more complicated prompt prompt as we go ahead when we work with Rag application.
Now let me just go ahead and create a Jeff function which is called as generate response.
Now inside this generate response this function is basically whatever user query comes right.
We need to interact with the OpenAI model LM models.
And it should give me the response from here.
Right.
This is what this particular function basically does.
So over here you'll be able to see that I will give my first parameter which is called as over here.
So let's say this is my first parameter that I really want to give over here is nothing but my question.
What is the query that is actually coming?
The second parameter that I'll give is my API key, because I need to pass my API key during the runtime
so that it will get validated.
Okay, I don't want to put my API key in my environment variable, um, and uh, directly my application
will be able to, uh, probably interact then will give my engines.
Engine basically means let's go ahead and give my LM model, which LM model I really want to interact
with.
Then you have something called as temperature.
Okay.
And finally you have something called as max tokens.
Right.
How many maximum number of tokens are there.
What exactly is this temperature value?
See, every LM model.
Uh, we do set this temperature value between 0 to 1 zero.
Basically means, uh, the model is not going to be much more creative with respect to the answers.
Let's say if I'm asking a question, if I ask that same question multiple times, it is just going to
give me the same type of output.
If I go ahead and keep the temperature value near to one, it is just going to be much more creative
and it will give you some different, different types of values every time.
Okay, so this is what the temperature value is for right now.
In the second, as soon as I go inside this, I will first of all go ahead and use this open AI and
I'll set my API key.
This API key will be nothing but whatever API key I'm passing over here that it will get to set.
Then we are going to use our LM model.
Now for this LM model, uh, we have already imported chat open AI, so we are just going to use this
chat open AI.
And here you will be able to see that I will go ahead and use my model is equal to LM whatever models
I'm actually going to give now what all models are there.
We'll discuss more about it.
We'll see the documentation page of the OpenAI itself.
Right.
Then I'm just going to create my chain.
The chain will be nothing but prompt or now C chain is something how the interaction is basically going
to happen right now.
For this interaction, I definitely require first of all, I need to have a prompt template.
That prompt template will be combined with my LM model.
And one more thing that I did not mention over here is about our output.
Like how our output should look like.
So I'll just go ahead and create my output parser, which is specifically coming from the, you know,
from, from the, uh, lm and here I will go ahead and initialize this.
Then finally, I can go ahead and see my output parser.
And this is what I am actually able to get.
Then let me just go ahead and find the answer.
So our answer will be nothing but chain dot invoke.
We'll just go ahead and invoke it.
And you know, while we are invoking, we have to make sure that the key name should be same.
Right?
So this will be nothing but question, but But what will be over here with respect to the question that
I am asking.
Right.
So this question is probably coming from this particular key.
It is just going to get assigned as we do chain dot invoke.
Now chain dot invoke is doing nothing.
It is just first of all getting this prompt template, combining it with the LM.
And finally whatever response it is getting, it will just go ahead and give this output parser.
So finally, I'll go ahead and return this answer over here.
Perfect.
So this is my function, uh, which is interacting with my OpenAI LM models.
Okay, now quickly, I will go ahead and play with the Streamlit app.
Okay.
Now, in my next video, uh, what I will show you is that I will show you how you can probably go ahead
and create your entire Streamlit app and how you can call this particular function.
So yes, this was it for my side.
I'll see you all in the next video.
Thank you.