LangChain GEN AI Tutorial – 6 End-to-End Projects using OpenAI, Google Gemini Pro, LLAMA2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Lang chain is a framework for developing applications powered by large language models like gp4 in this course you will learn Lang Chain by building six inin projects with the open AI API Google Gemini Pro and llama 2 you'll also learn how to deploy projects to the hugging face platform Chris neack developed this course considering this here is an amazing video of the entire Lang chain crash course along with this we'll be discussing six plus endtoend projects llm projects using different different llm models from open AI we'll be using Lama 2 from meta we'll also be using Google giny pro not only that we'll also be using hugging face and we'll also be seeing how we can deploy this in hugging space uh platform itself which is provided by hugging face itself right so there will be somewhere around six plus end to end projects we'll develop both the front end back end I hope you enjoy this entire Series this is a long video so please make sure that you devote some some amount of time every day and try to practice as much more you can right so in order to push this video to many people out there guys I'll keep the like Target to 2,000 please make sure that you hit like share with all the friends share your work in LinkedIn in different platforms tag me over there I'll be very happy to see what all things you specifically developing so let's go ahead and enjoy the series and I hope you practice along with me all the materials will be given in the description of this particular video so let's go ahead guys so finally finally finally here is the langin series and this is probably the first video where I'm probably going to discuss a very good one-hot video about Lang chain all the important components that you specifically need to know to build projects now why I'm stressing on langin is that because many people recently some of my students and some of experienced professional who switched into data science Industry they are getting work that are related to large language models and they're specifically using Lang chain and the community with respect to langin is also increasing so that is the reason I've created this dedicated playlist and I'm going to discuss a lot many things this video we will understand all the important competents of this Lang chain what you specifically need to know with respect to the Practical orientation and from the next video onwards lot of end to endend projects are probably going to come up uh in this video also I'll discuss about one Q&A project uh chatbot in short you know we'll try to use streamlet it's not like we only have to use streamlet you can also use flask you can use anything as you want right but streamlet it provides you a good UI you can also use gradio if you want right it is up to you so what all things we are specifically going to discuss first of all we'll try to understand the agenda and then we will try to uh do step by step each and every line of code will be done and as I said this is just like a kind of L chain one shot video just to give you an example that how we are probably going to create our end to endend application after we deploy that in a specific cloud like hugging phas right it provides your entire environment to probably host your application uh this is what we are going to create this chatbot see if I probably ask what is the capital of New oh sorry of India then you'll be able to see that I'm I'll be able to get the answer what is the capital of Australia many people get confused with the capital Australia please do comment down in the comment section what is the capital of Australia and let's see whether it is right or not so here you can see the capital of Australia scan so we are going to create this application at the end of the day but before that we really need to understand lot of important components in Lang chain so let's go ahead and let's start this particular session before I go ahead please make sure that you subscribe the channel press the Bell notification icon and share with many friend so that it will also be helpful for them and it will also be helpful for me so that you are able to provide this open source content to everyone out there many people require help and you should be the medium to provide this specific help by just sharing it right so what is the agenda we'll understand as I said this will be completely a practical oriented video it'll be a long video where I'll be talking more about practical things how you can Implement Lang chain how you can probably implement various important functionalities in Lang chain and use it probably to build an endtoend application so first of all we'll go ahead and do the environment setup this is commonly required you also require an open AI key API key so this also I will show you how it is done then we'll try to build simple applications uh with the help of llms three important things are there llms prompt templates and output parsel okay in llms you specifically have llms and chat models chat models are basically used in chat B to understand the context reference and all right I will also be discussing this practical promt templates can play a very important role and then coming to the third one that is called as output parser uh in short prompt template and llms and output parser gives a very good combination of output like it it'll give you a good output the output like you specifically want right so that is where output Parcels will also be used before to go ahead with what I will do is that uh first of all just go to the open aai uh website itself and get your API key how you should get it just go to this account and there you'll be able to see view API key and create the new C secret key right so once you create it give the key name and then copy it and keep it right I'm not going to share mine so that is the reason why I'm showing you this specific step now I will go to my vs code all my coding will be done in this VSS code itself here you can see it is completely blank right I've just opened a folder in the form of a project now all you have to do start your project over here now the first thing as usual what we need to do we need to create a new environment right so this is the first step that you specifically need to create with respect to an environment so don't miss this specific step it is important and probably whatever projects that we are going to discuss in the future we have to do the specific step so I will write pip install okay sorry cond create I'm creating an environment so let me just not open in Powers shelf instead I'll go and open in command prompt okay so here I will just right K create minus p v EnV V EnV python equal to 3.9 so 3.9 is the version that I'm going to specifically use and also going to give- Y so that it does not ask me for the permission instead start creating the specific environment the reason why I'm using this environment understand one thing that guys for every project that we probably create we have to create a new environment that actually helps us to just understand or just use only those libraries that are actually required for this particular project okay so this is the first step go ahead do it with me you know uh and do it in vs code because vs code is a good idea if you want to do it in pycharm then also you can do it but since you following this tutorial I'm actually going to do it in vs code I feel vs code is good I I've used both okay I've used different different IDs but I feel vs code is good okay so here it is now here you can probably see my V EnV environment uh the next thing we will go ahead and activate this V EnV environment so I will write cond activate cond activate V EnV Dash Okay so this is my first step done I'm good with it now the next thing what I will go to do is that I will just go ahead and write my requirement. thxt right because we need to install the library since inside this particular venv environment so I will go ahead and write all the list of libraries that I'm specifically going to use now what are libraries I'm going to use over here uh we will just write it down so that uh the first library that I'm going to use is Lang chain then open Ai and I think I'll be using hugging face also later on it is called as hugging face Hub that I will show you as we go ahead okay so these are the two libraries that I'm going to specifically use okay now the next thing what I will do I will go ahead and write pip install minus r okay so let me just hide my face so that you'll be able to see pip install minus r requirement. txt so once this installation will take place that basically means my requirement. txt is getting installed that basically means all the libraries that I actually require over here that is getting installed and for this I require Lang chain and open aai okay so once this installation will will be taken place like it will be done now one more Library I'll be required is called as IPI kernel because if I really want to run any Jupiter notebook over here I have to use that okay so let's wait and let's see once the installation is probably done and then we will continue the video so guys the all the libraries that were present in the requirement. txt has been installed now the next step that I'm probably going to do is also install IPI kernel which will be required to run my Jupiter notebook so I will go ahead and write pip install iy kernel Now understand one thing I'm not writing this library in requirement. txt because when we do the deployment in the cloud IPI kernel will not be required okay so that is the reason I'm installing separately pip install IPI kernel in the same VNV environment because VNV environment also we are not going to push it right so you can probably see over here downloading this this will happen and automatically the download will happen itself right now the next thing what I'm going to do I'm just going to write Lang chain dot ipynb okay py NB so this will basically be my jupyter notebook that I will specifically be using okay so right now it is detecting kernel once this installation will probably happen and then we will also be able to see the kernel okay so this is all the steps all the basic steps that you probably require from this you can start creating end to endend project but at least you require this uh along with this I'm also going to add two more steps one is about environment files EnV file okay so here what I will do I will write Dov file okay uh inside this EnV file the reason why I'm uh writing this EnV file because I need to probably use my open API key and probably mention the open API key over here so if I probably write it like this and and whatever API key that I'm probably getting from the website I can upload it over here and using right uh load environment function right we can load this API key uh as a variable so that we can actually call our API API key over there so I will update this later on as we go ahead okay so till here everything is done this is my Lang chin ipynb file I will go ahead and detect the environment this is what 3.9.0 so here it is so let's see whether it is working or not 1+ one it's working right so this is perfectly all right so everything over here is done with a respect to this and I'm very much Happy this is working uh which is really really good okay so this is done now what I am actually going to do over here is that we need to import some of the important libraries like open Ai and all right so for this I will go ahead and right from Lang chain. llms okay import open AI see there there lot many models like open llms and all first we'll start with open AI understand one thing guys the reason why I say this is completely practical oriented because you need to have the basic knowledge of machine learning deep learning and all but this specific libraries is used to build application uh fine tune your application with respect to models with respect to your own data set most of the things just with writing proper lines of code will be implemented in an easier way so you really need to focus on things how things are basically done okay now the next thing what I will do I will write import OS and I will say OS do Environ environment okay and here I will give my opencore API underscore key okay this is how you should basically write it down to import the API key now what I will do I will keep this hidden from you so just imagine I cannot show you the API key because I will be using my own personal API key itself so I will go ahead and probably pause my video and update the API key and I'll remove this specific code okay that is what I'm actually going to do so that none of you basically sees that and it is important you have to use your own API key so let me quickly go ahead and do that and let me come back so guys this is how you have to probably import your API key this will I've made some changes so if you also copy it is not going to work I made some internal changes in between changes so uh you just need to write os. environment open API key and this API key that you have specifically got okay so this is the initial step uh I have also imported open AI so that I will be able to call this particular uh open AI itself now this is done this is good everything is working Absol absolutely fine now what I'm actually going to do I'm going to create my llm model and go ahead and write my open AI let's see open AI open AI function is the called or not let's see okay open AI from L chin open Ai and inside this open AI what I'm actually going to do I'm going to basically call a variable which is called as temperature and temperature right now you can keep the value between 0 to 1 the more the value towards one the more different kind of creative answers you may get right if the value is towards zero then what kind of output you you are probably getting from the llm model is going to be almost same from the uh anytime you number anytime you probably execute so here I'm just going to keep it as 6 so this is basically my open a llm model okay now this is done my llm model is there so here you can see did not find an open AI key please add an environment variable open AI key now this is the error that you are specifically getting right so why this particular error is probably coming you should definitely understand okay without this understand that this kind of Errors can come to you the reason why I will not edit this particular error because I really want you all to understand it is saying did not find open API key now what you can probably do with respect to this okay there are two different things that you can probably do either you can take this API key save it in a constant variable and try to use that particular variable over here right so for that also you can directly do that uh I have also created this do EnV file what you can do you can load this environment variable and probably directly read it over there right but let me just go ahead with a simple way you know so you will be able to understand with respect to that also so here what I'm going to do here I will go ahead and probably say open API key and here I will going to write OS do environment okay and here I'm going to Define my open API key okay now let's see whether this will get executed or not I will show you much more better ways when we are probably executing our end to end application so let me go ahead uh open a key is not defined because I use double equal to perfect now you can see that it has got executed perfectly now when I am actually creating an end to end project I will show you a better way the most efficient way that we should specifically use when we are building an end to end project but right now I'll go to focus like this now understand one thing is that with respect to temperature variable right the temperature that we specifically used I will give a comment over here and you can probably see over here right so temperature value how creative we want our model to be zero means temperature it is it mean model is very safe it is not taking any bets it will risk it might generate wrong output may be creative so more the value towards one the more creative if the model becomes right it is going to take more risk to provide you some more better but again with respect to risk again there may be a problem you may get a wrong output perfect this is the step simple step that we have done at the end in this video only I'm going to probably do create an end to end project understand this will be very important for everyone because as we go ahead in the next videos the project difficulty will keep on increasing okay now this is done now what I will do quickly I will go ahead and write text let's say the text is what is the capital of India okay so here I will write print llm do predict and here I'm going to basically write my text so here you can see the capital of India is New Delhi so here what I have done is that this is my input and if we use lm. predict I'm going to probably get the text so if you like liking this video till here guys as I'm teaching you step by step I'm explaining you each and everything please make sure that you practice in a better way right if you like it please make sure that you subscribe the channel also okay so this is done lm. predict and we are able to probably get the output okay so understand what what all things we did we created an open AI model right but here in the open AI right you should also understand one important thing here there is a parameter which is called as model now what all model you can probably bring it over here what all model you can probably call so here I will go to my documentation page okay and uh if I probably click on the models now here are the set of models that you can probably use by default it is calling this GPT 3.5 turbo it is the most capable GPT 3.5 model and optimized for chat at the 110th cost of a Dy 003 we'll be updated with our latest model iteration 2 weeks after it is released it's not like you only have to use this you can use this you can use this you can use this you can use this whatever models you want you can probably use it if you want to probably go with GPT 4 you can use this you can use this you can use this but at the end of the day gp4 is the most uh amazing thing it is more capable than GPT 3.5 so this is what models is by default over there it is probably taking this specific model which you can probably use it now as we go ahead it is not like you can only call this model itself in hugging face you have open source models also right from Google from different companies you have that uh open source llm models you can also call that and I will also show you an example with respect to that okay so till here I hope you have understood it I think you should give a thumbs up if you're able to understand till here now let's go ahead and do one more thing I will also show you with respect to hugging face now okay now with respect to hugging face what I will do I will quickly go ahead head and write hugging facehub right I will probably install this library now let me go ahead and open my terminal okay so I will delete this and quickly we will go ahead and write pip install pip install minr requirement. txd done so this is getting executed and then I will probably show you with respect to hugging face also so hugging face this is done okay the installation is done so you have to use hugging face Hub now in case of hugging face also right you will specifically get a you will also be getting a because at the end of the day we'll also try to deploy it over here if you go to settings right and if you go to access tokens here you can probably see I have some kind of token right and with the help of this particular token only you will be able to call any models that are available over here so in this models if you probably go ahead and see there are lot of llm models that are available right so if you probably go over here natural language token classification question answer like uh let's say text to text generation this is basically one kind of llm model I will search for one name okay so the name is flan okay flan T5 base okay so this specific model or T5 large this is a text to text generation model right so this is also an llm model if I want I can use this also why I can use this because this is an open source okay if you want to probably see the answer right text to text generat false or not false or false is uh if I want to compute it right it'll give me some specific output okay false or false or false is the verb the verb right something like this it is getting an output right so I can also use my I can also create my chat models with the help of this kind of models directly by using this API right but how to do it let's go ahead and see it okay so here what I will do quickly I will first of all import one more important thing again in my environment variable os. environment and here I'm going to basically write in the case of hugging P I have to use something called as hugging oops I have to write in capital letter hugging face hubor API uncore to token okay so here is my token okay hugging face Hub _ API _ token now with respect to this particular token I have to write my own token the token is basically given over here as I have already shown you if I probably click on show you'll also be able to see it so I'm not going to do the show part over here so what I will do I will just pause the video upload it execute it change the token and then come back to you okay so let's go ahead till then you can go ahead and create a hugging face account also so guys now I have set up my hugging face Hub API token with this specific token again I've made the changes so if you probably use this again it will not work okay but I have actually imported it now let's go ahead and probably see how we can probably call llm models with the help of hugging face so again and again I'll be using Lang chain Lang chin is just like a wrapper it can call open llm models it can call hugging face uh llm models anything you can probably call with it okay so that is the reason why I'm saying it is powerful so I will write from Lang chain okay import hugging face Hub okay and then here I'm going to probably Define my let me just execute it and then probably I will call it so here I will go and write hugging face Hub here first of all I need to give my repo ID now repo ID is nothing but uh whenever you search for any model this will be your repo ID Okay Google slash this okay so here I'm going to probably go ahead and Define it okay and this will basically be given in a sentence form okay so this is done now the next thing that I will have is model quarks okay and here I will go ahead and Define my temperature and then here I'll go ahead and write max length column 64 that basically means I'm giving the maximum string length to 64 okay now let's see whether this will execute or not I know it is going to give us an error let's see so it is not giving you an error it is probably executing it perfectly it has probably taken that particular key itself inference API is working perfectly everything is working so I will go ahead and Define my variable so here I'm going to basically write my l lmore hugging face okay is equal to this one right so this is done we have probably written this specific thing over here and then I will go ahead and write name or I will see output let's see the output and here I'm going to basically write llm do hugging face do predict and let's say I'll say can you tell me the capital of of Russia okay so let's see whether we will be able to get the output or not so here I'm going to write print output and let's see whether we are so here you can see the output is a simple word right the capital of Russia is Moscow right but here the previous output that we saw with respect to the llm models here it shows that capital of India is New Delhi it is giving you entire sentence and probably here it is just giving you a word and this is what the difference is with respect to an open source uh model itself and models like GPD 3.5 or 4 right so here uh you can probably see this okay and I will also execute one more thing over here let's see uh can you write a poem can you write a poem about AI let's say I give this what kind of poem it gives okay it probably taking time to probably give the I love the way I look at the world I love the way I feel the way I think I feel I love the way I love see what kind of output you're specifically getting right now if I probably give the same output and probably write llm okay dot predict llm dot predict and if I probably give the same sentence let's see what is the output now you will be able to understand why we are specifically using this let's see it should give you a better output I think I love the way I look at the world oh so mysterious was so curious It's technology so advanced IT Evolution so enhance it's a tool that can assist um in making life much less hectic a force that can be used for good or a cause that's misunderstood it can make decisions so Swift and learn from the sto Swift tool that can be better see so how what an amazing poem it has basically written and by this you'll be able to understand the differences why I'm specifically using this open AI model and with respect to hugging face yes there are also some models which you can probably take paid one in hugging face that will give you better output but this is what happens with respect to open source uh models I think we should uh we have lot of Open Source models that are probably coming up Mr 7B and all that also we'll be seeing in this playlist as we go ahead but as I said this is just a basic thing to probably understand we will be focusing on understanding these things right so here uh till here I hope we have discussed so many things how to probably call open AI models with respect to open AI uh Library API itself and then hugging face API also llm models right and using Lang chain so here are what all things we have done now the next thing that we are probably going to discuss is about prompt templates prompt template is super amazing uh it will be very very handy when we are talking about about things with respect to prom template and all so that also we are going to discuss as we go ahead so guys now let's go ahead and discuss about prompt templates which is again a very handy component in the Lang chain even in open AI with the help of prompt templates you will be able to get efficient answers from the llm models itself right I'm not talking about prompt engineering that can get you three CR package okay I'm just talking about simple prompt templates and how prompt templates can be probably used okay now now let's go ahead and first of all import from Lang chain from Lang chain. prompts import prompt template okay uh what we are going to do is that whenever we call a specific llm model you know the llm model should know what kind of input it is probably expecting from the client or from the end user and what kind of output it should probably give it okay so what we do if you want to really Define how our input should be and how our output should be we can specifically use prompt template because understand if we directly use GPD 3.5 it can be used for various purposes right but here I want to restrict all those things within something right so with respect to the input and the output so here I'm going to probably Define my promt template so let me go ahead and Define my promt template now with respect to the promt template here first thing that we need to Define is our input variables so here I will go ahead and write write my input variables okay now in input variables we need to first of all say that what input we are specifically giving there will be a fixed template in that template I really need to give my input okay so let's say here I Define my input and here I'm just using one input let's say the capital or the country I'm just going to write it as country okay so this is my first parameter that I'm going to probably give in my template itself and this I will also store it in my variable which is called as promt template okay great now here I'm given country as my input variable okay here I will Define my template now inside this template what I'm going to say is that tell me the capital capital of this whatever template that I'm specifically giving that is country so this is just like my variable whenever I give the input to this variable it is going to replace it over here right so what will happen by this is that the open AI will be able to understand okay this is the question that is asked but this value is dynamic that I'm probably giving it during the run time something like that okay now here if I want to execute this again I can also write prompt uncore template okay prompt undor template uh dot format right so there is a function called as do format and here now instead of how should I give my input so here I will say country is equal to right whatever the variable name is country is equal to let's say India okay now here you can see that my entire prompt is generated in this way saying that tell me the capital of India okay so here you can probably see tell me the capital of India right now if I want to probably predict I will write llm do predict okay and here I will just say prompt template is equal to whatever my prompt template is defined so here I'm getting an error predict missing one required positional argument text now inside this I've given this prom template but it is expecting one text right what is that particular text that that is particular this particular value right so here what I will do I will go ahead and Define my second variable text and here I will write it as India let's see whether it will get executed still it is giving me an error so guys now you can see when I'm using this llm do predict and I've given my prompt template I've given my text also that was the error that was coming but still it is giving me an error saying that the prompt is expected to be a string instead found class list this this if you want to run the llm multiple prompts use gener instead okay something like this I will show you a way because that is the reason the reason I'm keeping this error over here there is a simple way of understanding things right because this is not the right way to call promt template along with the inputs itself so what I'm going to do quickly I will go ahead and import one important thing that is called as chains so I will say from Lang chain dot chains import llm chain understand one thing guys chain basically means combine multiple things and then probably execute I have my llm model I have my prompt I know I have to give my input based on that input I need to probably get the output so instead of executing directly by using llm do predict I'm going to use llm chain and inside that I'm going to give my llm model I'm going to give the prom template and I'm also going to give the input so this is what we are specifically going to do now this will get gots executed from Lang chain. chain import llm chain now I'm going to create my chain let's say the chain is equal to llm chain and here I'm going to basically write llm is equal to llm okay whatever is my llm model and my prompt is equal to my prompt template okay now this is there this is my chain not chain what it is doing it is combining the llm model it knows what is the prompt template right I'm going to use both of them and now in order to run it so I will write chain. run and here I will say India let's say I'm going to probably say India and I know what is the output it is going to get tell me the capital of India so if I write chain. run it is definitely going to give me the output the capital of India is New Delhi this is perfect right so I can also probably print it right see guys I'm not going to delete any of the errors I want you all to see the errors and then try to understand that is the best way of learning things okay other than this there is no other way right you need to find a way to learn things you don't worry about any errors that are probably coming up you just worry about okay fine you have got that error how you can probably fix that what is the alternate way of probably fixing it right so you can probably use all these techniques as we go ahead right so this is with respect to prompt template and here I'm going to also talk about and llm chain right so these are some important things because all these things we will probably be using in creating our end to end application now let's go ahead and probably discuss some more examples with respect to llm so guys now we are understanding one more important topic which is called as combining multiple chains using simple sequential chain till here we have understood about llm chain LM chain was able to combine an llm model along with the prompt template through which we can also give our input and get our specific output now if I have multiple chain let's say if I'm giving one input I want to use those input in both the chain or three chains four chains how can I specifically do it and for that I'm going to probably use Simple sequential chain okay so let us go ahead and let us probably see how this can probably be done so first of all I will probably say Capital template prompt Capital prompt okay so first like what is the capital of this specific country right so this will basically be my prompt so here I'm going to use my prompt template and here I'm going to basically use input variables is equal to and here I'm going to basically say country let's go to the next input the next input will basically be template and here I will say I want uh please tell me the capital of of the whatever input I'm specifically giving away as country so this becomes my first template right and what I will do I will create a chain the chain name will be Capital chain okay and here I'm going to probably use my llm chain and my llm model will be llm okay and then I will also be using my prom template is equal to as capital template capital template okay so this is done let's see Capital prompt what is capital prompt oh sorry Capital prompt Capital prompt is not defined why uh please tell me the capital of this uh template oh double equal to Let's it no worries uh two validation error for LM chain so first I've used an LM chain where prompt template is equal to this uh where it is capital prompt so guys after just checking the documentation this should be prompt itself okay because in llm chain we have used prompt and here is capital template here also I'm going to probably use Capital tempate now if I execute this this works absolutely fine uh one thing you can probably see over here that I've given my template name and then I've also given the capital chain right so if I want to probably execute it I can just give my chain. run and that particular parameter okay but now what I want is that I also want to create one more prompt template I want to give the same input to that chain also so here uh let's say I will write famous _ template and I will just say promp template and here again my input variable what is my input variable so my input variable will be whatever specific things that I'm trying to give right let's say please tell me the capital of uh India if I say right the capital whatever Capital I'm going to get that variable only I'm going to pass it over here so my input variable will basically be my capital okay and this will be my second one and here I'm going to probably sayest template and I'm going to probably ask a question suggest me some amazing things amazing some amazing places places to visit in that specific capital okay so this is what I'm probably telling right please tell me the capital of the country so I will have that capital information that will be my input variable to from this particular template uh in that specific chain okay so I will get two answers first of all I'll get the capital of that particular country and then what are the some amazing places to visit in that specific Capital place okay so these are all the information that I have put up okay so I hope this also works fine now now what I'm going to create I'm going to create an another chain which will be for this particular famous chain right so here I'll write famous chain okay is equal to and I'm going to probably use my llm chain oh llm chain and here I'm going to give my llm models but the second one that is my prompt is equal to uh whatever template that I'm going probably going to give the famous template okay so this is what I'm probably going to do uh and I've probably given this prompt also over there and this will basically be my chain so once I probably execute it both the chains are ready now I need to give one input it should go to one chain get the output from that particular chain and pass that output to the next chain okay so this is what I specifically want to do how can I do it so again from Lang chain do chains I'm going to import simple sequential chain I know guys uh here you may be thinking why I have to use this see you're passing one input to the get the other output from the one chain and pass that particular output to the other chain to get the just output itself right so this is quite amazing when you see an end to end application there you'll be able to understand these are some of the important components you should definitely know and try to understand okay so here finally what I'm going to do is that I'm going to probably create my chain is equal to and this will be my final chain and here I will probably say I'll import this okay so I get that so chain is equal to simple sequential chain capital letter simple sequential chain and inside the simple sequen chain I just have to name all my chains what all chains are specifically there in the form of list so the first chain uh that I have over here is nothing but Capital chain the second chain that I have is something called as famous chain okay so both the chains are ready now in order to run it all I have to do will write chain. run and here I'll specifically give India okay done let's see what kind of output I will probably get so it is running it is a bustling Metro Police and a great place to visit for historical site cultural this this this red Fort see most popular city the iconic monal is a multivisit who fought in World War one the 16th century mugal era Tom in UNESCO world heritage site everything it is probably giving it right so it did not give us the first answer with respect to the chain because it only provides the last input information okay uh if you want to probably display the entire chain I will show you a way how to do that for that we have to use buffer memory uh there will be something called as buffer memory but one amazing thing I gave one input I got the output and then probably I pass that particular output to my next chain and I able to to get one amazing out answer over here so definitely try it out from your side by using different different examples also now what I'm going to do is that I'm going to probably discuss one very important component about chat model open AI so that is also super important uh that is something related to chat models whenever you probably want to create a chart models you can have to use that okay so let's have a look onto that so guys one more additional thing that let's say I want to probably see the entire chain so here we will specifically use something called as sequential chain and let me just show you one example of that also uh it is not much to do with respect to that but you should definitely know this important video as said again I don't want to probably take more time with respect to this but it is good to know this okay sometime when you are developing things and that you'll probably be understanding once I start end to end project right today one end to end project will be done okay don't worry about this uh in this particular video it will be done uh but definitely I want to show this example also as we go ahead now now uh let's quickly go ahead and do the same thing I will copy this entirely okay I will paste it over here okay now along with llm promt template I will give my output key also so where I specifically want my output key so the output key will be nothing but it will be something called as capital okay so this is my Capital chain with this specific output okay so here I have created this now let's go ahead and probably create the next template uh that is this famous template okay so here also you can probably see the famous template uh suggest me some names of the capital and here I've probably created my template name uh and my chain is over here right so this will basically be my chain okay so the same name whatever output Keys over here I've given this as my input key and here uh I can also derive one output key like this output key places something like this okay so done this is done see two simple templates that I actually created uh s me some amazing places to visit in this particular Capital uh the capital is probably given from here so now the chain will probably be able to understand each and everything as we go ahead you know where the output is and all right so here now what I'm going to do I'm going to probably import from Lang chain do chain chains import sequential chain okay and then finally you can see I'll write chain is equal to simple okay I will let me just execute this because it is not giving me any suggestion so I will write chain is equal to sequential chain and now I'll Give All My Chains name so the first chain name is um to Capital chain D famous chain dang okay and uh after this you will basically be able to understand the input variables now the input variables that we specifically have input variables is nothing but whatever is my variable name what is the variable name in this case it is nothing but country okay and then my output variable I'll also create my output uncore variables so these are the two parameters see guys this this parameters is nothing but whatever parameters I'm specifically giving one is the capital and one is the places done so this is my entire chain now if I want to run any chain what I will do I'll basically write something like this and give what is my country name right so it should be given in the form of key value pairs so here is my country colon India right something like this now if I execute it I will now be able to see my entire chain right it'll take some time so what I have done over here I have in every llm chain that I'm probably creating I'm creating an output key uh two chains so two output key and here you can see chain country India country was India Capital the capital of India is New Delhi here are some amazing places to visit in New Delhi and all the information I have probably over here now let's go ahead and discuss chat models uh specifically in Lang chain and we also going to use one Library which is called as chat openi uh this is also very good if you want to probably create a conversational uh chat bot itself so in chat models with chat open AI first of all what we will do is that we will go ahead and import Lang chain uh do chatore models and I'm going to probably import chat open aai so we will quickly go ahead and import it now after I specifically import this in chat open AI there are three schemas that you really need to understand okay whenever a conversation basically happens if a human is probably giving some kind of input and expecting some response that basically becomes a human message right if by default when the when your chat bot is probably opening a default message will probably come right and that is something related to domain like what that specific chatbot does right so it can probably come up with a new schema which is called as system message and then there is also one more message which is called as AI message which is again a schema which probably gives the output right whatever the chatbot is giving an output uh the AI whatever models is specifically giving the output that is nothing but that is related to the schema that is called as AI message okay now from this here we what we are going to do we are going to import from langin do schema I'm going to import human message system message right as I said system message is also required and AI message here everything you'll be able to get this as an example because uh probably in the upcoming videos we'll create conversational U chat bot right at that point of time we'll be seeing all these things what we'll be using and how we will be using okay so here quickly we'll import this now uh obviously my llm model is there right by uh and while creating before the llm models how did we use it we basically use something called as uh open a right we used open AI now in this case I will probably copy the same thing okay and I will just past it over here and write chat llm okay and instead of writing open AI I'll use chat open AI right so this is what I'm specifically going to use chat open AI with some temperature in this and here I'm also going to give one model so let me go ahead and write my model name uh the model name that we are going to basically write from here is GPT 3.5 Das turbo right I showed you like what models we can specifically use so this is my chat llm model so here if I probably go ahead and write my chat llm so here you'll be able to see that it is a chat open AI uh and with all the information with so temperature what is the uh this and all open AI key I cannot show you so it shows you open AI key also over here so going to remove this okay so that you don't find the opening I key now let's use this three schema and then probably see how my output will look like let's say first of all I'll create the schema in the form of list okay first of all the system message right let's say system message I will go ahead and initialize and I'll write a content content one variable is there I say you are an you are a comedian AI assistant okay so this is the this is what I'm telling the chatbot to behave like right it is basically acting like a comedian AI assistant okay then in the next one I will say human message and here again I will go ahead and write the content and I will say please and this is what I will probably write as a human this is what the input that I am probably giving right so I'll say please make a comedy about or please provide some punch lines some comedy punch lines punch lines on okay AI okay so here you can probably see these are my two things these are the two information that I'm going to give to my chat llm models right and then let's see what is the output okay with respect to that now in order to give this input to my chat llm so I will write chat llm and here only I will open my brackets so it has two information first by default it knows the system is a comedian AI assistant and here as a human input what we are saying is that we are saying please provide some comedy punch lines on AI okay so if I execute this you will be able to see I will be able to get an output now this is how we are going to design later on in the end to endend project we are not going to give this as a hardcoded it'll be quite Dynamic so here you can see AI message see this is the output if I'm getting the output that basically becomes an AI message so this schema that we are able to see from the output of this particular chatbot the system message is basically telling that okay beforehand you have to act something like that we instructing the chatbot to probably act in that way right the human message is basically our input and AI message is what is the output so AI may be smart but it can tell me if your output makes look like a potato AI is a virtual therapist except it never judges you for eating an entire Pizza by yourself something like this so this is what comedy messages you can probably see right and I think this is quite amazing and you can probably set this up any number of time right you can probably say you can add this AI message over here and you can still build more conversational AI right so as AI also give the message you can probably store it inside this s let's say if I probably consider a list and I append this particular list with all this information it can act as a chat model as our as we go ahead right now guys we are also going to discuss about one topic and after this we are going to implement our project okay so over here we going to discuss about prom template plus llm plus output parcel now first of all we'll try to understand what exactly is output parcel now in order to make you understand about output plaster and how we can probably implement it I will use Lang chain again for this um as said guys langin is a powerful Library it has everything as a wrapper right so I will say from Lang chain okay from Lang chain. chatore models first of all I'm going to import chat open AI okay chat open AI I see there so many things Chad vertex AI chap open AI very powerful very powerful and the way it is getting developed right quite amazing right so from Lang chain dot prompts I'm also going to use some prompts and like how we have a prompt template when we use open AI right similarly in chat open AI we use uh prompts which is basically called as chat promate chat prompt template okay so I'm going to basically import chat prompt value no template chat prompt template so I'm also going to import this along with this as I said output parser right output parser is that if I want to modify any output of an llm model beforehand right so I can specifically use output parsers so for Lang chain I will also import this from Lang chain do schema import base output parel right so these are the three things I'm specifically importing and here I'll basically go ahead and write class let's say I am defining one output parser and I'll Define this in the form of class it'll inherit the base output class so let's say uh I will say comma separated output okay that basically means it is basically called as a comma separated output this is the class that I'm going to Define and uh even even in the documentation it is given in an amazing way okay so comma separated output and this will basically be inheriting the base output parcel okay now inheriting when I probably inherit right that basically means we are inheriting this base output par and we can call this along with an llm models here I will Define a parse method and inside this par I will take self as one keyword and whatever text the output that we have specifically getting which will be in the form of string format all we'll do we'll just write return text. strip dot dot split right and this will be a comma separated split understand one thing now this is what is the class that I've defined and this is just like an output parser by default the output parser is what you can probably see whenever I'm specifically using the chat models I'm I'm getting some kind of output right AI may be smart something it is giving in the form of sentence and it is adding a new line at the end but what I'm saying is that whatever output I'm getting I will take that output and divide all the words in comma separated okay something like that so for this again I will Define my template I will say you are a helpful assistant okay so this is my first message that is probably going as a template right so this becomes a system template the schema that we probably discussed right I will also give some information um let's say when the user gives any input okay you should generate five words okay in a comma separated list so this is what is my entire message okay the template I'm saying that whenever the user give any input you have to probably generate five words which should be comma separated okay so this is what I have specifically done okay now what will be the input what will be the text Will Define all those things okay and here I will say this will be my human template so what is the word that I'm going to probably give over here uh that will specifically defined over here right so here I will say Okay test uh you should generate five words synonym let's say synonym I'll just go ahead and write synonyms okay synonyms in comma separated so here will basically be my text whatever text I'm specifically given now I will go ahead and create my chat prompt now again from this chat prompt what I have to use I've already used chat prompt Pro template okay and inside this I will say do from message let's see that chat prompt template from from underscore messages okay now inside this from underscore messages I have to give two information okay whatever is the template right so first template is nothing but the system one so system information that I really want to give uh that system one is nothing but this normal template that I've defined and the second one will basically be my human template right whatever human message that I'm actually giving right and this will basically be defined as human uncore temp temp plates template right so once I execute it here you'll be able to see this is my chat prompt okay now in order to execute this obviously I have to use chain right because I have a prom template over here I have a human text I have this specific template also so how do I probably combine all these things that is what I'm actually going to show you over here so quickly first of all I will use this chat llm okay chat llm now see this is quite amazing and this is the best way of running chains so I will say chain is equal to whatever is my chat prompt so this is my chat prompt to this chat prompt I will give my API whatever API I'll write over here control V so I have to just give a or sign kind of thing right so this is getting chained up this symbol basically says that it is getting chained up and remember the order also okay or you can also initialize chat open AI over here now along with this I will also give my output parser the output parser will be the last one right so this will basically be my output parser comma separated output okay now see I've given each and everything over here one by one list by list right so here it is so once I probably execute it it will get executed so here what it is saying I'm giving this chat prompt the chat llm model is there and the output should be comma separated output which is getting derived from this particular class okay now here finally what I will do I will write chain do invoke and inside this I will again whenever I use chain I have to probably give it in a key value pair right colon something whatever the value is now in this case I will say the word is um intelligent let's say now I have to probably give in the form of text right so that is what I really have to give it right so this text is equal to in now let's see what is the output uh it is coming as okay there is some syntax issue that I have probably made because I have to close my dictionary over here now if I write chain. inor you can see that five words smart clever brilliant shop aute I don't know this specific word but here you'll be able to see whatever output that I'm probably getting right so if I probably remove this let's see okay this is how the output will look like okay AI message content this this this right but just by adding this output parsel you can see what an amazing message you're able to get and you're getting able to get the right thing that you specifically want this is what powerful a prompt template is all about right now this is done right and this is more than sufficient to know because more new things about PDF how to read PDF how to what is text iding and all we will discuss as we go ahead but now let us go ahead and try to create a simple chatbot okay simple chatbot I'll create an app.py and by using the simple chat bot we'll try to understand how things actually work and what all things we can basically do okay again here I'm going to probably use streamlet and I'll be writing the code line by line so let's go ahead and have a look so guys finally now we are going to develop our Q&A chatbot uh with all the concepts that we have probably learned I'm just not going to use all the concepts right now in this specific video itself because we should have probably uh 10 to 12 projects that are going to come up in the future in this series of playlist so there we are going to discuss about more projects as we go ahead right but now in this video I'm going to probably create a simple Q&A chatbot just with the help of open aai Lang chin and obviously use openi apis and llm models specifically to do that that here I'm also going to use streamlet okay so let's go ahead and let's see initially what all settings I need to do see this was Lang chain. iynb because I will be giving you this entire file uh again in the reference with respect to GitHub also so uh first of all in the requirement. txt I will be importing one more library because I need to install this Library this is the important Library itself which is python. EnV right so python d.v actually helps us to create or upload all our uh environment variables that we have created with respect to our application so here this is the library that I have to do it and just go ahead and install the requirement. txt I've already done that uh and this will be a specific task to you now we are starting over here so from lin. llms I have imported open aai then from EnV load load. EnV so as soon as I probably call this it will take all the environment variables from EMV file so here I've already created the environment variable I'm not going to show you again the environment variable because in short the environment variable will be something like this see I I I may have written like something like this open AP opencore API _ key is equal to this particular environment variable right so this is basically my open uh API key itself right so I'm going to probably use this uh in my application so here uh these are the basic steps that we will probably go ahead with now along with this what I'm actually going to do I'm also going to to import one more Library which is called as streamlet because we are going to use streamlet itself so let me go ahead and open my terminal and quickly let's go ahead and write pip install minus r minus r requirement. txt and then the installation will start taking place and the streamlet uh Library will also get installed Streamlight we are specifically using for a front-end application uh see it's it's not light only you have to use streamlet it'll be very much easy for me to probably create it and do the deployment because I'm also going to show you the deployment in the hugging face uh space itself right what is exactly hugging space uh space I will also discuss about all those things so quickly uh let's do this uh it'll probably take some time and then I will go to my app. Pui uh let me do one thing quickly uh let me go ahead and import streamlet also so I'll import streamlet as St okay so this will basically my streamlet itself okay so it'll probably take some time to download it let's see how much time it is going to take but again it depends on your internet speed and how fast your system is right my system is really really fast till it is taking time so for you it may probably take more time okay so let this installation take place till then I will go ahead and start creating our application now I will first of all create a function to load open AI model and get response okay get response so I will call this function something like definition um getor open AI response okay something like this and here I'm probably going to give since it is a Q&A chatbot so here I will have my question as my parameter which will be of a string type okay it can be a string type it can also be a numerical type so I will just keep it like this okay so this is done and here you can also see the installation is done so I will just close this now here as soon as I probably call this function what I really need to do I need to call my llm model so llm model I will say open AI okay open Ai and here I will go ahead and Define my model uh have I imported open AI yes I have imported model uh uh open itself so I will go ahead and write model uncore name is equal to and I will will Define my model I'll be using text Davin C uh this is one of the model that we have you can probably refer it so text Davy 003 and here I'm also going to Define my temperature temperature is equal to let's say5 Okay uh along with this uh I'll just go ahead and copy one more thing I will just set up my open API key also so I will set it up like by using this OS environment so here will be my first parameter okay so all this is done uh I think I need to also import OS okay so this is done in short what I'm doing is that I'm initializing my llm model OKAY in this code now the next thing is that I need to probably get my response so response will be nothing but llm directly how do I give a question over here I can probably give the question over here okay see I'm just creating a basic one then whatever things you really want to do from here you can probably do it try to create a own prom template try to use chain if you want try to do multiple things but just to start with I'm going to use a simple application where it is just taking an input and giving some kind of output it has no AI message set it has no human system message set no system message set also we have not given any prompt template also over here this just to give you an idea how things starts okay so now we will initialize in initialize our streamlet app okay now with respect to streamlet I will write STD do set underscore page underscore config so this is one of the function in streamlet which will actually help you to set the page title so I will just go ahead and write title is equal to I will say q& a demo okay Q a demo and this is done with respect to my uh and here I will set my another header the header will be something like Lang chain application something like this okay so I've given my header also with respect to this okay now I need to find out a way to get a user input okay uh if I get a user input then I should be able to submit the button and I should be able to get the text itself so first of all I will go ahead and create my submit button I will say St do button and here I will go ahead and write generate generate or ask the question something like this okay if ask button is clicked right if it is clicked that basically means if I write if submit okay if it is clicked this usually becomes true okay so if this is true it is probably going inside this particular function and here you'll be able to see s I'll just put a header and uh I'll say the response is okay and then I will probably write St dot right with respect to the response okay so this is what I am probably doing it okay I'm getting the response over here and with respect to this specific response I will probably this response is probably coming from here but still whatever is the input that input we are not able to capture it yet right because if we capture those input then only we'll be able to send that particular input somewhere right and for that also I may have to probably create another function so let's go ahead and handle the input part now so guys now what I am actually going to do over here is that first of all we'll go ahead and and capture our input text so let me go ahead and write over here input is equal to St do textor input because I'm going to use a text field over there and here I will probably be waiting for the response itself right so sorry from the request right so so here I will write input colon okay and I'll keep a space over here and I will just write key is equal to key is equal to input something like this so this will basically be my input itself okay now once I've done this okay once I've have done this I'm going to take this particular input and now call I hope you should know what we should call we should basically call this function right so this here I'm going to probably write uh not here itself uh so let me just write it over here and this input I'm actually giving it over here okay so this will basically be my input over here uh whatever input I'm probably getting it it'll just go ahead with respect to this particular question and I will probably get the response here I will just go ahead and write return response okay and then I will store this particular variable inside my response okay done see the way I probably got the input over here I sent this input to my get open AI response my open AI model has got probably loaded and then it is basically calling with respect to this llm you can either call predict message or predict functionality also uh you can also use chain you can use multiple things you can assign promt template in this particular function and all right and then finally you have S do Button as the button and if submit this is there okay now quickly let's go ahead and probably run it okay uh let me see whether if I directly call python app. Pui it will give us a error why because it is a stream L library right if it was flask I would have probably said okay it would have work ke now it says key error open API key okay so os. environment open API key load. EnV so guys one mistake that I have specifically done whenever I really want to call all the environment variables from EnV with the help of load uh this the specific library that is called as this this functionality which is load. EnV at that point of time I'll be using get EnV function and here I will just remove all the things brackets and probably call this function now I hope so it should work and I think we should not get any problem so Streamlight run app.py and here we have our entire application quickly it's running let's see um this is getting loaded and here we have right now probably I'll ask the question what is the capital of India right so I'll just ask the question over here the response is the capital of India is New Delhi um let's see what is generative AI right so I'll ask the question you'll be able to see that generative AI is a type of artificial intelligence that focuses on creating new data from existing data this this this is there still I'm I'm getting some kind of weird responses over here so that is the reason we'll also be using output parsers we'll make sure that we'll use conversation buffer memory we'll also Implement schemas like human message system uh human human system AI system um system messages all those things were there right all the schemas that part we probably discussed but this is a simple application that we are probably going to discuss with respect to this it is going to be quite amazing and uh you know this is just a basic Q&A chat bot uh wherein whatever questions you specifically ask like what is the please right write a poem on on please write a romantic poem I'll just give it as romantic poem on generative AI something like this because many people are now using this ask the question so here you can see gener way I knew love in my life your data driven hurt is perfect fit your algorithm so precise your knowledge is so wise so everything is over here now what I'm actually going to do is that I will go and show you the deployment part everything is working fine I will first of all login into the hugging face go to the spaces and create a new space because I'm going to probably do the deployment over here let's say I will say Lang chain Q&A chatbot okay I don't have to use license this will be a streamlet now in space Hardware like you have paid Hardwares also but I'm probably going to use a simple one CPU Basics 2v CPU 16GB and I will create this as public so that you can also refer it um let's see okay I will just remove this spaces please match okay this underscore is not there QA a chatbot I will go ahead and create the space now after creating the space uh there's couple of things that I'm probably going to do over here is that uh this is where this is just like a GitHub repository you know you if you probably go to the files you'll be able to see it now here I'm probably going to upload the file that I have okay uh but before that what I'm actually going to do I'll go to my settings okay and if I go down right so there will be something called as secret keys because this secret key I have to put it with respect to open AI so here no secrets are there so I will go and clear or click on uh new secret and you know that with respect to the new secret what I have to probably use I have to use open API key I will put it over here okay and now oops just a second open API key let me open this and I will put it over here okay and what I'm going to do I'm also going to upload the value okay so I'll not show you the value uh let me update this and let me come back and quickly and show you the next steps that we are probably going to do after adding the open AI API key uh you can see it over here in the secrets you'll be able to see this specific key now what I will do after updating that I will go to my app now again my entire application will start getting buil up now here you can see as soon as I add the open AI API you'll be able to see my application will start running now here I can probably ask question what is the capital of India okay and uh you can see that I will be able to get the response now clearly you'll be able to see uh I've been able to do the deployment in hugging pH spaces uh it was very much simple you can see the files over here itself on the app.py requirement. txt I had commented out all the codes with respect to EnV and all because soon as we add the secret variable as soon as this open a model is called it is going to take the open a API key from there and it is going to use it over here so yes this was with respect to the deployment and quickly we were able to also create a simple Q&A chatbot along with deployment so guys in this video we're going to create one Amazing llm Project which is nothing but PDF query with langen and cassendra DB uh cassendra DB will be probably creating in a platform which is called as data Stacks so if you have probably heard about this particular platform which is called as data Stacks which will actually help you to create cassendra DB in the cloud itself and why this platform is quite amazing because from this you will be able to perform Vector search and whenever we talk about this kind of documents or if you want to really create an Q&A applications from huge PDFs itself Vector search is the thing that you really need to implement now before I go ahead let's first of all understand the entire architecture we will be solving this entirely step by step what are the steps specifically that will be taken to probably complete this specific project that we really need to understand so let's begin with the architecture initially let's say you have a specific PDF this PDF can be of any size and any number of pages first of all we will read the documents and understand here we are going to use langin as I said because langin has some amazing amazing functionalities which will actually help you to perform all the necessary tasks to create this specific application now first we will go ahead and read the documents that is specifically the PDF and the first step usually when we whenever we work with this kind of data set is with respect to some kind of transformation we really need to do so after reading this documents we will convert this into various test chunks that basically means we'll split the data set into some kind of packets right so this text Chunk will be of some specific size based on the tokens that we are probably going to use so over here you can see some example reading the document and then we have divided this into some chunks then we will convert all this chunk into text embeddings now from here we will be specifically using open AI embeddings okay openai embeddings actually helps you to convert text into vectors now why you specifically require these vectors I hope you have heard about text embedding techniques in machine learning right there we have specifically used bag of words tfidf and many more things that is already present in my YouTube channel we have also used word to work average word to what are the main aim of all these techniques to convert text into vectors because once we probably convert into vectors we can perform various tasks like classification algorithms like similarity search algorithm and many more so that is the reason we will specifically be using openi embeddings which will be responsible in converting a text into vectors itself now once we convert every text into vectors we will also see this as text embeddings once we get this embeddings what we are specifically going to do now this will be quite amazing because understand if we have a huge PDF document right so definitely the vector size will keep on increasing so it is better we store entirely all this vectors into some kind of database and for this we are going to use Centra DB so in short what we are basically going to do is that we will take all the specific vectors and save it in a vector database here currently we are going to use cassendra DB now what exactly is cassendra DB so in order to understand about cassendra DB I have opened the entire documentation page over here cassendra aperture Apachi cassendra is an open source no SQL database and it can definitely be used for saving massive amount of data so it manages massive amount of data fast without losing sleep right so again understand this is a nosql database and for vectors kind of thing we definitely have to save it in this kind of database itself many bigger companies are basically using this cenda DB for this specific purpose so if you really want to read more about Apache cendra you can probably see over here Apache cendra is an open- Source nosql distributed database trusted by thousands of companies for scalability and high availability this is the most important point for scalability and high availability without compromising performance linear scalability and proven fall Tolerance on commodity Hardware or Cloud infrastructure make it as a making it as a perfect platform for Mission critical data now how we are going to probably create this specific database for that we will be using this data Stacks platform wherein it will actually help you to create this Vector cassendra DB so that you can store entirely all these vectors into this specific DB and at any point of time if a person is trying to query from this particular DB you will be able to get that specific response from that right and the most similar response that you'll be able to get it now that is the next step what we are basically going to do all these vectors we are going to save it in some kind of vector database as I said we going to use casser DB or we can also say astrab and this will be created in this data STS platform wherein you can actually perform Vector search now the next thing is that after you probably save entirely all your vectors in in the database itself then a human whenever a human tries to query anything that is related to that particular PDF document it is going to probably apply similarity search along with text iddings and is going to get that specific response so this this is the entire architecture that we are specifically going to perform in this specific project all the steps will be shown step by step everything will be explained in an amazing way along with the code and along with the explanation now let's go ahead and start our specific project for this PDF query with Lang chain and cassendra DB so guys now let's go ahead and implement this specific project I will be going step by step I will also be showing you how you can create the cassendra DB specifically in the data Stacks uh platform itself uh we'll be seeing step by step all the comment regarding this code and all is given over here I will also be providing you the code in the description of this particular video so first of all uh what exactly we are doing we are going to query PDF with astb and Lang chain uh it is basically powered and uh understand it is powered by Vector search so first of all you need to understand what exactly is Vector search so there is an amazing documentation that is given in the data stack documentation itself so Vector search enhances machine learning models by allowing similarity comparison of the embeddings embeddings basically means whatever text is basically converted into the vectors that is basically embedding right and over there you can definitely apply multiple algorithms right machine learning algorithms on the fly right as a capability of astrab vector search supports various large language models so large language models can be is very is supported in an amazing way in this the integration is very much smooth and easy right since this llm are stateless they rely on Vector database like Astro DB to store the embeddings see understand because uh when we say stateless that basically means what suppose if we have embeddings once we lose it we cannot again query it right so it is definitely require a database to probably store all these things and what you can do after that you can query any number of time so let us go step by step and let us see okay so first of all we need to create a database on astb so I will probably click this specific link everything is basically given over here for this we will be going to astra.com right so first of all it will probably ask you to sign in right and here you can probably sign it with your GitHub or with your Google account so here I'm going to go ahead and sign it with GitHub and probably once I probably sign in over here you will be able to see that uh I'll be providing you the link along with everything in the uh code itself right so it'll be very much easy for you so once you go to Astra data.com the next step is basically to create a database right so this database uh what kind of database we are going to probably create it will be serverless vector and this is specifically a cassendra DB okay so here I will probably give my database name let's say I want to do PDF query right so this will basically be my PDF query DB okay this will basically be my database name you can give anything as you want and here I'll be basically be giving Lang chain _ DB a key space name it should be unique the provider that you can specifically use you have multiple like Amazon web services Microsoft Azure but here I'm going to probably use Google Cloud which is the default that is selected in the next step we will go ahead and select the country region which is by default Us East one so as soon as you probably fill all this details and as you know that we are specifically going to use this Vector database itself because at the end of the day the algorithms that we probably going to apply it will be easy with respect to this kind of database right so finally we will go ahead and create the database now once how we create the database you will be able to see that my database is basically created over here right so this is what is my database that looks like right PDF query diving now if I probably go to my dashboard I've already created this kind of database a lot so let me consider one database which I have already created and over here some important information that you really need to take first of all I will go and click on connect okay so when I probably click on connect one some information you will definitely require one is generate token right and the other one is the DB ID so DB ID is basically present over here right the token is basically present over here now I'll talk about where this specific information will be required okay so here I will go with respect to my code now let's start our coding initially we will be requiring some of the important libraries like Casio data set langin open Tik toen so here I will go ahead and execute it and I will go ahead and install all the specific libraries so it will probably take some time right I have already done that installation so for me it has happened very much quickly now the next thing is that as we know that we are specifically going to use cass. DB so in Lang chain you have all these libraries which will actually help you to connect with cassendra DB and perform all the necessary tasks like text T meetings uh creating V vors and probably storing it in the database itself so here I'm going to probably import all these libraries from lin. Vector stores. cassendra I'm going to import cassendra along with this I'm also going to use this Vector store index wrapper it is going to wrap all those particular vectors in one specific package so that it can be used quickly then I'm also going to import open AI because open AI is the thing that we really need to use along with this we are also going to use open a embeddings which will be responsible for converting your text into vectors along with this if you want some kind of data set from hugging face you can also use this and one more important library that we are going to use is cashio now Casio actually helps you to uh probably integrate with the Astra DB right in Lang chain and it'll also help you to initialize the DB connection so all these libraries we are going to use I'm going to execute this step by step we going to probably see and this is the first step installing the libraries and initializing all the libraries that we are specifically going to use along with this what we are going to also import is one PDF which is called as Pi PDF 2 this will actually help you to read any PDF uh read the uh text inside the PDF itself so this is one amazing library to probably use okay so here I have basically used pip install Pi PDF 2 so let me just go ahead and execute it and inside this you will be able to see it shows requirement already satisfied because I've already installed over here then from PI PDF you're going to use PDF reader because this will be the functionality that will be used in order to to read the document here is the document that I have specifically taken so this is one budget speech PDF so this is the Indian budget that is probably of 2023 it's a big document with somewhere around 461 KB file it has around 30 pages so I'm going to specifically read this PDF and then convert into vectors store it in the database itself and then query from the database anything that you have any information about that particular PDF now let's go ahead with the setup okay now with respect to the setup you require three important information one is the astrab application token one is the Astra DB ID okay so where you can probably get this two information so go to your vector database uh Vector database in the data Stacks so here uh is what you have specifically logged in okay as I said inside your DB just go and click on connect here you need to click on generate token as soon as you probably click on generate token then you will be getting some code which looks like this this token you will specifically go getting so this will be probably found in your token Json file so it'll probably show you a Json file which will have this information okay the first information that you have over here is the Astra DB application token so here you can probably see it starts with Astra CS so what you need to do just click on the generate token and you'll be able to see it this is the first information you just need to copy and paste it over here the second information is Astra DB ID right Astra DB ID is nothing but this specific information that is your database ID where do you get it you just need to copy it from here so this is the information with respect to your astrab ID so this two information once you do it you paste it over here I've already pasted it and then you can also see that I've also used some open API key and this specific API key don't use this only because Ive made some changes I've already executed the code also okay so I'm going to take this three information this two information is basically used to connect to your Astra DB right which has a cassendra DB hosted over there in the cloud right and the other information is basically to use the open AI API features right so all this information is basically there I'm going to probably execute this and then we will go ahead and read our budget speech PDF so this is the first step according to this we are reading the specific document before that we have initialized everything with respect to this okay so once we specifically do this I will probably be reading this now after reading as I said we are going to divide all our content into some kind of chunks right so here is what chunks we are basically going to do now first of all I will read all the raw text so for this I'm going to use from type extension using concatenate I'm going to read from each and every pages I will extract all the text so here you can probably see for I comma page in enumerate PDF reader. Pages page. extract text Will basically take out all the text from those pages and it will concatenate in this particular variable that is rawcore text so once I probably execute this what will happen is that you will be able to get all the text inside this particular variable so you can probably see over here rawcore text has all the entire text so this is the entire text from that specific PDF right slash in basically means new line so this step is basically done just imagine before if we did not had this specific Library it was very difficult to read a PDF right and we have actually done this just with writing four to five lines of code now the next step is that we will initialize the connection to your database I have all my database information right like uh token ID and the database ID I'm going to use that cashio cashio is basically used as a library over there for initializing of this particular database so cashier. init here I'll be giving one parameter which is called as token which will be nothing but astb application token and then your database ID which is nothing but astb ID right so I've taken this two information I will execute this you'll get some kind of warnings so don't worry about the warnings it is just like it is showing you some kind of warnings okay with respect to some drivers issues and all but this will basically get executed and now I have uh basically initialized my DB itself right now we are going to create the Lang chain embeddings L LM objects for letter use so for that I'm going to use I'm going to initialize open AI with my open AI key and embeddings also open AI embeddings with my open a key so I have my llm I have I have my embeddings okay now is the main step I need to create my lch Vector store so over here this is what we are basically going to create now right and for that you know we have initialized cendra right we have we have imported cendra now what will do is that in this cassendra we will provide three important information what is the kind of embeddings we are going to use what is the table name inside this particular database session none keyp space none so this is the default parameters we have specifically used QA mini demo is my table name okay just like a question answer table name and what kind of embeddings we are going to specifically use that basically means whenever we store any whenever we push any data in my cassendra DB in my Astra DB itself what it is going to do it is going to probably convert all the text using this embeddings into vectors right and this is the embeddings that we have initialized over here so here is the next step we will go ahead and execute this so this is my Astra Vector store but still I have not probably converted my text into vectors only when when I'm pushing my data inside my DB that time this entire embeddings will probably convert that particular data into vectors then what we are specifically going to do is that we will take this data and we will try to uh we'll take this entire data we'll convert into checks uh chunks and we'll also do the text embedding right text embedding while inserting right so here you first of all we are dividing the data or the entire data entire document into text Chunk so for this we are using character text splitter which is basically present in Lang chain. text splitter we need to split the text using character text splitter it should not increase the token size so here I've given character text splitter I'm saying use the separator slash in use chunk size some chunk size of 800 characters chunk overlap can be 200 and how much is the length with respect to that specific length you can probably provide it over here right and once I probably do this you can see text splitter. split text here you will be able to get all the text and if I see the top 50 text you can probably see that I'll be able to see all the top 50 text over here right all the data itself this is amazing right and this is basically from the PDF right all the data all the data right it is basically taking the top 50 right and understand the token size is basically over here as the chunk size is somewhere around 800 okay now this is done we have the text I'm going to just use top 50 and probably store it in the vector database to see if everything is working fine now how to add this specific text now what will happen when I add this text inside my Cassandra DBC axtra Vector store what is this this is basically initialized with respect to the cendal library right so here you'll be able to see that I have used embeddings so now when I'm inserting inside the cassendra DB what it is going to do it is going to apply this specific embeddings also so that is the reason you'll be able to see that when we write extraor Vector uncore store. addore text and I'm taking the top 50 top 50 texts over there this will also perform embeddings so that basically means if I see over here it is going to perform this task and it is going to insert in the Astra DB which is having that cassendra over there right so it is going to do this both the steps with respect to this particular code so we are going to add this text and then we also going to wrap wrap this entire inside a wrapper okay so these are the information this is the index that we'll be getting with respect to those text so once I proba executed you'll be seeing that in the same database it is going to insert all this headlines okay now finally let's go ahead and tex it that basically mean I have my vectors inside my database now it's time that we just query and we ask some kind of questions now I have read this entire PDF guys I could find out some of the question like what is the current gbd how much agriculture Target will be increased and all so I will take this particular example and let's say I'm writing first question is equal to True while true if first question I'm just say that input okay it will just ask like what kind of question you want to type else uh it is just asking you to uh put more questions if I write quit it is going to break otherwise it is going to continue now see this is the most important as soon as I give my first question it will go ahead with v Astra Vector index and it'll query whatever query text we are specifically using and the llm models that we are specifically initialized and after that we will be getting the answer along with this we'll also be providing some information right like for Doc score or similarity Source score like some other information also right so let's go ahead and execute it and as I said I'm going to use this question okay how much is the agriculture Target to be increased and what focus it will be okay so I'm going to paste it over here I'm going to press enter so as soon as I press enter you can see that it is now taking the information see this um you can probably see over here we are quering this particular DB right and it's going to give me the top four results okay so here you can see that agriculture credit Target will be increased to 20 lakh CR with the focus on animal husbandry da and Fisheries right why it is giving only this much data because I've told that take the 84 characters or 84 words 84 characters text still there and probably give the results right if I increase this it'll give you more result along with this you can probably see that it is giving me stop K queries that is the four query Hyderabad will be supported as Center of Excellence some more information but the most suitable answer that you have specifically got is this one right and this is what probably if you go ahead and search in the PDF if you give the same question you will be able to see the same answer right along with this probably if I want to probably see what is the current GDP if this information is present over there it'll also be giving you that specific answer it'll just do the similarity search right so here you can current gbd is estimated to be 7% isn't it amazing now you can probably take any huge data because at the end of the day you specifically using DB right and finally if you want to quit it I will just go ahead and write quit and this is basically quit right so in short we have performed each and every step now this is what which is happening whenever a human is giving an text query text emings will happen and based on that similarity search and then you'll be probably get the output right and this is the entire steps We have basically done step by step so guys yet another amazing video on generative AI where I will be specifically discussing about llama 2 uh Lama 2 is an open-source model uh again it has been created by Facebook or meta and you can use this specific model even for commercial purpose uh so this is quite amazing this is an open-source llm model altogether I will try to show you how we can use this create an end to endend project also in this specific video so there are many things that are going to happen and probably whatever topics that I teach going forward that is related to generative AI I will definitely follow this kind of approach so that you also get a brief idea about all these kind of models so what is the agenda of this particular video the agenda is that we will get to know about Lama 2 then we will go ahead and see the research paper where I will be talking about the key points uh about the Lama 2 model again since this is an open source and uh soon Lama 3 is also going to come up so that is a reason I'm going to create this particular video I really want to be in sync with all the open source llm models that are coming up right then we'll go and apply and download the Llama 2 model so we'll be seeing like how we can actually use this particular model in our project also so for that purpose I will be downloading this model you have to also apply this in the meta website itself and there is also one way how uh we can also use it directly from hugging face so I will also show you that and after that we will try to create an end to end llm project and this will be a Blog generation llm app uh all these topics I will be covering it I know it'll be a little longer video but every week one kind of this kind of video is necessary for you all and since 2024 I have the target I really need to teach you gener in a way that you can understand it and use it in your industries also so I will keep a Target so every video I'll keep a Target like this target for this particular video is, L likes not thousand lcks but thousand likes and comments please make sure that you write some comments and I'll keep the target to 100 okay so this will actually motivate me this will probably help this particular video to reach to many people through which they can actually use this and entirely this is completely for free which will also be beneficial for you and I my aim is to basically democratize the entire AI education okay so let's go ahead and let's first of all start with the first one that is introducing Lama 2 what exactly is Lama 2 Lama 2 is an again open source a large language model it can be it is used and it is uh available for free for research and commercial purpose you can actually use this in your companies in a startup wherever you want to use it okay now let's go ahead and read more about it so inside this model uh it has till now Lama 2 has released three different model size uh one is with 7 billion parameters the other one is 13 billion parameters and the the best one is somewhere around 70 billion parameters uh pre-training tokens is taken somewhere around 2 trillion context length is 4096 uh again when I say that if I probably compare most of the open source models I think Lama 2 is probably very good we'll be seeing all those metrics also so here you can see Lama 2 pre-trained models are trained on two trillion tokens and have double the context length than Lama one it's fine tune models have been trained on over 1 million human annotation okay and now let's go ahead and see The Benchmark and this is with respect to the the benchmarking with all the open source models so it is not comparing with chat GPT sorry GPT 3.5 GPT 4.0 or Palm 2 okay so all the open source models uh here you can probably see this is the three version 7 billion 13 billion 65 billion 70 billion right all Lama 2 right llama 1 was 65 billion one uh one model it had over there so if you see Lama 2 with respect to all the metrix is very good MML that is with respect to human level understanding Q&A all all the performance metrix is superb natural language processing gsmk human evalve in human evalve it is probably having a less when compared to the other other open source models so here you can see in human uh human Val human eval human eval basically means with respect to writing code code generation there it has a lot of problems so here you can see 12.8 18.3 it is less it is less when compared to all the other open source models over here and there are also some other parameters you can probably see over here with with respect to different different tasks you can see the performance metrics okay so this was more about the model now let's go ahead and probably and this is one very important statement that they have come up with we support an open Innovation approach to AI responsible and open Innovation give us all a stake in the AI development process so uh yes Facebook is again doing a very good work and then soon they also going to come up with the Lama 3 Model now let's go ahead and see the research paper so here is the research paper the entire research paper now see uh what you should really focus on a research paper you know in research paper they'll be talking about how they have actually trained the model what kind of data points they have they actually taken in order to train the model and all right so over here you can see that um in this work we developed and release Lama 2 a collection of pre-trained and fine-tune Lun language models ranging in scale from 7 billion to 70 billion parameters so if you talk about parameters it is somewhere around 7 billion to 70 billion our fine tune llms called Lama 2 chart are optimized for dialog use cases just like a chat bot and all right uh more information you can probably see over here what is the pre-training data see so they have told that our pre-training data includes a new mix of data from publicly available sources which does not include data from meta products or Services we've made an effort to remove data from certain sites known to contain a high volume of personal information about private individuals now this is where ethics comes into picture they really want to use this AI in a responsible way right so we trained on two trillion tokens uh and obviously for all these things you have to use Nvidia GPU okay I know guys it is boring to read the research paper but it is good to have all this specific knowledge so please keep your energy up watch this video till the end then only you'll be able to understand things right not only here because later on you'll be having other models like Mistral I'll probably create a video on Mistral also in the upcoming video right so everywhere with an end to end project everything I will take this format let me know know whether you're liking this format or not so training data we adopt most of the pre-training settings and model architecture from Lama one we use the standard Transformer architecture now you can understand how important Transformer is right most of the open source model are based on Transformer architectures itself right we trained using adamw Optimizer okay with so and so parameters we use consign learning rate schedule with so and so and here you could probably see with respect to the performance like how well it was training BPL process tokens how many tokens was actually done with respect to all the different varieties of llama model now this is basically the training loss you can probably see training loss for Lama 2 okay this is also important training hardware and carbon footprint it is basically saying that how much it is using they used Nvidia a100 I've seen this GPU it's quite amazing it's very huge okay and it is very fast also but again with such a huge amount of data it is also going to take time right so all these things are there you can also see time how much time it has basically taken how how many hours 70 billion this many number of hours power consumption this this all information is there right this is good to have right all all you should know like we just taking more energy and all right and here um with respect to the uh llama 2 you can probably see with respect to Common reasoning it is very good when compared to all the other models open source model World Knowledge reading comprehension math mlu math it is little bit less you can see over here when compared to the other model I think it is still 35 itself but remaining all it has basically come I think this 35 is also greater than all these things right MML is very much good it is able to achieve till 68.9 Google gini has said that it is reach to 90% okay but again this is the thing that you really need to know uh some more information fine tuning fine tuning also okay this is very much important guys it has it has used this uh reinforcement learning okay where uh and with human feedback so our R lhf basically means reinforcement learning with human feedback and this is what chat GPT is also trained with right so uh definitely I think as we go ahead as we go ahead and see Lama 3 and all it is going to give us very good accuracy I guess okay so superv fine tuning uh if you go ahead and just check how generative AI how llm models are trained you'll be able to get a video on this I created a dedicated video where I explained about supervised fine tuning how does supervised fine tuning happen what how does uh rhlf happens right reinforcement sorry R lhf human feedback happens all those things I've actually explained so here you can see some of the prompts right a poem to help me remember the first 10 elements on the periodic table hydrogen come first as the element one helium is second for balloons this this I want you to roast me now see this statement is also very important right so uh I want you to roast me I want you to make it particular brutal swearing at me so it is saying I'm sorry but I cannot comply with that request using language or intentional hurting someone feelings is never expectable so some kind of feelings they're trying to bring inside all these kind of models okay uh sft annotation is basically there you can probably read all these things this is good to have good to learn how this reinforcement learning with human feedback was done and all everything is given over here so uh this was all about the research paper still there are many papers to go ahead you can probably go ahead and check it out uh there is a concept of reward modeling also reward is also given right the parameters they have used two separate parameters over here and various kind of test is basically done so this was all the information about this now the next thing is that how you can go ahead and apply or download this specific model just click on download the model over here so the third part provide all the information over here and what all things you specifically required like Lama 2 and Lama chart code Lama Lam guard so go ahead and just put all this information and click on submit after submitting probably it'll take 30 minutes and you will start getting this mail okay you all start to set building with code llama you will also be getting the access from Lama 2 see you'll be getting this entirely right model weights available all the models weight will be given to you in this specific link you can click and download it also if you want so that you can use it in your local or you can deploy it wherever you want okay so this kind of mail you'll be getting uh Lama 2 commercial license all the information with all the info over here and these all models it is specifically giving again I told you 70b 70b chat why these two models are there this is specifically for Q&A kind of application dialog flow application I can basically say uh remaining one can be used for any kind of task uh in a complex scenarios and all okay so once you do this the next thing is that you can also go to hugging face in hugging face you have this Lama 270b chat FF and there is the entire information that is probably given about the entire model itself you can probably read it from here with respect to this Lama 2 is a collection of pre-trained this this information is basically there you can also directly use it if you want the code with respect to Transformer you just click on using Transformer you'll be able to get this entire code where you can directly use this also okay what we are basically going to do I'm not going to use 70 billion parameters since I'm just doing it in my local machine with the CPU itself okay so what I will do I will be using a model which is basically uh it is basically a quantized model right with respect to this same llama model it is called as Lama to 7B chat gml so if you go ahead and see see this uh you'll be able to see that this particular model you'll be able to download it and you'll be able to use it it is just like a good version but uh less parameter versions right so when we say contage that basically means uh this model has been compressed and probably provided you in the form of weight so what you can do any of these models the recent model what you can do over here which is of 7.16 GB you will first off all download it so I've already downloaded it so I'm just going to cancel it over here okay because I've already downloaded it over here okay so I will do that specific download uh over here and then you can probably go ahead and start working on this and start uh using this and now how you can probably use it I Will Show You by creating an endtoend project so for creating an NN project what are the steps uh again the project name that I've already told is basically a b blog generation llm app here I'm going to specifically use this open-source llama Lama 2 model again I'm going to use the hugging face API also for that uh and let's see how the specific uh step by step how we'll be doing this specific project so let's go ahead and let's start this particular project okay guys now let's start our blog generation llm platform uh application so the model that I had actually generated over here you can probably see the model over here in the bin size and this is the size of the model is over here I'm going to specifically use in my local machine for my local inferencing and all so over here what I will do I will go quick quickly go ahead and open my VSS code so my vs code is ready over here okay now let's go ahead and do step by step things that we really need to do first of all I'm just going to create my requirement. txt file requirement. txt file and now I will go ahead and open my terminal so I will go ahead and open my command prompt and start my project okay so quickly I will clear the screen I will deactivate the default environment cond deactivate okay and we'll do it step by step so first step as usual go ahead and create my environment cond create minus P VNV environment I hope I've repeated this specific step lot many times so here I'm going to create cond create minus pvnv with python wal to 3.9 y okay so just to give you an idea what how exactly it is going to run run how things are basically going to happen uh step by step we'll understand so first of all we are creating the environment and then we will go ahead and fill our requirement. txt now in requirement. txt I'm going to specifically use some of the libraries like sentence Transformers C Transformer fast API if you want to specifically use fast API I I'll remove this fast API I think uh I will not require this IPI kernel so that I can play with Jupiter notebook if I want I can also remove this I don't want it langon I will specifically using and streamlet I'll be using okay so first of all I will go ahead and create cond activate Okay cond activate uh venv so we have activated the environment and the next thing is that I will go ahead and install all the requirement. txt okay and in this you don't require uh okay so okay I've not saved it so requirement. txt is not saved now in this you don't require any open AI key because I'm just going to use hugging face and from hugging face I'm going to probably call my model which is basically present in my local so here is the model that I am going to specifically call okay so once this installation will take place then we will go ahead and create my app.py and just give you an idea like uh I'm going to basically create the entire application in this specific file itself so quickly uh let's go ahead and import our streamlet so till the installation is basically happening I will go ahead and install streamlet Okay as St and then along with this I will also be installing Lang chain. prompts because I'm also going to use prompts over here just to give you an idea how things are going to happen it's going to be very much fun guys because open source right it it's going to be really amazing with respect to open source you don't require anything as such and then I'm going to basically write prompt template because we need to use this from Lang chain then I'll be also using from Lang chain Lang chain do llm I'm going to import C Transformer okay why this is used I will just let you know once I probably write the code for this okay so three three Transformers also I'm going to basically use over here so this is going to be from okay so C Transformers prom template and St for the streamlet I'm going to specifically use the first thing is that I will go ahead and write function to get response from my um llm uh llama model right Lama 2 model I'm going to basically use this okay still the installation is taking place guys it is going to take time because there are so many libraries I've been installing okay so I'll create a function over here let's create this particular function later on okay now after this what I'm actually going to do is that we'll go ahead and set our streamlet right setor pageor config see now many people will say streamlet or flask it does not matter guys anything you can specifically use streamlet why I'm specifically using is that it'll be very much easy for me to probably create all the things right the UI that I want so in a set page config I'm going to basically use page title generate blogs page icon I've taken this robot icon from the streamlet documentation layout will be Central and uh initial sidebar will be collapsed okay so I'm not going to open the sidebar in that specific page now I will keep my ht. header so ht. header in here I'm going to basically generate my blogs right so generate the blogs and I'll use the same logo if I want so it looks good okay so this is the next thing I will probably this will be my head over here first of all I will create my input text okay so input text field right and this will basically be my input text field and let me keep it as a um a text area or a text box whatever things is required so I will write go ahead and write St do st. input textor input okay so this will basically be my St so let's see everything is working fine why this is not coming in the color okay still the installation may be happening so over here I'll go ahead and write this I will say enter the blog topic right so if you just write the blog topic it will should be able to give you the entire blog itself with respect to anything that you want okay so done the installation is basically done over here you can probably see this good I will close this up now I'll continue my writing the code so I've created a input box now the other thing that I really want to create is that I'll try to create two more columns or two more Fields below this box okay one field I will say that how many words you specifically want for that blog okay so over here creating two more columns for additional two Fields additional two field okay so here first of all will be my column 1 let's say column 1 and column 2 I will just write it like this and here I will say St do columns and uh here I'll be using I'll be giving right what should probably be the width like let's say 5 comma 5 if I'm giving you'll be able to see that the width of the text box of width of the column that I specifically have I'll be able to see it okay I'm I'm just creating that width for that columns okay now I'll say with column one whenever I probably write anything in the column one or select in anything in the column one this will basically be my number of words okay number of words and for here I will be creating my St do text input and this text input will probably retrieve the details of number of words okay so here I have specifically number of words great now the next column that I specifically want the detail so for whom I am actually creating this particular blog I want to probably put that field also so with column 3 I will probably create something like this I will say okay fine um what blog style I will I'll create a field which is basically called as blog style okay now inside this blog style what I am actually going to do sorry not column 3 column two because I've created those variable over there okay so the blog style will be basically be a drop down so I will say St do select box okay and I will say what box this is specifically for so that first message I will say select write writing the blog for for okay so this I'm basically going to say that okay for whom I'm going to write this particular blog okay and with respect to this I can give all the options that I really want to give okay so for giving the options I will also be using this field so let's say the first option will be for researchers whether I'm writing that particular block for researchers or for data scientist okay data scientist or I am basically writing this block for for common people okay common people so this three information I really want over here and this will basically help me to put some Style filing in my blog okay that is the reason why I'm basically giving over here okay and by default since we need to select it in the first option so I will keep it as index as zero okay so here is all my stylings that I've have specifically used so if you want to probably make it in this way so you'll be able to understand this so this will be my column one and this is basically be my column two okay and then finally we will go ahead and write submit button submit will be St dot button and this will basically be my generate okay so I'm going to basically generate this entirely uh generate is just like a button which will basically Click by taking all this particular information so from here I'll be getting my input from here I'll be getting number of words from here I'll be getting my blog style okay all this three information now this will actually help me to get the final response here okay so I will say say if submit okay if submit I have to call one function right and what will be that specific function that function will return me some output okay and that output will be displayed over here now that function I really need to create it over here itself let's say I will say get llama response okay so this is basically my function and this I will create in my definition and what all parameters I specifically require over here right this three parameters right and uh if I probably call this function over here what are the parameters that I'm going to write over here is all these three parameters so first parameter is specifically my text input input text the second parameter that I'm actually going to give over here is number of words the third parameter that I really want to give is my block style so like what block style I really want okay so all this three information is over here so this will basically be my input text okay uh I'll write the same name no worries number of words and third parameter is basically my block style so all these materials will be given in the description if you're liking this video please make sure that you hit subscribe press the Bell notification icon hit like again just to motivate me okay if you motivate me a lot I will create multiple contents amazing content for you okay now here is what I will be calling my llama model right l Lama model Lama 2 model which I have actually downloaded in my local and for that only I will be specifically using this C Transformers right now if I probably go ahead and search in Lang chain Lang chain see whenever you have any problems related to anything as such right C Transformer C Transformer go and search in the documentation everything will be given to you so C Transformer what exactly it is it is it is over here it is given over here or not here let's see the documentation perfect so here you can see C Transformers the C trans Library provides python binding for ggm models so gml models the blog gml models whichever model is basically created you can directly call it from here let's say in the next class I want to call mistal so I can go ahead and write my model name over here as mist and it'll be able to call directly from the hugging phas okay um not only hugging face but at least in the local uh if you have the local if you want to call it from the hugging face then you have to probably use the hugging face API key but right now I don't want to use all those things so I want to make it quite simple so CC Transformers and here I'm going to basically write my model model is equal to and this should be my model path right which model path this one model slash this one right so here you can probably see this specific name V3 Q8 Z bin okay so I'm going to to probably copy this entire path and paste it over here okay so this will basically be my model and inside this what kind of model type I want there is also a parameter which is basically called as model type and in model type I'm going to basically say it is my llama model okay and you can also provide some config parameter if you want otherwise it will take the be default one so I'll say Max newcore tokens is equal to 256 and then the next one will basically be my temperature colon 0.01 let me keep the temperature point less only so I want to see different different answers okay so this is done uh this is my llm model that I'm basically going to call from here and it is going to load it okay now after my llm model is created I will go ahead and write my prompt template because I've Tak taken three three different information so template here I will go ahead and create this will be in three codes if you want to write it down because it is a multi-line statement and I will say write a blog write a blog for which style right blog style for whom for this specific blog style for researchers for freshers for anyone you can write right or I'll say job profiles I can for researcher job profile for fresher job profile for normal people job profile right so something like this job profile for a topic which topic I'm going to basically say this will be my number of words sorry not number of words this will be my input text so this is how we basically write prompts within how many words the number of words okay this many number of words I'm going to basically write this okay so this actually becomes my prompt template entirely okay this is my entire prompt template write a blog for so and so for block style this this this to make it look better what I will do I'll just press tab so that it'll look over here okay so this is my template that I'm probably going ahead with I've given the three information blog style input text number of words everything is given over here now finally I need to probably create the prompt template okay so for creating the prompt template I'm going to use prompt is equal to prompt template and here I'm going to basically give my input variables so input uncore variables and inside this I'm going to basically write first information that I want what kind of inputs I specifically want right uh whether I want um this block style so for block style I can just write style second one I can probably say text third one I can basically say ncore word so this will basically be my three information that I'm going to provide it when I'm giving in my prompt template okay and finally uh this is my input variable this next parameter that I can also go ahead with I can provide my template itself what template I want to give so this will be my template over here now finally we will generate the response from the Lama model OKAY Lama 2 model which is from gml okay so here what I'm actually going to do I'm going to basically write llm and whatever things we have learned in Lang chain till now prompt dot prompt. format and here I'm going to basically use email sorry email what are the information that I really want to give over here prompt. format so the first thing is with respect to style the style will be given as block style so I'm going to basically write blog undor style okay the next information that I'm probably going to give is my input text input text is equal to not input text text is equal to input text I have to give text is equal to input undor text and the third parameter that I'm going to give is my ncore words which will basically be by number of words done so this is what I'm specifically giving with respect to my prompt uh and what llm will do it will try to give you the response for this and then we will go ahead and print this response and we will return this response also okay response response okay and what we'll do we will go ahead and return this response so step by step everything is done now I'm going to call this get Lama response over here here already is done now let's see if everything runs fine or not uh hope so at least one error will at least come let's see so I will delete this and let's go ahead and write over here to run the streamlet app all you have to do is just just write streamlet Run app.py Okay so once I probably execute this you'll be able to see this is what is my model but still I'm getting a model streamlet has attribute no head okay so let's see where I have specifically done the mistake because I think it should not be head it should be header okay I could see the error header okay fine no worries let's run it baby let's run this again stream L run app.py no I think it should run this looks good uh enter the block toping number of words researchers writing the researcher blog data scientist common people so let's go ahead and write about large language model so 300 words so number of words I will go ahead and write 300 I want to basically write it for common people and we will go ahead and generate it now see as soon as we click on generate it is going to take some time the reason it is probably going to take some time because uh we are using this particular in my local CPU but we got an error let's see key error block style it seems so I will go to my code block style block style block style so one minor mistake that I have specifically done over here so what I will do is that I'll give the same key name so that it does not give us any issue okay so this will be my input text and number of words the thing is that whatever things I give in that prompt template the input variables should be of that same name okay so that is a mistake I had done it's okay no worries so let's go ahead and and execute it now everything looks fine have assigned the same value over there number of words number of words so here also I'll go ahead and write number of words block style input text and this also should be block style the name I'm giving same right for both prom template and this okay so I think now it should work let's see so go ahead and write this and now my page is open opened now I'll go ahead and write large language models and it will probably create my words so this will be 300 I want to create it for common people let's generate it as I said that the output that I'm probably going to get is going to take some time because I'm running this in local CPU um let's say if you deploy this in the cloud uh with respect to if there are GPU features then you will get the response very much quickly so so just let's wait uh till then uh we get the output hardly but I think it is 5 to 10 seconds Max and since I've told 300 wordss it is again going to take time so let's see the output once it comes so guys it hardly tookes 15 seconds to display the result so here you can see that large language models have become increasingly popular in recent year due to the in due to the ability to process and generate humanlike languages it looks like a good blog you can also create any number of words blog itself Now understand that I have a good amount of ram my CPU has lot of cores so I was able to get it in 15 seconds for some of the people it may take 20 seconds it may take 30 seconds now you may be asking Kish how can you specifically reduce this time is very much simple guys we will probably do the deployment in AWS or any other Cloud Server itself which I will be probably showing you in the upcoming videos and there you'll be able to see that how with the help of gpus the inferencing also becomes very much easy not only that we'll also see how we can probably fine-tune all this data set with the OWN custom data itself guys yet another amazing llm project for you all now this llm project will be quite amazing because from this like this is just like a base you can probably create any kind of app on top of it you can create text summarizer you can create a quiz app or you can create any other app itself that is probably something related to text right so what is the main aim of this particular project is that from this project you will get all the guidance that is probably required to create that production grade application whenever you specifically work in the companies why because we are going to also include Vector search database and this is where you'll understand the power of the vector search database whenever you work in any NLP project something that is related to text you try to convert those text into embeddings or vectors if you have a huge vectors you you cannot just store it in your local machine you probably are requiring some kind of database and specifically with respect to vectors or embeddings V Vector DB is very super beneficial why because you can probably apply some of the important algorithms like similarity search or you can also uh apply any other algorithms that is related to text it can be text classification very much quickly by just squaring it from the vector database and getting the right kind of output so all these things we are basically going to cover it will probably be a longer video because every step by step I'll probably show you I will also write the code in code in front of you wherever any documentation is probably required I will also show you all those things so yes without wasting any time let's go ahead and probably see this project my main aim is basically to teach you in such a way that you get the right kind of knowledge and this you apply it in your company and nowadays many companies are specifically asking interviews regarding Vector DB they asking related to open a llm models and many more so let me go ahead and share my screen and as I said we will be doing completely from Basics right so here is my vs code I have a document over here budget speech. PF I am probably going to take this particular document upload it in my Vector DB right and then ask any kind of queries from it convert that into a quiz app right let's say this is a general knowledge book I can probably convert this into a quiz app with four options and get the right kind of answer from it right so this is what I'm planning to do other than this any idea you have you can probably do it on top of it right so first first thing first what is the first thing that we really need to do over here is that create a environment right and this is in every project I at least make you do this because it is super beneficial because at the end of the day with respect to every project you need to probably create a separate environment so in order to create an environment I will go ahead and write cond create cond create minus p v andv will be my uh environment name and then here I'll basically going to use Python 3.10 right so once I execute it it'll ask me for an option whether I need to install or not I will just say why and go ahead with the installation so this is the first step that we should specifically do right and uh it is important step because at the end of the day you should definitely create a different environment don't always work in the same environment whenever you are actually working in this kind of projects the second thing that I'm probably going to do is that create my requirement. txt requirement. txt the reason because whenever I'm using an lmm model or anything as such I have to probably install a lot of packages so over here first of all I will go ahead and cond activate activate this specific environment V NV slash okay so this is done the environment is activated and we are ready to go right now from my requirement. txt what are things I'm basically going to use I'm going to to probably note down all the requirements over here the libraries that is unstructured Tik toen pine cone client P PDF open aai Lang chain pandas numai python. EnV and at the end of the day guys uh I would always suggest you to please understand about Lang chain Lang chain is an amazing Library it has lot of power lot of functionalities which you can specifically do the community is huge and many many companies are specifically using it okay so requirement. txt has been saved so I will quickly go ahead and install this requirement. txt so probably it may take some time and before that uh since it is probably installing what I will do I will also go ahead and create my EnV file right so in this ENB file what I'm actually going to do I'm going to put my open API key so quickly I'll create my open AP API key save it and start using it okay so this will basically be my open API key in the EnV so that I can basically load it so along with this python. EnV is also there so let's wait till the all the libraries has been installed okay so this is the initial steps that we should specifically do right our environment is ready we have installed all the libraries that is probably required we have also kept our open AI key because at the end of the day I'm specifically going to use Lang chin you can also do it with hugging face if you want but I will try it with open AI because the accuracy is pretty much better in this okay now the next step uh what I'm quickly going to do is that quickly create one file and here I will just show you test ipynb and this will basically be my ipynb file itself and here I'll be showing you the entire code later on you can probably convert this into an end to-end project you can probably create a streamlet app but here is the main thing that I'm probably going to show you by executing step by step and and what all things are specifically required to create this app again understand what I am planning to do right so I will just show you over here first of all let me just clean this screen and what is my entire agenda like what I really want to create as an llm application over here so I have a PDF okay I have a PDF so this is basically my PDF you can also say this is a data source it can be a GK book it can be a maths book it can be anything right I will will first of all load this document right once I load this document or read this document what I am going to do is that I'm going to convert this into chunks right because we cannot open AI hugging face models they have some restriction with respect to the Token size so I'm just probably going to create chunks and this is what we say it as text chunks right after this I'm going to use open AI embedding okay and this embeddings will be responsible in converting all this text CHS into vectors right so this will basically be my vectors I hope you know what exactly is vectors a numerical format for different different text right so this will specifically be my vectors and this I'm going to basically do with open embeddings further this vectors needs to be stored in some Vector search DB so here I will put all these vectors in some kind of vector surge DB now why this DB is required because at the end of the day whenever a human being queries any inputs right because of this Vector search DB here we can apply similarity search right and probably get any kind of info that I specifically want so this is my what my entire architecture of the specific project looks like right and here this Vector search DB I'm probably going to use something called as pine cone and they have lot of DBS I will talk about the advantage and disadvantage there is some amazing DBS called as data Stacks where they specifically use cassendra DB Pine clone is one right we'll see all the documentation page with respect to this okay so step by step I'm going to basically do this and you can actually do it for any number of pages one more thing that I'm probably going to install is IPI kernel since I'm going to work in my Jupiter notebook okay so this all steps are basically happening it is very much good and we are able to see this okay so let this installation happen and then I will set up my kernel okay so these are the initial steps that we really need to focus on and uh understand this project will be the base to create any kind of chatbot application mcqs quiz apps okay question answering chat Bots not only question answering chat Bots text summarizer anything that you probably want right or you can also basically say it as a chat B that gives you specific answer with respect to specific domain right with respect to the data that we have so all these things are done now I'm going to probably select the kernel V EnV python 3.0 right I'm going to save this perfect now the first step as usual I will go ahead and import start importing libraries and now we will do it completely step by step okay so what all things we basically require I'm going toire open a I'm going to import Lang chain uh apart from open and Lang chain what I'm going to also going to do go ahead with pine con I will talk about Pine con more when I probably show you the documentation apart from Pine con I'm going to basically go to Lang chain okay and I'm going to basically use something called as document loader document loaders will basically be responsible for for loading any kind of documents it can be a PDF file and all so for PDF we specifically use something called as P PDF I can also use directly Pi PDF loader but since my PDF is inside the directory I'm going to use Pi PDF directory loader okay so this is the next thing now from the next thing what we need to do is that as soon as we load any PDF we will get all the documents we have to basically do uh text splitting right because we really need to convert those into chunks we cannot take the entire token right there will be a restricted token size right like uh recently open has come up with the open 4. 4. o turbo right so I think it is GPD sorry GPD 4.0 turbo there 188 128k is the token size right so for that I'm going to basically use from Lang chain dot text spitter I'm going to probably import recursive character text spitter you can also use any other based on this right my always suggestion would be that go ahead and check out the documentation with respect to all the libraries that I'm probably uh uploading right now the next thing is that whenever I probably convert this into chunks right the next thing that I need to probably convert that into vectors and for that I'll be using some kind of embedding techniques so over here we are going to basically use do embeddings doop so it is embeddings do openai and we are going to import open AI embedding so open AI embeddings is a technique wherein it will probably convert any chunk into vectors right so this is the next step now the next step is basically also to uh import a library that will be responsible in creating a vector DB with respect to Pine call or we also say it as Vector store so here I'm going to basically use from Lang chain dot vector dot I think Lang chain dot it should be dot I'm writing comma I don't know why Vector oh spelling is mistaken do Vector stores okay and here I'm basically going to import I think it will be there pine cone right so I'm basically going to also use this pine cone pine cone will be our Vector store uh later on we can integrate this with our Vector DB that is present in Pines conone so the next thing is that I will also import our llm model because we will be requiring llm import open AI right so all these libraries I'm going to specifically use it I will quickly go ahead and execute it let's see if everything works fine you may get some kind of warning but it's okay right so this is your initial load that you are specifically doing now you know that I have an environment variables that is with respect to hugging pH so what I'm actually going to to do I'll go ahead and write from EnV import import load. EnV so this will specifically load all your environment variables okay so whatever environment variables that you have with respect to open API key or anything that is required you can basically do this right now I will also be importing OS over here right OS we can specifically use later on okay quickly now the first step as I said we need we have a PDF file we need to read it right so now I will write let's read the document okay now first step while reading the document I'll create a function so that I can reuse it and I'll write read Doc and here I will give my directory I can also give my file for that what library will be used Pi PDF loader right over here I'm using directory loader since I have to probably give my directory name and then I will basically write file _ loader and I will initialize my P PDF directory loader and basically give my directory path over here okay so directory path over here right so as soon as I give my directory path it will go to this specific directory and it will see whichever PDF is there it will start loading it okay and then I will go ahead and write file uncore loader dot load right now see why I'm showing you this step by step because everybody should understand what steps we are be doing it later on to convert this into a modular code it will be very much easy that is the reason I'm writing it in the form of functions all these functions will go into your utils.py file okay and finally you can see over here I'll get file loader _ load that basically means it is going to load all the documents and here I will basically be getting my documents right and finally we will return this documents done right now let's check check if everything is working fine so here I'm going to basically write read uncore Doc and this will basically be returning my document and here I will give my document folder so let me just go ahead and write documents in string right so this will basically be my directory path okay and now if I execute what is this doc it will probably read all the docs that are probably there now see every page by Page content this this is my first page second page third page fourth page fifth page like this I have 54 pages in my PDF right 54 Pages now if you also write length of Doc here also you'll be able to see it right so length of Doc I'm going to get 58 so that basically means we have done this first step right we have loaded we have read this particular PDF right now the next step is basically with respect to dividing these documents into text chunks okay so this is what we are probably going to do in our step two but till here everything is working fine so guys now we have finished reading the document uh now what we are basically going to do is that we are going to convert this into chunks right now for converting this into chunks what we are specifically going to do let's see so here I'm going to write the code here I'm going to basically say divide the docs into chunks and again because of the model restriction of the token size we really need to do this okay so here I'm going to basically use defin I'll create a function which is called as definition chunk data here first thing I will basically give my docs then I'm going to basically mention my chunk size right so let me go ahead and mention my chunk size my chunk size I'm going to mention it as 800 you can also mention it as 1,000 right don't keep a very huge value and then I can also say what about the chunk overlap Okay so so the chunk overlap like 50 characters can overlap with from one sentence to the other sentence right so here the next thing I'm going to basically create a text splitter and that is where we going to basically use this recursive character text splitter so first first thing first I going to mention my chunk size which will basically be my chunk size itself and along with this my chunk overlap which will be nothing but the chunk overlap that I have basically mentioned great uh so here I get my text splitter and now I'm going to basically up take this text splitter and split all the documents based on the kind of splitting that I've actually mentioned so here basically I'll provide my docs as my parameter and then I will convert this into and I'll return this docs perfect if you want to know more about this chunk uh recursive chunk splitter uh sorry recursive character splitter you can probably check this out documentation also I'm going to specify over here uh this documentation is good to understand what exactly it does and all right so perfect this is my chunk data function now what I'm actually going to do is that quickly use chunk uncore data and try it on my docs file right so here I'm going to basically mention my docs docs is this I've actually got this docs is equal to Doc okay and let's see so this will basically be my documents it is just going to apply all this right it is going to convert that entire document into a chunk size of 800 with the overlap of 50 okay and probably if I go and see my documents you'll be able to see it now see every document has now been properly mentioned right and the document that we are specifically reading is the Indian budget document right so any question that I proba asked related to Indian budget I'll be able to get the answer done this is good if I probably want to see the length of the documents also I can also see it okay just to give it get an idea like 58 is the length okay great so this is done uh now the next step what I'm actually going to do is that I'm going to also initialize my embedding technique so embedding technique of open AI right so we are going to initialize this so here I'm going to mention embeddings is equal to open Ai embeddings and here I'm going to use my API key OS do environment I can directly use os. environment and I can mention what is my API key so here I can say opencore open AI uncore API underscore key right so this is what is my embedding so let let me just quickly see what exactly is my embeddings so here is my embeddings that I'm going to probably use and this is what is basically used to convert that text into vectors right so quickly we have done this uh then I'm going to probably create my vectors let's say Let's test any vectors with this embeddings okay uh and there are various other embedding techniques like one h word to uh average word to and all but uh in open AI embeddings this provides you a much more advanced technique okay and over here also it will provide you some kind of vectors like there will be some Vector size also with respect to this okay like every every sentence will be provided with with respect to a vector size so here if I want to probably check and write embed underscore query and just test it with respect to anything like how are you right and let's see what kind of vectors we will probably get so this is my vectors that I'm actually getting see the entire text and if I want to probably check the length of these vectors it will also give you the length of this vectors okay so it is some something around 15 36 and this length will be super important because at the end of the day where I probably create my Vector database I have to specify this length okay for my problem statement now great now let's create our Vector search DB and pine code okay and now this step is very much important uh because after this particular step we will be able to see what kind of vector database we probably get okay Vector search DB in Pine con so let's go ahead and let's quickly create this Vector DB okay so guys here is the pine cone documentation you can probably check it out uh get started using pine con explore our examples this this is there what is the main important information about this Pine C is that it definitely helps you in semantic search in chat Bots also it helps you right where it probably helps you to store the entire Vector right and it provides you generative QA with open integration Lang CH leral argumentation uh rag also we basically say open integration and it has multiple uses okay so if I probably show you one of the document or guide right so if I probably go ahead and click on the guide right and this is where we really need to create the vector database I'll show you the steps of creating it right so Pine con makes it easy to provide long-term memory for high performance AI application it is managed Cloud native Vector database with a simple API no infrastructure has less pine cone serves fresh filtered query results with low hency at a scale of billions of vectors so if you have a huge data set you want to probably work with the vectors you can probably store it over here in the form of vector database um what is the importance Vector embedding provides long-term memory for AI Vector database stores and queries embedding quickly at a scale you know so anytime it is probably saved if you're quering it you will be able to get the response very much quickly now first thing first how you have to probably create this okay so if you once you log in once you log in over here or sign up you'll be able to see this okay so and here I've already created one index okay but this index will not work because see uh in the free tire right it allows you to just create one index so I will just delete this and show you how to probably create it completely from scratch so this is the name so I'm I'm going to delete this index because at the end of the day whatever vectors you are probably storing it will start indexing it okay so this is terminated now we will go ahead and create a new index so for creating a new index uh what I have to probably do is give a name so let's say I'm giving langin Vector now this is super important configure your index the dimensional metrix depends on a Model you select right now based on a Model if I probably uh see to it right so here you'll be able to see what is the length that I was able to get from my embedding 1536 so this is what is the dimension that I'm also going to give it over here and since I have basically doing cosine similarity kind of Stu or you can also do Dot product ukan but I'll stay to cosine similarity because at the end of the day the similarity search that is probably going to happen is with the help of cosine similarity and then finally we go ahead and create the index this is the main thing that you probably need to do this is basically getting terminated and this was the data that I had actually inserted but again we will do it okay so if I go to back to uh um back to probably a index let's see why it is not created or still it is showing terminating it should not not show terminating but at the end of the day because one I have already deleted it or I can just change the name if I want so but it is created over here okay Lang chin vector and it is a free Tire in the case of free tire they will provide you this thing right now from this there are some important information that you really need to retrieve one is the environment one is the database name okay so what sorry index name so I'll go back to my code here you'll be able to see Vector search DB and pine code let's let's initialize it I I've imported P cone I will say do in it okay so do in it basically does the initialization here two information are required API key okay API key with some information comma the next thing that I probably require is environment okay so environment something is required so let's retrieve this two information along with this what I can also do I have to also provide my index uncore name so here I will specifically say my IND Indore name index name I've already copied it from there so it is nothing but langin Vector let's go and see where is the API and environment so here I'm going to go back if I go and see there's an option of API keys so this is basically my API key I will copy it and I will paste it over here okay so Ive pasted my API key over here now the environment thing where will I get my environment so if I go to indexes and if I click this this is the environment that I'll be able to get it right so this two information is specifically required I will paste it over here right so this two information is done by executing it my Vector search DB will get initialized over there but at the end of the day I need to put all these embeddings specifically all these embeddings uh in my Vector DB right so over there I will again use pine cone pine cone which I have actually initialized and I'll say from documents and here I will give all my Docs so from documents I'm going to first of all give my doc parameter over here the dock which where which I need to probably store it in my Vector DB and then I will go ahead and write embeddings embeddings what kind of embeddings that I'm specifically giving is the same embeddings that we probably created and then I have my index name is equal to whatever index name I have basically initialized so as soon as I probably execute this you will be able to see that I will be able to get one index over here okay so let me just go ahead and execute it it'll probably take some amount of time because I have a huge data over there but you'll be able to see the changes once I probably go over here okay so if I go ahead and click it and if I refresh it let's see okay whether we'll be able to see everything or not whether the data part and all we will be able to see so here you can probably see query by vector and all all the data is there if I want to probably see the vector count it is 58 because the document size that you could probably see is 58 right and these are all the information you can see over here all the data has been basically stored and based on the metadata you can probably see it it has already done the indexing now any query that you probably hit it over here in the form of vectors you'll be able to get those specific response okay now to do the query part what I will do I will apply a cosine similarity so I will say cosine similarity retrieve results okay so I will try to retrieve the results over here so here let me just go ahead and write definition retrieve uncope query and here I will say query K is equal to 1 let's say k is equal to 2 I I will probably see the top two query now the second thing is that if I want to probably query I will get the matching results whatever matching results I'll use the same index dot whatever index is over here dot similarity let's see index dot similarity unor search right the similarity _ search what I can do is that let's see what function I've actually made for similarity _ search because I need to probably get those documents also right so basically uh I need to also create one more function over here right and that function will basically be my similarity underscore search that basically means what is my result that I'm probably going to get right inside this so index. similarity unders search is a function that is probably present inside this index itself right so similarity unders search and here I will probably give my query comma K is equal to some K value okay so what is the k k is equal to 2 whatever results I'm specifically getting and here I'm going to return my math matching results okay matching results so once I execute it so this is basically my retrieve query uh example so any query that I specifically give with respect to that particular PDF I'll be able to get the answer now this is fine this is the function to get the data from the database itself right so cosine similarity retrieve results from Vector DB I'll write it over here so that you will be able to understand okay so done this is the function that is basic Bally required now two important libraries that I'm going to probably use one is from langen Lang chin. change. question answering I'm using load question answering chain and along with this I'm also going to use open AI open AI will specifically be used to create my model and here my llm model will be created with the help of this so here I have written open a model name will be tax uh text Dy uh 003 and I've taken the temperature value as uh this one and then I'm also going to create my chain where I specific ially use this load QA chain and load Q chain actually helps you to create a question answer application and then here I will go ahead and write chain type is equal to stuff okay so my chain is ready my llm is ready everything is ready now all I need to do is that retrieve my queries right for retrieving the queries I will specifically be using this retrieve query function also so let's go ahead and write my definition I will go search answers from uh Vector database Vector DB okay and here I will basically write definition retrieve answers and whatever query I specifically give over here based on that I will should be able to get it right so if I probably see doc search then I will write doc search is equal to I'll call that same function retrieve query with my query that I'm actually going to give and then I will also print my doc search okay whatever print I'm basically getting now whenever I get that specific doc search I should also run this chain chain that I've actually created right to load QA chain so here I'm going to basically say chain. run and inside this what will basically be my input documents so I will say input input documents is equal to I will give my doc search right the document that I'm probably going to search and then the next will be my question which will be in the form of query right the query that I'm actually getting so once I do this my chain will basically be running and it will provide you some kind of response that it probably gets gets from the vector DB okay if it matches right and then we are going to return this specific response done now see the magic okay once I probably call this function what will happen so here I will write our query okay so the query will be I I saw something right I I basically so this will basically be my retrieve answer okay now see this I read the PDF I could find one question over there how much the agriculture Target will be increased by how many cores right how much the agriculture Target will be increased by how many cores I have just written this kind of statement now this retrieve query as soon as we call it will basically sorry retrieve answer as soon as we call okay so here I'll just make make this function change also the spelling should be right right retrieve and here also I'm going to probably make this to retrieve answers okay now as soon as I give my query over here it'll go to retrieve query it'll see from the index right it'll probably do the similarity search it'll give you the two results itself so let me just go ahead and see the answer over here now retrieve answer is not defined why okay I have to execute this sorry now it should be able to get the answer see so agriculture credit Target will be increased to 20 lakh CR with an investment of so and so information I I've just put right uh I can also write any other question how is the agriculture doing right so I may get some kind of question answer if it is not able to get something then it will say I don't know okay the government is promoting corporate based this this this this I'm getting that information from the entire PDF itself right so this is how beautifully you can probably get this and now it is probably asking being acting as a question answer application right now see this is what is the base you have a vector DB you're asking any question and you're getting some kind of response now on top of that you can also do a lot of prompt templating you can probably convert this into a quiz app you can convert it into a question answer uh chatbot you can convert this into a text summarizer you can do what whatever things you want right and this is what is the specific power over here right and this is really really good and that is what I'm probably going to show you in the next video on top of it like how can I probably do a custom prompt templating on my llm application this is what I'm probably going to show you in the next video but here i' shown you about what is Vector database and why it is very much important what exactly how the vectors are basically stored and here you can probably see see this is how your vector is stored if I probably search for any Vector over here I'll be able to get those kind of response over here right based on that uh search itself so start using this many companies are basically using this at the end of the day just for your practice sake it is completely for free right but if you have if you want more than one indexes two indexes then at that point of time you can probably take a paid tool paid version that specifically requires in a company itself so I hope you are able to understand this Amazing Project hello all my name is rush nyak and welcome to my YouTube channel so guys just a few days to end this specific year this month was amazing because I was able to upload many many videos related to generative AI many people had actually requested it uh the reason is very simple because all the students who have made successful career transition into the data science Industry they're working in different different llm projects so I hope you're liking all those videos that I'm specifically uploading um again as requested if you like this particular videos and all please do make sure that you subscribe the channel press the Bell notification icon hit like this will motivate me to upload more videos as we go ahead so it is a sincere request please do that and share with many people as uh many people as possible by you the reason is that all these videos is completely for free uh my main aim is basically to teach you in such a way that where you understand each and everything in depth Let It Be theoretical intuition practical intuition and many more right so what are we discussing in this specific video so I hope everybody has heard about um gini right gini API that was probably gini model that was launched from Google obviously the demo that they had actually shown on the website it was not true demo they had made made up that particular demo but now the gini pro model is available for you and you can also use it for your own demo purpose uh we'll understand we'll see a complete demo like how these models are these large language models are and how it is probably performing we'll be seeing various codes I'll be showing you that how you can probably create an API for this and the best thing is that with respect to this they have come up with this two different plan you know one is free for everyone the thing the model the gini pro model which is free for everyone it has a rate limit of 60 queries per minute that basically means within a minute you can actually just hit 60 queries price is free Price output is also free input output is free and you can start using this uh to just get to know like how powerful the gini pro is and I probably used it it looks pretty much good you know um at least uh not like that fancy thing what it showed in the demo not like that but yes we can compare with chat GPT or we can compare with open AI apis which perform various tasks like test summarization uh text classification or let's say other tasks like Q&A and many more right so the next uh plan that is probably go uh that is going to come which can be specifically used in industries that is pay as you go and that basically starts for more than 60 queries per minute okay so here is is the entire information I will be providing the link with respect to the description in the description of this particular video now let's go ahead and check the documentation and one by one I will show you how you can probably create the API the API Keys how you can probably load it and start using it okay so first of all just go to the python section over here and I'm just going to click on this Google collapse so as soon as I probably clicked on this Google collap you can probably see over here I've got this entirely okay so we will go ahead step by step we'll understand each and every line of code we'll see multiple examples and then let's see how good the Gemini API is okay so as suggested as I told you already this is like Gemini has come up in three different version and gini Pro is right now available for you okay where you can probably try and uh just by seeing this things right I I definitely I've already tried it out I feel that yes it is good enough right um if I compare with any openai apis yes it is doing a fabulous task okay I know the demo was bad but here the things that I'm going to execute is very much good so to get this particular notebook file all you have to do is that click on python over here and just click on this okay so this is the entire information how you can probably create the API key and all I will be showing you step by step okay so let's start this video before that please do hit like as you know that I uh I I always thought that within this year right I may reach 10 lakh subscribers but I could not but it's okay for the next upcoming 3 to four months I would definitely like to reach 10 lakh subscribers okay 10 lakh subscribers 10 lakh is a very good number right and just imagine how much beneficial it is for so many people out there so so let's go ahead and start this okay so we will go step by step I know please try to understand this things because I will be explaining you the code what exactly gini API is all about what this gini model why it is so good because this is a multi model right multimodel that basically means it is trained on both text and images so I'll show you if I probably give a image and it will be able to read that image and it'll be able to give you the information about that image that powerful the specific model is okay so uh we'll set up our development environment and get the API access to gini so this is the entire agenda we will generate text response from text inputs we will generate text responsive for multimodel inputs and then we'll use gmin for multi- turn conversation and we'll also see how different embeddings can be applied for large language model okay so first of all this generative AI entire there is a library which is called as Google generative AI with the help of API you can use various features that is available in this gini model right gini pro model so first of all I will go ahead and install this entire library that is Google generative AI okay with the help of the specific code it may take some time again it depends on your internet speed how good it is uh and then after we probably go ahead and install this so import the specific library now here are some of the important things that we are going to do okay so first of all you'll be able to see we are importing path lib text WP Google generative AI as geni so this is the allias that we are going to specifically use and this is the library that has almost all the features over there from google. collab you import user data inside user data you can store your API key okay I will show you how to how you can probably do it along with this I'm probably importing display and markdown to display the information and there is another method which is called as definition to underscore markdown that basically means whenever I get any kind of response I'm going to replace this dot by star because I think this generative a is gini pro gives some kind of response where it will be having this kind of output okay and then we are going to convert that entire data with respect to markdown okay so all these things we are specifically importing now let's go to our next step setting up your API key so for do doing that just click on this particular link okay so it will go to this makers suit google.com app API key you can also create Palm apis from here and all right so after going over here what you can do you can actually go ahead I've already created one particular API key over here which you can actually see if you want to create a new API key just go ahead and click on this as soon as you click on this you will be getting the API key just copy from there and here what I have done I have written the API key over here okay so don't worry that uh this API key is not right uh I've already executed or I've already stored that particular API key itself right so probably when I share this particular notebook with you you'll not be able to see this API key over there until then I may have also deleted it from here okay so the reason don't use this do it with your own because it is completely for free right 60 queries you can actually hit it now let's go ahead and do one thing first of all I'm creating an environment variable called as Google API key okay so this will basically be my API key okay and I will remove this I will not require this and then what I'm doing over here I'm I'm saying gen. configure API key and I'm using the environment variable and I'm setting that API key to this okay so once I do this done that basically mean my API is configured this is the simple steps that you specifically need to do now what all models you specifically get from Gemini API so over here there are two models one is Gemini Pro this is optimized for text only prompts so text summarization Q&A chat anything that you specific Al want to do you have to use this specific model that is Gemini Pro and then you have one more model which is called as gini provision this is optimized for text and image prompts okay so for text and image prompts specifically you can use gini pro version if you want to check how many different models are there just write for M gen. list uncore model list underscore models will give you all the models that it is basically having and it is saying that if generated content in M supported generation methods then it will show you all the both the model name so here you can probably see that as soon as you execute this you'll be getting that you have two models one is gini pro and then the other one is Gemini Pro Vision now let's go ahead and let's try something okay so first of all I'm going to use the gemin pro model this is specifically for text related task okay so here I'm going to use generative AI gen AI dot there is a method which is called as generative model and there I'll be giving my model name so once I execute this this basically becomes my model so if I probably go ahead and execute over here so here you'll be able to see that I am getting a model trust me guys this is good enough because if you don't have open API key also you can use this and when you use this you'll be able to understand more about the llm models okay so now let's go ahead and use one method which is called as generate content this generate content method can handle a variety of use cases including multi multi-t chat multimodel input depending on what the under underlying model supports so here I've used gin Pro so in this particular case I am going to specifically use it for text related task okay so now here we use model dot generate content and here I'm giving the message what is the meaning of life okay so this is the default message once I execute this you see the response time the response time with respect to this particular time it will go ahead and capture so uh and also remember guys uh when I was executing some some some time before you know this was really really fast right now it is a little bit slow is it a problem internet connection I don't know okay so but here you can see user time it tooks 120 millisecond system time was 10.5 millisecond total time was 131 seconds which is very good like open AI API speed I think it'll take more than this okay that I specifically know now in order to see the response I will use this 2core markdown and we will write response. text as soon as I write this you will now be able to see the output of this right what is the meaning of life so here you can see that the meaning of life is a philosophical question that has been posed by human for centuries so and so blah blah blah blah all the information is very much easily given and it looks good you did not have to do any other prompt template techniques to probably put it in this dotted point it has considered in a better way yes you can again use prom template also for this purpose okay so if the API and now this is the most important thing which I like about gini Pro okay if the API failed to return a result use generate content response. prompt feedback now you may be thinking why the API May Fail it may be because of some of the other reason to see it was blocked due to safety concerns okay because of safety concerns also it may not give you some response now what may be that safety concern okay so first of all we will go and see response. prompt feedback when I probably execute this I also have these all features that are probably coming up this information in the response safety rating category harm category sexually explicit probability neg eligible so you can see it is categorizing based on this four important categories whether it is a hate speech whether it is a harassment whether it is a dangerous content right and here you can probably see that it is also giving that particular feedback if any of the feedback is positive I think you may not get a response so let's go ahead and execute this particular code and let's see whether this works true or not okay I definitely want to check it out so I will go ahead and execute and I will say um I will say Okay I I did not I do not mean anything to write anything bad over here but uh I would just like to see how to insult someone let's see okay I'm just trying I'm not I I'm I don't mean to but let's see so here you'll be able to see that whether I'll be able to get a response or not and again over here now now it has becomes fast right so now let's go ahead and do this see the response part quicker ex only works for a single C but none were returned now I will go ahead and check this prompt feedback now this is where block reason safety see over here harm category harassment medium so this is what is so good in this ethics is definitely there right so it is not giving you any kind of resp resp right so I hope you have understood the importance of this okay now similarly G gini can also generate multiple possible responses for a single prompt okay it can also generate right so for that you just need to use this responses. candidates now what I will do I will not execute this but instead we will go ahead and execute this what is the meaning of life okay okay so let's execute this it's okay um or I I'll just go ahead and ask a different question can you let me know about the future of future of generative AI okay so I'm asking this specific question now let's see I'm not executing this now it should definitely give me some kind of response and this also depends on the kind of like amount of tokens that is probably coming from the llm model so here it has taken 122 milliseconds now let's see the prompt feedback I think this is absolutely fine okay and here I will also go ahead and see my text it'll give so here you can see the future of generative AI holds immense potential and Promises to revolutionize various style Gan gpt3 this this is there now if I go ahead and right response. candidates okay now here you can probably see that I'm getting the entire info this is so nice see so this is my first text right role model find this this this all the information is there with respect to all the information that you will be able to see that right all whatever thing we executed step by step we getting everything okay so this is very very good okay now by default the model returns a response after completing the entire generation process you can also stream the response as it is being generated and the model will return chunks of the response as soon as they are generated which is absolutely amazing again right so what we can also do is that you can stream the response okay no need to wait for the entire response so let's see okay so here I will use the same question let me see so I will so can you let me know the future of generative now I think for this it will not take much time when compared to the previous one one that we had done right so here I will go ahead and write all you have to do is that just write over here let me just show okay you just need to add a parameter which is called as stream is equal to True by that you'll be able to get uh the response as it is being generated so let me just go ahead and execute this okay now I'm not going to directly print response. text but I'm saying that for every Chunk in response print chunk. test text okay and then it will show 80 like dotted lines okay so we can also display this in this way so here you can probably see how fast it was able to chunk by chunk obviously when chunk by chunk is getting displayed it will be very very good right so here you can probably see all the information ethical this needed for skill Force long-term impact on society and all now one more thing is that when streaming some response attributes are not available until you have iterated through all the response CH this is demonstrated below so here if I say what is the meaning of life with streaming is equal to true now you'll be able to see that let's see let's see okay so once this gets executed now I have this response. prompt feedback in prompt feedback you'll be understanding whether it has some problems or not with respect to that thing now if I directly go ahead and write response. text okay it will automatically tell me please let the response complete iteration before accessing the final cumulated attribute okay so this is a very good problem statement and now based on your requirements what I feel when compared to open AI still Gemini uh API that we have right it may have more functionalities as we go ahead but till now it really looks promising it looks really good okay now we will try to generate and text from image and text text inputs okay so this is also good now let's download this image so by using a curl operation I am probably downloading the image if you see the image the image looks something like this okay or I may also use some more image right I will write cat playing image okay so cat playing image so here you will be able to see some images let's see let's see let's see let's see this looks like a complicated image I guess it should find some problem okay uh downloads okay downloads downloads here I will say upload that specific image okay I will save it let's rename this image I will say cat. jpj now if I execute this over here I will write cat. jpj okay now this is the image it looks something like this now what I'm going to do I'm going to give this image to my Gemini Pro Vision model and then we will see what it can understand from this image like if it is if I say that the Kay is playing with some cotton fur or Hol right this cotton holes now let's see what answer gini Pro Vision gives right so first of all we will go ahead and load gini provision okay and then we will go ahead and generate model. generate content image and then we'll say to markdown response. text okay so let's go and see the answer so it is going to take that image here directly we are giving the image now it is going to understand the specific image it is going to read and it's is going to understand it is going to give me a response in text okay now let's see so this looks amazing till here but let's see the response I really want to see the response of this and it is taking some amount of time I think when we go with respect to the paid API it will be little bit less but again it depends on the image size how we are specifically calling it and all right let's see I think as we go ahead the correct answer is play right so here you can probably see if I go ahead and see this image right it shows play now it was not that well but let's see the previous one okay so let's see the previous one over here okay I think with just play it is showing I think I'm not satisfied with that specific answer but we can also try with the previous one so let's say this is the image and then we will go ahead and execute this let's see what kind of response it gives us so here you have some tiffen box you have broccolis you have some food item right so let's see till then I will download some more images Okay um let's see let's take this image also images. jpj I will go ahead and upload it over here okay I just want to see the answer like what all different kind of answers we specifically get yes uh right now for this image to text I think we are taking some time but I don't know like in the future future it may have a good response time when compared to right now but here definitely some amount of time is basically happening right or these are meal prepared containers with chicken BR brown rice broccoli and Bell papers this also looks good so it is able to give minute details over here this is really good okay now I will go ahead and write play images. jpg let's see so this is the image I think this image is small so it should be able to give it should be able to check the image and generate some kind of text let's see it was an error post intern please try a report okay some some kind of error is basically coming up okay let's see I I think it was a timeout issue or I don't know but I think now we should be able to see the answer okay it is giving in some Chinese text okay so this I think works with some other other kind of images itself or where you have a detailed image but definitely some of the use cases is failing over here okay so I feel that it is failing over here okay now let's try this one okay so there is one more option I don't know like with respect to image do we have to give only this kind of images if I'm giving cat images playing cat playing images I don't know what kind of response that we are getting or do we have some options to probably change it we'll have a look okay now the next thing is that to provide both text and images in a prompt I'm saying that right a shot engaging blog post based on this picture it should include description this this I think for this uh it should be able to give right it should be able to give I think that is the reason it was not giving that well so now let's see I will go ahead and write cat. jpg I hope it was cat.jpg only okay so yes this was CAD jpg uh can you include the description of the photo of the of okay uh let's see can you write a short blog based on this picture okay it should includ a description of the photo okay now let's see how what kind of response we specifically get and here the second parameter I'm giving it as image and that is how we are going to probably get it and uh to provide both text and image pass a list containing the strings and the image so this is my string the first thing that I'm giving this along with this image so I'm saying that write a short engaging blog post based on this picture okay so now let's see what kind of response we will specifically get okay and quickly let's see but I did not find a good output something like this so here it says like that only right is designed to handle multimodel prompts and return a text output okay perfect so yes uh this is there now let's convert this into text the adorable Ginger kitten is having a blast playing with a colorful cat toy the kitten is batting at the toy with a spa this looks good right I'm really impressed by seeing the image it is providing you all the information okay now let's see one more okay sparton image I don't know let's see sparton group image I will put this image let's see it looks good I like this image spans jpg okay so I put this image let's upload this and let's see whether it'll be able to provide the description or not first is observing what all things are there in the image I think that is what gini provision actually gives you okay so here I will say Spartans do jpg not directory why spotten it is spotten spotten Spartan okay Spartan so this is my image which looks oops oops oops oops what is the error now Spartan okay it is jpeg okay so uh I'm getting this specific image of Spartan right now and let's see how it looks like so this is the entire image right now let me just go ahead and give this image over here okay I'm saying it to generate the content model. generate content let's see and I'm saying write a short engaging blog post based on this picture it should include a description of the photo okay so it is what I feel is that that Vision it was not able to just recognize everything but the text information that we getting over here it's good in this epic scene from the movie 300 Leon is the king of spot okay it is able to understand from the movies also completely right which is absolutely very very good okay so I hope you like this this particular video guys please go ahead and try it out and there is one more assignment that I really want to give in this go ahead and try there is something called as chat conversation so there are a couple of very simple by using Gemini Pro you can actually do it just go ahead and try this you just need to execute by appending this in the history all the information is given over here okay but yes I feel Gemini Gemini Pro looks promising and uh yeah it looks good in some computer vision right the images that I gave like cat and all it was it was just saying play so at least it was able to understand someone is playing over there okay so guys yet another amazing end to endend project for you and in this particular project we are probably going to create a multilanguage invoice extractor and we are going to use gini Pro API for this gini pro has been quite amazing you can definitely do a lot many things I have preped prepared more 10 to 15 different kind of projects that are related to Real World Industries and trust me all the specific projects are performing exceptionally well with respect to accuracy so over here we are going to focus on creating a multil language invoice extractor app we'll be using gemin Pro we will be writing all the codes step by step so please make sure you practice along with me and once we practice things right one then you get multiple ideas like what different kind of projects we can basically do okay so let's go ahead and first of all let me show you the agenda what all things we are basically going to focus on so here is the entire agenda so in this agenda what we are going to focus on first of all I will go ahead and show you the multil language in wased extractor app demo okay how the demo looks like later on we will start the process of creating the project project by creating the environment first of all then we will go ahead with the requirement. txt what all libraries we are specifically required and then we will start writing our code this will be an endtoend project code step by step we'll try to build this app again it will take some time let's say this project will probably take somewhere around 25 to 30 minutes and then in fifth point we'll also discuss about what more additional improvements you can specifically do so that you can also try it from your side and as usual guys I'm actually keeping Target likes for every video so let's target uh th000 likes for this specific video because all these videos will be super beneficial for you in the companies so let me first of all complete the first one that is the demo okay so here you can probably see this is my entire app okay and here I have actually uploaded one of the uh invoice okay so this is the GST invoice and it is completely in Hindi okay the best thing is that if I ask any question related to this using gini Pro so here I have asked what is the address in the invoice so address basically means over here 1 2 3 uh SBC building DF state so this is just a common invoice I've taken from the internet itself so here you can probably see we are able to get the entire response so this is quite amazing not only this I've asked for different different questions what is the date let's say if I go ahead and say what is the date what is the date in the invoice and here you can see date basically means the knock so that usually this Google gini pro is able to understand those things okay so I think we will be getting the response so let me just go ahead and see it so it's running uh so here you can probably see 12 27 21 so all the information in this specific invoice you are able to extract just by putting a prompt over here now the best thing about this particular project is that it is very difficult to automate it because I'll tell you uh we have tried the specific project with the help of testra OCR and all right just imagine that Google Germany is able to perform exceptionally when well when compared to all those kind of tools okay so this was the demo now we will go ahead and probably develop this project completely end to end and we'll start from completely from scratch itself so uh let me go ahead and let me start this specific project so guys here is one of the project that I've started in my vs code itself so first of all just go to the terminal so I will show you all the steps what you should basically do as I suggested the first step is basically to create my virtual environment so for creating the virtual environment I've already created it so that it does not take much time because for creating the virtual environment also it takes some time so in order to create it just go ahead and write cond create minus P okay V andv your environment name okay and then you can also give python version and remember to give python version greater than 3.9 in this case because Gemini Pro is suitable for python version greater than 3.9 so here I'm going to basically use 3.10 and then you just give- y so that it does not ask you for any permission while doing the installation as soon as you probably press enter so this kind of V EnV environment will get created in the same project folder okay so I'm not going to repeat this thing and probably execute it because I've already done this okay so just do it from your site with the help of this specific command the second thing is that I will go into theb file and I'll create an API key which will be available from the Google okay so Google API key this is basically for gin Pro and and if you don't know gini pro gini pro is again an amazing model that is provided by Google which actually provides you in a free way so you can actually hit 60 queries per minute okay so here is the API key that I have got if you want to also create your API key go to this website okay maker suit. google.com/ API key and you can just click on this create API key new project okay so I have already created it so I don't want to create it again okay so these are the first two steps you really require the API key and you require the environment now after that you just activate like you just write cond activate venv Okay and just activate this specific environment okay once you activate it you will be able to see that you'll be in that same environment location now let's go to the next step in requirement. txt what all libraries we specifically require so here is streamlet then you you have Google generative AI then you have python. EnV then you have Lang chain you have P PDF P PDF is basically to load any PDF as suchar or read any PDF uh then you have chroma DB chroma DB is specifically for Vector embeddings so we will try to also do Vector stores or vector embedding will try to create it so uh these are the basic steps that we specifically require now let's go ahead and start my coding or creating this specific application uh I will start writing the code completely from end so first of all what I will do I will go ahead and load my environment variable so I will say load do from EnV import load uncore do EnV so the reason why I'm doing this is that so that I can upload my all I I can load all my environment Keys okay so if you remember we have also installed python. EnV so python. EnV is basically for all my environment variables now I will go ahead and write load doore EnV so this will what it'll do it will take it'll load all the environment variables all the environment variables fromb file okay so this is what it is specifically going to do we'll do step by step now you'll be able to understand and please make sure that you write the code along with me so that you'll be able to understand it now the next thing is that I will go ahead and use streamlet as streamlet is a better framework to quickly you know create an app and definitely I use chat GPT for taking out the code and all right so that is the reason you're able to see that I'm able to upload daily videos see not the entire project is created by chat GPT but how to use stream late how to create this uh website kind of app you know all those things I can usually use streamlet uh use chart GPD so then uh so this is is my streamlet the next thing is that I will go ahead and import OS uh OS will basically be useful by for picking up the environment variable assigning the environment variable from somewhere else okay now this is done uh the next thing that I want is from P I also import image okay I don't know whether I'll be using this but let's see the next thing I will also go ahead and import from Google Dot generative AI as gen AI okay so I'm also going to import this specific because gen AI will be my entire libraries that I'm going to access it okay so done this is done these are some of the basic uh things that we are specifically going to load it okay now usually when we start our any application using gin API so what we need to also do is that we need to configure uh the API key so here I'm going to write gen a configure API key is equal to os. getet OS dot get EnV okay and here I'm going to get my environment variable that is nothing but Google API key so here whatever environment variable is basically present over here we are going to take this okay so configure okay so gen. configure uh the API key with this okay now it's time that we will create our function to load gini gini provision since the invoice instructor is on top of an image so we have to use this gin provision okay so function to load or first of all I'll load the model so I'll say model dot gen dot generative generative model so I'm going to specifically use gen. generative model and here I'm going to basically give my model name so it will be Germany Pro Vision okay so once I do this that basically means we are going to use this specific model now I will go ahead and write definition get giny response input image prompt okay so let me go ahead and write model equal to gen AI sorry I'll not initialize the model again so what I will do I will go ahead and write see the thing is that here I'm going to give three parameters one is this specific input input basically means uh uh whatever input I really want okay with respect to all the images that I'm giving and I'll also talk about this specific thing okay okay the three important information this input is basically I'm telling what what I want the assistant to do okay if I say hey you need to act as an invoice extractor you need to act like an expertise who is very good at uh taking out details from the invoice right so that basically becomes my input okay this prompt is what message I want like what is the address I actually return this is basically the image that we are going to pass okay so all those information this three information what we can basically do I'll write response dot model dot generate content and here we are going to use this three information first of all is input then you have image of zero the second one and then you have the prompt okay so this three information basically when you're generating this content you can give this three information in this same way okay input image of zero and prompt okay so in gini Pro they take they take all the parameters in the in the form of a list okay and remember the first parameter is basically the kind of prompt that you're giving where your model needs to behave in that specific way so I will talk more about it as we go ahead and finally we are going to just return the response. text so this easy it is with the help of Gemini Pro okay and that is the reason I'm loving it when I probably compare with open Ai and the best thing is that I can also use uh this along with my Lang chain you can probably use it with different different things I will show you I've also created a project where you can chat with multiple documents okay so that will also be we'll be using Lang chain and all so this is the function that is specifically done now understand one thing guys um we will do our streamlit setup okay so streamlet setup what I will do so here I will go ahead and copy and paste like this so here I'm using st. set page config let's say that I'll go ahead and say over here multi- language invoice extractor okay multi- language invoice extractor now in this multi- language invoice extractor I will probably also give this information let's say okay now here I've given one input box this one input box is my input prompt okay and this is basically my upload file file upload so I'm saying that choose an image the image can be jpg jpg PNG this is the image of the invoice okay so let me go ahead and write this message of the invoice so once I specifically upload this specific file then we can do anything that we want okay now the next thing is that I will create an image variable I'll keep it blank initially and let me go ahead and write if uploaded file is not none so that basically means when I've when when I have uploaded some file then I will go ahead and write image and again I'll be using image. open and we will upload uh open this uploaded file okay now once we upload this so what we can also basically do is that we can uh write some kind of image and all I want to display the image also as soon as I upload it I probably want to display it so I can just try use this st. image functionality and I'll say caption uploaded image and we can use this properties Now understand that this this code right I have directly searched from uh uh chat GPT okay and uh I've just written okay just create me an image where to upload files and all right uh so very simple it is not like I am learning from somewhere I even not seeing the documentation chat GPT actually provides everything a Google Power provides everything that is basically required now this is my uploaded file now I will also go ahead and create my submit button so here I will go ahead and write St do button and I will talk about it saying that tell me about the image okay tell me about the invoice something so this is my message that I'm actually going to give in my submit button and finally I have to also design my input prompt now see this input that I'm actually going to give right so this basically becomes my input prompt I what how I want the germini pro llm model to behave so here I will go ahead and create my input prompt just see this okay this is important and this will also give you an idea like how improv prompt works okay how we can actually work with any kind of improv prompt I will say you are an expert okay in understanding invoices okay um we will upload we will upload a image image as invoices okay I'm just writing some messages and you will have to answer any questions based on the uploaded invoice image so this is just a basic prompt that I'm specifically using over here I'm telling this to do something related to this okay so this is my input prompt and all I've written it over here then let me go ahead and write if submit button is clicked if submit button is clicked so this is my default input prompt now what I will do is that I'll also create my prompt template itself and probably go ahead right if submit button okay okay is clicked now what will happen if I click the submit button so first of all I will go ahead and write if submit first I need to get my image data okay now understand over here as soon as we load the image but still we have to do some kind of image processing and convert those images into some bytes okay so for that again how do we do it so I will write definition input uncore image set up so for this I have just written in chat G saying that and here will be my uploaded file okay uh uploaded file uh okay uploaded file okay see now you may be thinking what I'm doing in this function in this function what we are writing is that it will take that uploaded file it will convert that into bytes and it will REM it will give all the image format all the image information in the bytes now I did not write this code I just went and searched in the chat GPT and this is the code that I specifically got okay and this code is quite amazing same way nothing I did not do anything see here if the uploaded file is not done so we first of all we are getting all the values then the image part what all things we basically require the type the data and byes data right and then we are returning the image Parts in these two format okay the M type and data and if the file is not uploaded this is that so this is completely I got it from chat GPT I'm not bragging anything about myself and all um again charit is already trained in internet data so it's just like writing an input prompt and I'm saying that okay I require this two specific information please give me that information now in this image data what we will basically do is that we will get all the image information so here I will go and write input image setup so let me do one thing input image details okay so I will call this give a good name okay and here I will give my uploaded file okay uploaded file so uploaded file whatever uploaded file I'm specifically getting I'm going to give that specific thing over here now by this I will be getting my image data now image data once I get it okay then I will go ahead and write my response and go ahead and call my get Gemini response so here I'm going to basically write my input input prompt first p parameter is this second parameter that I'm going to give is my image data as usual remember all the information will be coming in the form of list okay so image underscore data and this will basically be my input input and this input is nothing but whatever information I'm putting it over here all this information will go over here and you have all this information in this format right now after this I will get the response and now I will go ahead and write st. subheader I'm giving some kind of subheader and I will write the response is st. WR and I will just display the response okay whatever response we are specifically getting okay that response we going to get over here so all this information is done and this is really good now it's time that we can just run the code so guys now let's go ahead and run this uh we have completed almost everything that we really want to do now is the most amazing thing whether the project will run or not okay so if the project runs it is absolutely good because at the first time we have written the code and everything should work fine so here I'm going to write streamlit run app.py and let's go and execute this so it has opened let's see so I've have downloaded two invoices let's see what all things will be there first we will try with the normal invoice okay so here you can see all the information who is this invoice build to okay so I'm going to put this information over here and I'm going to click it tell me about the image tell me about the invoice on the all the information will be provided over here this is good so your client so all the information is over here your client this this this this even the number has been extracted which is quite amazing it is really a daunting process guys okay uh let's see I will just take a small one what is the deposit requested okay so I will just go ahead and write it what is the deposit requested this is good this giving an amazing response so I will go ahead and click tell me about the invoice over here and here you go let's see what it is going to get so tell me about the deposit requested it is just saying your company uh who is the deposit okay my prompt is wrong tell me so it is not able to understand the context obviously if you don't give the proper uh tell me how much was the deposit requested I'll give a good response Okay so I will go ahead and now click on it should give uh the proper answer I think now it is somewhere 169.99 5 it'll pick up that exact info and provide you all those information this is good so let's see 169.99 this is good guys this is trust me this is very very close uh what was the Consulting fees let me go ahead and write what was the Consulting fees now I think it should get confused with those two values what was the amount of the Consulting fees I think it should be able to give it let's see then we'll try with some other language invoice like Hindi and all okay let's see let's see let's see I think it should work fine but this is a good thing guys you can automate this entire process just imagine it is such a daunting process for with respect to invoice just see that whether you get an invoice all so the amount of the Consulting fees was $550 okay it is taking this information um okay there are some minor mistake but other than that I think let's see what is the total what was the total discount let's see discount is somewhere around 17.8 but if you give proper prompt I think you'll be able to get a good response response okay 179.1 4 okay so let's go ahead and try some other invoice this also looks good and uh let me go ahead and write this so here I will go ahead and write what is the HSN of Lenovo 51251 Lenovo in Hindi it is written in Lenovo so what is the HSN number of of of Lenovo okay I'm writing it in English 51251 5125 5125 I let's see whether it'll be able to give or not see this small information also it will be able to take now over here the date is denak okay in Hindi we basically say it as dinak so here you can see 84713 01 0 amazing amazing just amazing okay so what is the date in the invoice and you can try anything you can try different different invoices if you want I downloaded this invoices from internet you can also do it okay so yes here let me see whether you're able to get it yes perfect so guys this was it for my side I hope you like this particular video if you like it please make sure that you subscribe the channel and all the information regarding this will be given in the description of this particular video this video we are going to see how we can actually build a conversational Q&A chat bot with the help of Gemini Pro API not only that we'll also try to save all this chat in the form of a history and will will also display all the results that we all had a conversation about that is the reason we are discussing about conversational Q&A chatbot so before I go ahead guys we will keep the light Target of this specific video to th000 so that I will definitely get motivated and I'll try to bring more similar kind of projects for every one of you out there now before I go ahead please let me go and go ahead and show you the demo so this is how the demo demo will look like so if I ask hi you can probably see I will be getting the answer the response how can I assist you today the chat history is Ive asked hi bot says hi hello how can I assist you so let's say if I go ahead and ask what is generative AI okay all all the previous information I really need to record it somewhere right so let's see after this the chat history right now is this much right so generative AI also known as so and so all the information is coming up and after that your chat history will also get updated and the best thing is that I'm streaming all the specific data okay so how streaming actually works and all we'll also be discussing about that so here you can see in the history I've asked what is generative Ai and this is specifically all the information now this is what we are going to implement step by step I'll show you each and everything again all the files regarding this all the code regarding this will be given in the description of this particular video so let me go ahead and let me solve this specific project so guys I have opened my VSS code over here and right now uh if you remember in my previous video I've discussed about all these things like vision. py how you can actually play with images with the help of gini API gini Pro API then we also discussed about some kind of simple Q&A chat B now in this video I am going to show you this entire code with respect to this qpy so here is what is my entire code I'm going to specifically write step by step I'll try to show you what all things is basically required as usual first of all we need to have an environment file with respect to Google API key this you can actually get it from makes. google.com so from there which will basically provide you all the features to create the API key for gini pro the first thing is EnV file once we create the EnV file then we will go ahead and start implementing our code if you have not seen all the videos in My Gin playist I would suggest go ahead and have a look so let me quickly write over there all the code so first of all I will go ahead and uh load all the environment variables so for this I will use forv um import loore EnV okay and then we will go ahead and initialize load. EnV and finally I'm going to import streamlet as STD so I'm going to use streamlit over here and remember one thing guys there are some important libraries that you need to install that is present in the requirement. txt everything will be provided in the description of this particular video the GitHub code right so I'm going to use streamlet Google generative a and python. EnV all this Library needs to be installed before ahead right so I'm importing stream. asst then I will go ahead and import OS because I will be requiring it and then I will say import Google do generative AI as gen okay so I'm going to use this Library only for doing all my task now initially whenever we load any environment key first of all we need to set this in my gen AI so for doing that I will write gen ai. configure configure is a method where it will be asking for the API key that I have and since I've already loaded that from my environment so you can see that os. getv I'm using this Google API key okay now the next thing over here I will try to create a function function to load gini pro model okay so here you can probably see gini pro gini pro model and get response okay so I'm doing this and here you have model. geni Dot generative model I'm going to initialize my generative model itself and in this case also I'm going to use gini Pro okay so gini pro and gini pro vision for conversational Q&A we will specifically be using this one that is called as Gemini Pro okay and then we will go ahead and execute it and write chat model dot startor chat and here I'm going to specifically use history okay so this history will also maintain all the things that we are probably going to uh have in our conversation but I will show you another way where I'll use the power of streamlit to store all the history in a form of a session later on you can also put that inside your DB or you can also use it from your session itself right uh so first of all let me go ahead and Define my definition so here I will basically write definition get gini under underscore response response and inside this response I will specifically give my question whatever question we have asked so this function should basically uh you know give me the response that I'm getting from the generative model itself like from the Gman Pro right so this question I will send it to my llm model and then I will specifically get the response so here I'm going to write response chat. sendor message and here I'm going to basically write question stream is equal to True okay so stream is equal to true because as the llm model is giving you the output we are going to stream it and we are going to display it right and then we will go ahead and return the response so once this response is basically coming this response is nothing but it is the output right when we specifically get response. text now we are going to initialize our stream late app for initializing it what we are going to do is that I'm going to use this three Fields one is the Q&A demo J Min L application page config and header it is very much common the most important thing is that if I really want to record the History part right the history of the conversation we will initialize session state so in stream late it provides you session States for chat history if it does not exist I'm saying if chatore history not in session State then we will go ahead and create a sess State and we'll right chatore history over here so right now it is blank as soon as we have any conversation later on we will try to record all those we'll try to put all those conversation inside this particular session state that is what we are going to look at then in the next step we are going to basically say input is equal to st. textor input and here I'm going to basically use input input and here we are basically going to write key is equal to input okay so input will be my variable name in short whatever text box I'm specifically using along with this I'm going to also use a submit button St do button and here I'm going to basically write ask the question okay so what I've actually done I've initialized my session okay session state so here that the name of the session state is chat history okay now if I click on submit or input right basically both the fields input should also be filled okay so if both this satisfies both this conditions satisfies then what I will do I will write I will go ahead and call my get Gemini response and here I'm going to basically give my input whatever input I am probably giving it as soon as it calls this function it is going going to get that message and it goes to get that response okay now the next thing is that add user query and response to session chat history now see as soon as I probably have created this input this is what is my input that user has given and this is what is the output that we have got right now what I'm actually going to do here for all this entire history right we going to save this in our chatore history session state so for that we will go ahead and write St do session State okay st. session State and here we going to basically use chatore history okay chatore history and I'm going to do append with this specific let's say I'm going to write you basically you who's sending the message and then I'm going to basically use input okay so I am storing all this session inside this particular U variable okay and finally I will get my response also so let me write over here St Dot subheader and here I will write a statement saying that the response is the responses and in short I have to probably display the response Now understand one thing we used something called as stream is equal to true that basically means this entire response can without getting the entire content can also be populated in whatever Pages we want to probably display right what what do I mean is that now my process did not have to wait for the entire content to come from llm so as llm is sending text Data whatever response it is basically sending it is going to display it in the front end screen okay so that is what we are basically looking at so now I'm going to write from Chunk in response see that is the reason when we write stream is equal to True okay that basically means we get the exess of all the streaming data and then we can write a for Loop and I'm saying from Chunk in response and here I write st. write and we will go ahead and write chunk. text so we are displaying the text part by part and along with this I will go ahead and append this entire response okay and here instead of writing you I will write bot okay and inside this instead of writing input I will go ahead and write my entire chunk. text so what I'm actually doing is that as soon as I get the response it is coming in the streaming manner we are displaying it and accordingly we are also appending in this chatore history okay now this is perfect this is done and finally what I will do is that I will just go ahead and create my history because I need to display all the history right so here I will go ahead and write the chat history is okay so this is what I am going to basically Implement and and here I will say for RO comma I will create two common variables in St dot session State and here I'm going to use my chatore history okay chatore history and whatever is there it is either in the ski value pairs U colon bot colon some kind of answers here I'm going to basically write st. write I'll use a f one over here and I will say roll colon and then here I will say text so in this specific format okay roll colum text now let's go ahead and see if everything works fine or not okay and I will go ahead and open my terminal I'll delete this let's see so we are now displaying perfectly all our details uh this VNV has got activated I've already shown you in my previous video how to activate V EnV environment also and here we will go ahead and write stream late run uh QA chat q a chat. py and let's see if everything works fine or not so it has got executed so here is my things I will say Hi how are you and then we will go ahead and ask the question let's see whether we'll get the response the response is I'm a conversational AI chat B this the chat history is having all the details okay and it is giving chunk by chunk you can see over here right uh let's ask some other question my name is krishn okay something krishn what is your name okay something like this and I will go ahead and ask the question let's see whether this is getting saved or not okay so here you can see how are you this my name is Krishna what is your name I'm a chat bot assistant I do not have a name bot designed to help users so and so so all the information that I probably type it over here along with the response it is getting recorded in the chat history now this is what I really wanted to show it to you and it was so much easy many people had asked this specific question in my upcoming video what I'm going to specifically do is that I'm going to create a PDF document with the help of gini API I'll show you different embedding techniques how we can convert a word into vectors and then how we can utilize for a normal document Q&A kind of thing with the help of Gemini API right so I hope you like this particular video this was it for my side all the information regarding this will be given in the description of this particular video thank you take care have a great day bye-bye
Info
Channel: freeCodeCamp.org
Views: 79,372
Rating: undefined out of 5
Keywords:
Id: x0AnCE9SE4A
Channel Id: undefined
Length: 241min 40sec (14500 seconds)
Published: Thu Jan 25 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.