Hello guys.
So we are going to continue the discussion with respect to Lang Chin.
And already in our previous module, we have discussed about some of the very important components of
Lang Chen that we usually use, uh, that are nothing but like document loaders.
We also discussed about data transformation technique, where we are dividing our documents into chunks
of text or chunks of documents.
After that, we also saw how we can convert this text into vectors by using various vector embedding
techniques.
And after that, we also saw how to store this vector embeddings into a vector store database.
And finally we could find out the response of our output with the help of both retriever and.
Along with that we also use some kind of LM models.
Okay, so now we are going to go ahead and build some amazing simple LM applications.
So in this video we are just going to build a simple LM application.
And in the upcoming videos lot many things we are going to add on top of it okay.
So what we are going to discuss in this video we are building a simple LM application with LCL.
Okay.
So this is a very important word.
If you don't know the full form of LCL, it is nothing but using Lang chain expression language.
And this is basically used to chain components together.
Okay.
So what we are going to do in this tutorial here I have given a brief information.
In this quick start, we'll show you how to build a simple LM application with long chain.
This application will translate text from English into other languages.
This is a relatively simple LM application.
It is just a single LM clock plus prompting.
So I will also be talking about prompting over here.
Still, this is a great way to get started with launching.
A lot of features can be built.
Uh, and that is what we are going to see in the upcoming series of video.
Right?
So after seeing this video, you will be getting a high level overview of using language models, using
prompt templates and output parser, using Lang chain expression uh language to chain components together,
debugging and tracing your application using Lang Smith, and finally deploy your application with Lang
serve.
So everything.
We will go ahead and discuss about it here.
In this video we are also going to discuss about something called as Lang serve.
Okay.
So multiple set of videos are going to come with respect to this.
So let's go ahead and discuss uh this entire thing.
But at the end of the day, after completing at least this particular module, you will probably get
the best hands on experience of building the LLM application.
I am going to make that.
Sure.
Okay.
So let's go ahead.
So first of all here we will go ahead and install.
That is nothing but Lang chan okay.
So I will go ahead and right over here Pip install pip install Lang chan okay.
So we definitely require this.
And already in our previous module we have done this installation.
But just for the people who have directly jumped into the session, I will just show you how to do the
installation.
So once we do the installation in this specific environment it will get installed.
You can see already the requirement is already satisfied at my end.
Okay.
The reason is because I have already done the installation.
So please make sure that you go ahead and right after the installation, this particular library name
in the requirement dot txt right how I have actually shown you in the previous module.
Now after this, uh, what we are going to do in this particular video, that is very much important
here.
See, in our previous module we have shown how to use the OpenAI API key.
Right.
And with the help of this we try to interact with some LLM models over there.
Now the most important thing that you really need to understand from this is that whenever we try to
create an OpenAI API key, you have to go to the account and create it.
So one problem that I usually find that many people do not have credit card or debit card, and they
don't even want to invest some money in just going ahead and seeing OpenAI API calls, right?
Uh, and OpenAI API is basically paid if you specifically use both the embedding or any other models
like GPT four or GPT four turbo or GPT 3.5.
So there will be some charges involved.
So in this video, I'll just not show you OpenAI.
I will also go ahead and show you how you can use open source models.
Okay.
Open source models such as, uh, llama three okay.
Llama three from meta you.
I will also show you how to use this gamma two model, which is the recent model that has been come.
Uh, it is an open source model that has been brought by Google before it was gamma one.
Um, along with it, if you want, you can also go ahead and use Mistral.
Okay.
So all these kind of variants of model will have we are going to see uh, how we can actually use it.
And to use this open source model I'm going to use a platform which is called as grok.
Okay.
So the first thing what I'm actually going to do is that I will go ahead and show you how you can go
ahead and create your grok API key.
Open API key is already there in the env file, which we basically created in our previous module.
So let me do one thing quickly.
Let me just go over here.
I will open my Google over here okay I'll just go ahead and write grok LPU okay.
Now what exactly is this grok LPU will discuss about it.
So first of all, uh, instead of just searching, I will just go ahead and do grok.com.
Okay.
So once I write grok.com this is what a platform you will be getting.
I have right now signed in.
Uh if you have not signed in.
So please make sure that you go ahead and create a, uh, your account over here.
Sign up.
Because, uh, grok actually helps you to access all these open source models like gamma two, nine,
nine, be it other than that gamma seven, be it uh, llama 370 billion parameters llama three 8 billion
parameters Mistral eight into seven be.
All these models are completely open source.
And these are like powerful models.
These are from tech giants.
Now to access these models you definitely require API key because grok has deployed this particular
model in its own cloud.
And over there they have used this amazing inferencing, which is called as LPU AI Inferencing Engine
right now.
What exactly is this LPU inferencing engine?
Let's talk about it.
So first of all we will go ahead and click on Why Grok okay.
You need to understand why grok.
So grok is a fast AI inference okay.
What is exactly grok.
It is an AI infrastructure company that delivers fast AI inferencing.
Let me tell you one thing guys.
Right now, in this generative AI era, every bigger companies are in that competition to probably create
the best LLM models.
Okay.
Every company like let's say llama three open source, they come coming up with the slam from meta.
Specifically llama three model has come from Google.
Gamma two model has come.
You know if I probably talk about OpenAI again there is a GPT four model, right?
It is a multi model which works with both text and images.
So all these specific models are there.
Right.
And all these tech giants are in fierce competition.
Who actually brings the best accuracy out there.
But I still believe that the company instead uh, you know uh, the company who will win is that who
will be able to help us in the inferencing.
Right.
Because all these models are huge models and we really need to deploy this particular model somewhere.
Let's say that if we are using our own inferencing or if we are using our own premise, right, to deploy
that particular model and use it for inferencing, then there will be a lot of charges for that, right?
It is not that simple.
They will definitely be a lot of charges and grok what it has actually done.
It has brought this amazing LPU inferencing engine.
Right.
So what is an LPU inferencing engine?
LPU stands for Language Processing Unit.
It is a hardware and software platform that delivers exceptional compute speed, quality and energy
efficiency.
And because of this, this is really, really fast.
You will be able to get the response in no time.
You'll be seeing it once.
I will probably go ahead and execute things right in front of you.
You will be able to understand how powerful it is now, why it is so powerful, and why it is faster
than GPUs that also you really need to understand.
The GPU is designed to overcome the two LM bottlenecks.
One is compute density and memory bandwidth, and LPO has greater compute capacity than a GPU and CPU.
In regards to LM, this reduces the amount of time per words calculated, allowing sequence of text
to be generated much faster.
Okay, so this is what it is basically doing is that it is the two bottlenecks is basically there in
the GPU, which is called as compute density and memory bandwidth, and it is fixing that.
You can go ahead and read about more about this particular research paper.
You know and probably understand about the architecture and all.
But again, thanks to grok, uh, this AI infrastructure is giving us some APIs to probably call, uh,
all this kind of LLM models and use it for our, uh, application purpose.
Okay.
Now let's go ahead and let's do this.
So first of all, I will go to my grok, uh.com okay.
Now let's go ahead and log out.
I will first of all show you how the home page looks like.
So this is what you will be able to see.
So first of all go ahead and sign in for signing it.
Uh, I will just go ahead and use my Google account.
Okay.
So I'll just go ahead and click on Google right now.
As I said, here are so many different, different LLM models.
Now if you want to use this LLM models with the help of uh in the grok AI platform specifically from
here, we have to go ahead and create our, uh, you know, we have to create our API key.
Now in order to create a API key, I will go ahead and click on Grok Cloud.
Let's open this in a new link.
Uh, over here you'll be able to see playground documentation.
Right.
How to use this grok API key.
Everything is over here right.
How to use it.
Uh, along with the library, everything, uh, is basically available, right?
We will talk more about this, but, uh, let's go ahead and create our API key.
So here you can go and see that I have created so many API keys.
You can use any of the API key that you want in order to create it.
Just click on create API key.
Give the name of the API key like something like grok test and just click on submit.
Once you click on submit, you will be able to get this secret key, something like this.
Right?
It is not visible right now, but once you create it, you will be able to create that secret key.
Once you get the secret key, please copy it.
And then you go to your environment variable.
And here you can see I've also created this grok underscore API key with this particular secret key
because I have already created it.
Okay.
Now with the help of this grok API key, I will try to call the open source models.
Okay.
So let's go ahead and let me show you how you can basically go ahead and do it.
So first of all I will go ahead and write import os okay.
Import os uh, along with the OS, I'm also going to say from dot env I'm going to import load underscore
dot env okay.
Now let me just go ahead and initialize load underscore dot env okay.
So now this load underscore dot env right.
It actually loads all the environment variable I have both my environment variables of OpenAI key and
grok API key.
In order to load the OpenAI key.
What I can do, I can just go ahead and right import OpenAI.
And here I will just go and say OpenAI dot API key is nothing.
But here I will say OS dot get env uh os dot get env.
And here I'm just going to give my key name, which is nothing but open AI underscore API underscore
key okay.
This is done right.
Uh, that is how I actually call.
Now I can go in and just, uh, use any, uh, open AI models and I can basically go ahead and do my
further task, whatever task I really want to do.
Right?
Similarly, in order to create the grok API key, what I will basically do is that I'll say, hey,
this is my grok API key.
I will go ahead and create this and I'll say, hey, this is my OS dot environ, and let me just go
ahead and call sorry OS dot get env.
I'll say.
And here I'm just going to go and call my grok underscore API underscore key.
Okay.
Now this basically is my grok underscore API key.
Okay.
Now understand one more thing I have got my key.
This is my key that I'm actually going to use to interact with the models right now.
The next library that I'm actually going to use is something called as pip install lang chain grok.
Now understand why I'm installing this library, because this library will be responsible in taking
that particular API, along with interact with any LLM models that are deployed in the grok platform.
Okay.
So first of all we'll go ahead and install this.
So here I think I've already done this installation because I don't want to take much time.
So here you can see it is already satisfied okay.
Now do one thing.
As soon as I do this installation you also need to go ahead and update in the requirements.txt.
So I have already done that.
I have updated in the requirements.txt.
Uh, and please do not miss that because later on whenever you want to do the, uh installation, I
can, you can directly go ahead and write pip install minus requirement dot txt in the same environment
that is called as v and v.
Okay.
Perfect.
Till here everything is done.
Now let's see how to call our model okay.
So I will go ahead and write from lang chain lang chain underscore grok.
And we will be using this will not be using OpenAI.
Yeah.
In some of the use cases we'll be using OpenAI API keys because uh it actually performs well over there.
But, uh, in most of the use cases, I'll go ahead and use this open source, uh, API keys itself.
Right.
So here I'm going to import something called as chat grok.
Right.
So whenever I go ahead and import OpenAI.
So for that I use from lang chain underscore OpenAI I'll import chat import chat OpenAI.
Right.
But in the case of grok I will be importing chat grok.
Now see this is what LinkedIn is basically doing.
LinkedIn wants to probably create integration with every LLM platform out there, right?
LLM models out there, they'll say, hey, you all bigger companies, you keep on competing, you bring
up new new models, but we will create a wrapper which will help us to integrate with any kind of model
that comes in the in the picture right there.
Right.
So that is what it is basically doing.
Now let me show you how we can go.
Go ahead and call a specific model from grok AI platform, uh, specifically the open source model.
So first of all, I will go ahead and initialize Chad Grok.
And I will say first parameter that I need to give is my model name okay.
And the second parameter I will go ahead and write my grok API key which will be equal to my grok API
key.
Right.
So this is what I'm actually initializing.
Now you need to understand what model name we will give okay.
So to give the model name.
So I will just go ahead and use this one.
This is the most newest model gamma two nine be it okay.
So if you want to know about this particular model it is nothing.
But it is a 9 billion parameter version of Google Gamma models, a family of lightweight, state of
art language models from Google with open weights and pre-trained variants.
Okay, so we are going to use this specific model out there so quickly.
Let's go ahead and open this over here.
Now I will just go ahead and write.
Uh let me just see the model name gamma two nine.
Be it okay.
Gamma two nine, be it gamma two nine, be it okay.
So this is specifically my model over here.
And with respect to this particular model if I go ahead and execute it.
So here you will be able to see that I'm able to call this model.
And the model name is nothing but gamma two nine be it.
So let's see gamma two nine be it okay.
So this particular model is basically over here.
Now with the help of this specific model we are going to develop our entire application.
Uh I've already shown you how to call chat OpenAI a model name.
Uh, already we have set up this particular environment variable.
I can just go ahead and write, chat OpenAI AI and give the model name over there.
That's it.
Automatically the model will be initiated.
Perfect.
Uh, I hope you got an idea.
Till here.
Now in the next video we will continue this implementation.
But in this video I have shown you how to.
You can set your grok API key to access the open source model that has been hosted or deployed in the
grok AI platform.
And remember, uh, you will be able to use this particular API key for some number of requests completely
for free.
And I think, uh, I've never faced a problem with respect to the number of requests till now.
I'm using it.
Uh, uh, you can also go ahead and use it.
Okay.
So yes, this was it.
Uh, in the next video, we are just going to continue the implementation of simple LM by LCL.
And uh, then after loading this particular model, we are going to see what all things we will do.
Okay.
So yes, this was it from my side.
I'll see you all in the next video.
Thank you.