Day-4: Hugging Face API + Langchain | How to use Hugging Face & It's Applications

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
for for for for for e for for for for for for for for for for so hello all welcome back to the ComEd session of generative AI I think I'm visible and audible to all of you so please do confirm in the chat if I'm visible and audible to all of you yeah good afternoon good afternoon to all uh I think I'm audible my voice is clear and my feed is also clear I'm clearly visible to all of you yes or no great so I think we can start with the session so now let's start let's begin so in the previous classes uh in the uh previous three classes actually I have talked about the generative Ai llm and then I came to this open Ai and yesterday I have I did the detailed discussion on top of this open Ai and I have introduced the length chain to all of you uh so guys this is the notebook inside this notebook I have kept each and everything whatever notes whatever code and all uh whatever thing I was doing all right so uh in terms of code and all so each and everything I have kept inside this particular notebook and this notebook is available inside your resource section so from where you will get a resource guys so for for that uh you need to go through with the dashboard so here is your dashboard here you will find out uh here you will find out all the recordings uh Day One recording day two recording day three recording so just try to go through with the day three you just need to click on the uh day three and here uh check with the resource so go inside your resource section and this is the dashboard guys generative AI Community addition English so here you will find out uh two dashboard uh the two Community dashboard one for Hindi and one for English so this is for the Hindi one uh actually I'm taking a same classes on a Hindi uh Channel as well I on Hindi I on tag Hindi you can can search over the uh YouTube and the uh it's it is your one this English one so just go and check with your dashboard you will find out all the recordings and all so click on this day three and here check with your resource section so okay so resources is not there I have already given to my team but don't worry I will check and here is what guys here is a a notebook so uh definitely I will provide you this particular notebook inside the resource section so you you all can run it you all can run it and by running it you can uh revise the thing and all and apart from uh this notebook apart from this resources you will find out the quizzes and assignment also so please try to enroll to this dashboard try to visit the Inon website sign up over there login and then uh enroll into this community session for this community session you no need to pay anything it's just it's a free one okay so just just go through with the Inon website and login um after sign up do the login and and you can access this particular dashboard and you will find out the same dashboard in a description also so just just try to check the description of this video of this live section you will find out the dashboard or else you can check with the previous Live recorded session also which is already available on the over the Inon YouTube channel got it so this uh resource uh part is clear to all of you now in today's session what all thing we going to discuss so guys first I will start from the linkchain first I will explain you the complete Len chain that what is a len chain what all things we have inside the Len chain why we should use it why it is too much powerful each and everything we'll try to discuss regarding the Len chain and after that I will come to this hugging phase I will explain you that how you can uh how you can use any any like open source model from the hugging face Hub got it yes or no so in the previous class I told you that whatever model whatever model is there over the open AI platform how you can use that by after generating a API key now in today's session after discussing this Lenin I will come to the hugging face and I will show you I will show you that after generating a API key hugging face API key how you can utilize that particular model so each and everything uh will talk about in today's session uh whatever I have told you and after that we'll start with the project so in tomorrow session or maybe day after tomorrow so I will start with the project and to and project I will use this open ey concept hugging face concept Len chin concept and I will show you that how you can create a web application end to end web application and then we'll come to the advanced part like vector databases and some other topic so I think uh everything is fine uh the agenda is all clear uh so please give me a quick confirmation in the chat if we can start then and whatever I have explained you whatever I have explained you so far so it is clear or not so please do let me know in the chat uh if it is clear and if we can start then I'm waiting for your reply for fine so I got uh the answer now great so let's start uh let's start with the topic so in this uh uh notebook itself I'm going to write it down the entire code uh of the Len chain so whatever thing is there regarding the Len chain I will try to do here itself and whatever thing uh things will come into the picture uh whatever other libraries and all so definitely we'll try to install all those library in the current virtual environment now here guys uh I told you that how to create an environment how to launch the jupyter notebook how to install the openi over there how to like install the lenen each and everything I have discussed in my previous session so if you don't know about it so please go and check with my previous session there I did a detailed discussion regarding the environment setup got it now here guys uh already I have written some sort of a line some uh like sort of a quote for the L Chen yesterday actually I I like uh I was uh I have imported the Lenin and I have used the key the openi key and and basically I have imported this openi uh class and I created a object then I written a prompt over here and here I was uh like giving this prompt to my open API and in the back end it was running the llm model and here you can see this is what this is my output got it now here I had written actually this this this is a today's agenda whatever thing we are going to discuss in today's session so hugging face API use of Lang chain and all so each and everything we'll try to do here itself in the uh in today's class itself so first of all let me write it down each and everything over the Blackboard so with that you will get a clear-cut understanding regarding the agenda and all that whatever thing I going to discuss and after that I will come to the code part code section so let's start uh with the agenda now in today's class guys we'll be talking about the Len chain so let me write it down over here in today's session we're going to start with the Lang ched now what is a langen Chen why we use Lenin and what is the difference between this open and this Len chin so each and everything we'll be discussing over here itself now the first thing the first thing which we're going to discuss in the Len chain the first thing how to use Len chain or how to use open AI uh how to use how to use open AI bya L chain so how to use open AI via Len chain that's the first thing we'll try to discuss got it after that I will come to the prompt template prompt uh templating so how you can do a prompt templating by using this Len chain so the second thing the second topic which we're going to talk about that will be a prompt templating prompt templating the third thing which we're going to discuss inside the Len chain that will be chains we'll talk about the chains that what is a chains uh how we can utilize this chains what is the meaning of the chain how uh what all the different different type of chains is there each and everything we talk about over here then we'll talk about the agents that what is the agents okay so we'll talk about the agent that what is the agent and what we can do by using this agent so each and everything we'll try to discuss regarding this agent and here if uh so here I will show you that how you can use the Google API so by using this surp API so what I will do so by using the Sur API I will try to I will try to use the Google API Google API Google search API so in the agent section I will explain you this particular thing and after the agent the fifth one the fifth topic which we're going to discuss that's going to be a memory so we'll let you know that how we can retain the memory how we can retain the memory like chat GPD is doing how we can do the same thing if we are using this open API so we try to discuss this memory uh memory part as well and which is a uh like which is available over here inside the Lenin and by using this Lenin we can implement this particular feature after this memory I will come to that uh document loader so uh how we can load a different different type of document so document is nothing document is just a file like PDF file CSV file tsv file or any other file how you can load that particular document so we'll talk about a document loader as well so here let me write it down document loader after completing all these thing then I will come to this hugging phase hugging phase I will show you how you can I will show you that how you can uh generate a hugging face API key hugging face API token and how you can utilize any sort of a model whatever model is there over the hugging face Hub so how you can use that particular model so I will talk about the hugging phase after that and finally we'll move to the project section so uh this is the agenda for today's session for today's class and apart from this each and everything I have explained you how to generate a open key how to uh like use a open a what is a chat completion what is the function calling and all even I have talked about the basics of the langin as well so if this part is clear to all of you so please do let me know in the chat if till uh like uh if the agenda is clear so I just want quick ear in the chat and please do let me know how many of you you are writing a code along with me because today I will go a little slow so you also can write it down the code along with me please do let me know guys please write down the chat G I think many of you you are writing a code mm uh just a wait just uh give me a second fine so let's start with the uh agenda now so here guys you can see I have written a agenda and first of all uh let me explain you that what is a link chain why we are not using this open API why we are using this Len chain and uh why it is too much important this Len chain and this llama index to so first of all let me talk about uh the differences between this openai and this Len chain and then I will come to the implementation part so here uh first of all let me write it down the limitations of the chat GPT sorry limitations of the open API uh limitations of open AI API now here guys see uh if we are talking about this open a API so here you won't be able to find out a free model so the first thing actually the first thing uh in a limitation uh like which uh we are going to talk about so here openi model is not a free but so here let me write it down open AI model open AI model open a model is not a free now let's see uh let's uh assume that okay so the model is not a free one and if I want to use the LM uh like if if I want to use the llm capability or that AI capability in my application I I if I don't have a budget so what I will do I will go with the other option other free option open source option okay so let's say some XYZ organization some XYZ organization created one llm now I want to use this particular llm so yeah definitely what you can do you can use the uh API whatever API this XYZ company has given to you and by using that particular API you can use this particular llm right now let's say you don't want to use this llm you want to use some other llm now how you will access it by using the different API now now let's say if you want to use some other llm whatever llm is there let's say uh one llm is over the hugging face Hub right if you want to use that particular llm large language model from the hugging phase right if you want to use it then definitely you can use it by generating that particular API key but guys just think over here uh yes we are using a different different API over here first of all uh we were using this openi API but as you know that openi model is not a free one for uh uh like if you want to use it so definitely will have to pay something and how we're going to pay it so based on tokens yesterday actually uh day before yesterday I shown you the uh the token price and all that how much you will be charged if you are going to use this openi API if you are going to use a different different model over there I told you regarding the input tokens output tokens each and everything I have discussed so just go through and check with the previous session okay so if you are not aware about it now let's say if I want to use any XYZ llm or any other llm so how you can use it by using their API key but just think that uh just think on top of it if why not like if we have any one solution so the one solution actually it can interact with several apis right so here I'm using this open API and if I want to access this particular model definitely I'm using this XYZ API or let's say some other model for that I'm using this XYZ API or maybe I'm downloading it but just think on top of it if we have any single solution for all the llms with that particular solution if we can access all the llms to that will be well and good now so length chain provide you that capability Len chain provide you that capability so by using this length chain you can access any sort of a llm right I will let you know that uh what all llm let's say this open is not a free one now let's say if you want to access a model from this hugging phase let's say you want toess is one model from the hugging phase so this L chain gives you that particular capability by using the Len chain you can access the model from the hugging phase also and from a different different apis I will show you what all apis this lch is having I will come to the documentation so Len chain is not restricted till this open AI it is having an access of a multiple API that is the first thing here is a limitation and here I told you the advantage of the Len chain I think you got my point now the second thing if we are talking about this GPT model uh if we are talking about the GPD model you know this have been trained till September 2021 data this train till September 2021 data if I'm going to ask anything to my chat GPT or if I'm going to ask anything to my GPT model definitely it won't be able to reply me and you all agree with this thing okay get my point so if you will ask to the chat GPT that uh just tell me who won the recent Cricket World Cup will the chat GPT uh able to answer this particular question no it cannot answer to this particular question because this have been trained till September 2021 data so for that what I will have to do I will have to call any third party API for extracting the information yesterday I was doing by using the function call in OPI open a right but here by using this length chain we can do in a more efficient way getting my point why we use this length chain because here if we are talking about if we are talking about this uh like if we are talking about the limitation of the GPT so I can write it down over here uh it is uh it is having limited knowledge so let me write it down over here it is having it is having it is having a limited knowledge a limited knowledge till 2021 so if I want to extract something if I want to extract something if I want to exess some extra if I want to exess something which is which happened uh recently or uh any like real time information so for that also like we use this length chain and apart from this you will find out uh like different different U like function or different functionality inside the Len chain this Len chain actually it's a more powerful so here there I have given you two main reason that why you should use the length chain now here by using this length chain so let me write it down over here by using the different color so we are talking about this length chain so by using this length chain what you can do you know so you can access any model okay so you can access different llm model different llm model by using by using different API whatever API this lenion support by using different API second thing you can access you can access you can access uh private data resources private data sources you can access uh any third party API so here let me write down the third point you can access you can access any third party API got it so this is the uh like some features of the Len chain now if we are talking about this Len chain so let me do one one thing let me create one Circle here what I'm going to do so here I'm going to create a circle now here I can write it down inside this particular Circle I can write write it down this length chain so what I'm doing here I'm writing down uh just a second so here I'm writing down length chain now what this length chain can do so this length chain actually it is having a chain so it can create a chain I will tell you what is a chain it can read the documents okay so document loader it is having a document loader now here I can write it on the third one so it is having a concept of agent for accessing any third party API agent now this can access any sort of llm so let me create Arrow over here so here I can do one thing I can uh keep the arrow so what it can do so here uh let me keep the arrow so it can access any sort of llm large language model from a different different API whether it's a open AI or any other API I can give you the example of two as of over here hugging face hugging face and open Ai and open Ai and it is it is having a access of different different apis as well so it is is having agent it is having a chains it is having a document loader and it can retain the memory as well so we are talking about the fifth one so it it it can retain the memory so let me write it down over here what it can do guys tell me so it can retain the memory it can retain the memory I will uh come to that memory part so this one Lin actually it can do a multiple things it can perform a multiple things and here I have written a couple of limitations of the the openi API and this is a limitation which you will find out inside the openi API openi model is not a free one and it is having a limited knowledge so here guys you will uh so what is this what is this langen chain so here this Lang chain actually it's a open source framework which provide you a multiple functionality with that you can create a agent you can connect with any third party API you can create a memory you can retain a memory you can uh read a different different kind of documents like CSV tsv PDF or whatever and here you can create a chain you can create a prompt template also I forgot uh one thing so here I can write it down you can create a different different a prompt template so let me write it down over here different different prompt templates got it are you getting my point so if we are talking about so see if we are talking about in terms of openi the code basically which I have written inside uh my previous previous class this one so what is this it's nothing now instead of using open API directly I'm using one wrapper on top of that that is what that is a length chain so over here let me write it down one more thing one more point so just just think over here that this is what this is my open API let me let me draw it over here so here is what guys tell me so here is my open AI API this one now here we have a length chain sorry uh here actually see this open API and how we are making a request to this openi API so this is what this is my length chain now if we are going to run any sort of if if we are passing any sort of a prompt right so just just think over here if we are passing any sort of a prompt so we are running it we are running it through this Leng chain okay so we are passing an input this is what this is my Len chain Len chain and here this prompt is going through now to this open a API open AI API and here is what here is my llm we are talking about with respect to this openi API so like this it is working it's nothing it's just a wrapper it's just a wrapper on top of on top of open API on top of opena API it is what guys tell me it just a wrapper on top of this open AI API and not this open a API actually it can do a multiple thing so it can do a multiple thing right so let let me tell you what all thing it can do let's say this is your application so here what I can do so let's say this is what this is my application and here is what here let's say I have used this Len chain this is what guys tell me let me change a color so this is what this is my Len chain now if I'm using this Len chain so it can interact with many it can interact to a many uh like apis like hugging face open eye or with any third party like API so let me draw it over here this one this one okay now let me do one more thing so over here let me draw uh one more Circle and with that maybe the thing will be more clear now here what I can write it down let's say this is what this is your application okay so over here I can write it down this is what this is your application so this is your app now it's making a request so this request is going through this Lin you can think that it just it is nothing it's just a prompt we are passing we want to interact with llm actually large language model so here we are passing a prompt so first it is going through this Len chain this is what this nothing this is my Len chain now this lenen actually it can it can interact in a many ways so over here I can write it down some sort of API so here I can connect with the open AI open API I can connect with the hugging face hugging face API I can connect with a bloom API and I can access a different different llm I can access what I can do I can access a different different large language models getting my point yes or no and apart from this this Lenin can connect with the other data resources also with some third party API like Google like Wikipedia and some other data sources now tell me guys this length chain is clear to all of you what is the length chain here I have uh here here I've created like each and every diagram and with that particular diagram I I I try to explain you each and everything regarding this Len so please do let me know in the chat if this thing is clear or not I'm waiting for your reply please do let me know yes I will share this PDF note with all of you don't worry uh I will keep inside the resource section please do let me know in the chat guys if this thing is clear then I will proceed further I will proceed with the Practical great so if you are liking the content then please hit the like button also so I will get some motivation so yeah guys please hit the like button and please be interactive if I'm asking something something then please try to answer please please write down the answer in the chat uh that will be a great motivation for me okay now let's start with the Practical implementation so over here you can see I uh started with the Len chain so let me uh run it first of all so here is what here is what here is my Leng CH now uh here I'm going to be import my open a uh this uh each and everything I have explained in my previous class itself now let me uh import first of all let me check with my key this uh I will have to generate openi key if I want to access the open API now now I'm not directly going to hit this open open API I'm hitting by using this length chain getting my point so here I will have to mention the open API key so let let me take my open API key just a second uh so here I can keep it somewhere just wait uh so here is my openi key now let me paste it over here this one so yes I have created my client means I have created my object now here is what here is my prompt here is what guys tell me here is my prompt now what is the prompt guys tell me the prompt is nothing in whatever see prompt is nothing it's just a sentence which we are passing to our to our llm as a input it's nothing just a collection of words collection of tokens so word itself is called a token that's it that's a prompt now over here if I'm going to run it so let me run this particular prompt and here you can see I'm asking to my chat GPT sorry I'm asking to my GPD model can you tell me total number of country in the Asia can you give me top 10 country name yes it is able to give it it is it is able to like provide a name basically now let's start from here because still here I've explained you each and everything in the previous class now let me give the next prompt the second prompt so over here I can ask something else to my uh GPD model now tell me guys what should I ask any uh any question anything which uh you would like to highlight uh which should I return over here great so over here I didn't get any okay so let's uh ask like any uh basic question so can you tell me can you tell me a capital of India so let's uh search about this capital of India and here what I can do I can run it and uh let me uh give this particular input uh let me give this particular prompt to my uh uh to my model and I just need to call this client. predict and here I need to provide the prompt so client. predict and here I just need to provide the prompt so it is giving me answer it is saying that the capital of India is New Delhi now here let's try to strip this uh particular output strip means it it will remove the slash end from here so I'm going to strip it and here you can see it is giving me an answer so I am getting answer without this selection now I think it is clear to all of you now one person is asking that what exactly tokens and Vector uh so here let's try to ask this same question uh to the GPT or uh to the jpt model model so what I'm going to do here I'm going to uh keep same question from the chat itself and the question is what is a token and a vector you can ask anything to your chat GPT and behind the chat GPT actually this uh behind the chat GPT the GPD model is working so let's uh ask about the tokens and the vectors and let's see uh what will be the answer uh which I will get from the GPD side so let me predict this a prompt three and here here the answer is client. predict prom three and see the answer tokens are individual unit that a computer program used to perform operation they can be words symbol or numbers so the same thing I told you now this tokens is nothing just a words right that are used in programming language to represent a specific intersection Vector is data structure that is stored a elements of the same time it is used to store sequence of elements such as number of character so a vector is nothing what is a vector vector is having two unit magnitude and the direction so how we represent the vector in our algebra in our algebra if you are like little familiar with the algebric uh algebra concept um algebra Concept in mathematics so we open the square bracket we write it down some sort of a number and we close the S square braet that is the representation of the vector and along with that maybe the direction might be involved that's it so here uh you can see definitely we are able to call the openi API now let's try to understand few more things related to this length chain now here let's start to talk about the prompt template the very first topic which we're going to talk about uh we want to talk about related to this prompt template so first I will show you the example of this prompt template that how you can create a prompt template and after that I will um I will try to explain you that what is a prompt template first let me run the code so here is what here is what uh we are going to discuss about this prompt template now I'm going to write it down from length chain from length chain and from here I'm going to import prompts prompts and let me import this prompt template class so prompt prompt uh PR M PT prompt templates so I'm going to import this particular class what is the name of the class prompt template okay it's not a template actually a template so prom template now if I will run it so definitely I will be able to import it so here my spelling is wrong so let me correct it first of all and here you can see we are able to import this particular class now after that what I will do so here actually I want to create my prompt right I want to create my prompt now let me do it first of all and then I will come to the explanation so here what I'm going to do so I'm going to create object of this prompt class so here is what here is my object so I'm saying that it is nothing it is my prompt template name so here I'm going to write write it down promp template this is what this is nothing this is my variable prompt template name got it Ive created my object now inside this object I have to pass some parameter so let's try to pass few parameters over here the first parameter which I'm going to pass over here the parameter is going to be input variable so here the parameter which I'm going to pass over here that's going to be an input variable input variable and the second parameter which we going to pass over here that's going to be a template so how my prompt will be looking like so here I'm going to write it down template and is equal to right now in the variable actually I'm going to write it down the name what will be my variable so here I'm saying city city will be my variable and here I'm going to write it down my template now in the template actually I'm going to write down that uh can you tell me the capital of so here I'm just saying that can you tell me the capital of and here on a in a curly braces I'm going to write it down the city right City so c i t y so here whatever uh this is what this city is nothing it's my input variable so here I'm going to write down the city so this is what this is my object this is what this is my object for the plum so here I can put the question mark as well and if I'm going to run it now here you will be able to find out it is giving me a error why because I didn't put the comma over here now here you will you can see this is what this is my prompt template now what is the issue over here input variable okay so the so the parameter name is what input variable now I think everything is fine everything is clear now here what I will do I will call one method I will call one method just just be careful over here right so here I will call one method now here I'm going to write it down format and here what was my variable what was my input variable input variable was City now if I'm going to write down City so here let me write it down this uh Delhi so here once I have done it now so it is giving me a specific prompt that can you tell me a capital of Delhi automatically right now here see again I'm going to ask the here again I'm going to create a prompt for uh for a different country let's say I want to ask a capital of China c h i n e now here you can see it is saying uh it is uh giving me a prompt that can you tell me a capital of China can you tell me a capital of China so what is the meaning of this prompt template what what what is the use of it now I think you can understand so by using this prompt template we can construct The Prompt based on a input variable now let's say you are going to create an application I can give you very uh good scenario now here is your application right here is what here is your application now you you have created this application by using the flas now here you are asking to the user just a city name just a city name or just a country name actually and based on that City or based on that country you want to provide a specific information and here you are using any sort of llm whether it's from hugging phas or open a now guys over here uh you don't want to be here actually you don't want that that your user is giving a entire prompt you just want to take a you just want to take a city name you just want to take a variable like we do in a python you know p in a python we we have a input function yes or no but and by using this input function we take a like input from the user and let's say we have to uh showcase the addition uh divide or maybe uh multiplication whatever on top of those input variable we can do it similarly over here let's say we are taking just a city name so by using this city name we can construct our prompt and that particular prompt we can pass to the llm and Leng chain gives you this particular functionality we don't have this thing inside open AI API getting my point now so here I have created my prompt now let's try to pass this prompt to the length chain so what I can do here I can write it down this is what this is my prompt first p r o p Mt prompt first this is what this is my prompt first and here I can write it down prompt second this is what this is my prompt second and here is is prompt second now let's try to pass this particular prompt to my to my llm or let let's try to call the API open API for that already we have a method client predict so let's try to call this particular prompt now here I'm going to call the prompt first this is the prompt which I'm going to call and here uh I'm going to call I'm going to write down the strip function also so I won't get any sort of a slash or whatsoever right now here you can see the capital of uh Delhi is India the capital of New Delhi is India okay so here I need to write it down just just let me redefine it instead of the city what I can do I can write on the country right now uh this is what this is my country and here instead of the city let me write it on the country one more time and here I can write on the India I think now it is it is a meaningful now here I can write it on the country one more time uh country cou okay c o u n c o u n and here the same here is a same and here is also same now it's a meaningful and let me run it and see what I will be getting over here so prompt one prompt second and here is uh like a it's a New Delhi and let me check with a prompt two so guys here what I can do I can pass the prompt two and let's see the output it saying the capital of China is a buing so this prompt basically this prompt template will help you a lot whenever you are going to create any sort of application where you just required a single word from the user this thing is clear to all of you if yes then please do let me know in the chat please do let me know in the chat if this part is clear to all of you please please write it on the chat I'm waiting for your reply are you liking the session are you liking the content so please hit the like button as well if you are getting everything if you are able to understand whatever I'm explaining to all of you please do let me know in the chat and yeah and whatever questions you have you can write it down in the chat I I I'm monitoring the chat don't worry wait sonat I will come to that again I will try to explain the Lang Advantage first of all let me complete the code part otherwise we won't be able to complete all the thing within a hour yes correct Vishnu your understanding is pretty much clear now since open AI model is not free uh so we'll l access all API all other API as well like hugging face API it can access the hugging face API it can access the bloom API or a different different API I will come to the documentation let me uh clarify the basic basic thing uh whatever is there inside the Lang chain I will come to the uh documentation great now here everything is clear everything is fine so here we have this uh here we have this object name prom template uh name and here is what here is my method that is what that is a format now what I'm going to do here so here actually we have a second method also which is doing the same thing let me show you that at many places you will find out that particular method also I return it somewhere uh just give me a second yeah this one so it is working in a similar way Len has given you the two ways actually for creating this prompt so first of all see we have this prompt template class we can create object and we can call this method format method got it now we have a second way here you can see this one promp template. from template you can call this particular method also and it will work in a similar way both are same don't ask me sir why we are using this that lenen is giving you the two option for creating a prompt template right now here you can see prompt template form template what is the good name of the company that makes product I can write it on any like name uh any uh product name so here uh what I can say I can give this particular uh okay first of all let me run it and here is what I'm going to call this format method over here so from template do fromom temp prom template. promore template and here is what here is my template template and here is what here is my tell me what is this this is my key now input variable now right now let me show you what I will get over here so I will be able to construct my prompt what is a good name of the company that make a toys here is my key and here is my template it's going to combine both and finally I'm getting my prompt so over here what I can do so over here I can write it down my prompt so this is what this is my prompt number three and see guys if I'm going to run it so what I will get so here I'm if I'm going to run it this promt three uh it will give me a name it's not a 23 basically it's just a three so let me run it and let's see what will be the output so p r o p Mt p r o m PT it's a spelling mistake and now let me check it is working or not so toy makers unlimited so this is the company name actually which I'm getting if I'm giving this particular prompt to my GPT model you can test over the chat GPT as well so you will get this type of nam in the back end we are calling the GPD model don't forget over here don't forget okay so we are getting a uh GPT we are basically calling a GPT model over here so this part is clear to all of you and uh I think now this uh prompt part prompt section is pretty much clear I believe that it is clear yes or no this uh prompt template if it is then uh please confirm in the chat then I will uh explain you the second topic that is a agent agent in a lang chain and after that I will come to the uh chain and memory and document loader and finally we start with the phase so tell me guys it is clear this uh prom templating how we can create a prom template great it is clear to all of you now let's understand the agent so what is an agent guys tell me so agent is nothing we use this agent in the Lang chain for calling any third party tool that's a simple definition of the agent if someone is going to ask okay just tell me who is a agent who is a agent in a real time let's say if I'm saying uh there is one agent uh let's say you went to the uh any uh you want to purchase any property you want to purchase any property and you went to the Builder and you are uh and uh once you visited the property and you have visited the Builder office or whatsoever there you will find out an agent so who is the agent actually so it's a it will so let's say you are a main uh person and uh you want a information of the property so that you want a like the main person and you want the information from the of the property basically so this agent will help you this agent will collect the information of that particular property and it will provide you in a similar way the agent is working over here getting my point yes or no I think yes now let me run it and let's try to understand the agent so guys over here I will start the thing uh I will ask one question to my chat GPT so here I'm going to ask one question to my chat GPT just a wait great so let me open my chat GPT and here let me ask one question the question is very very simple so here I want to know that uh can you tell me current GDP of India so here uh I'm asking to my chat GPD can you tell me the current GDP of India now if I will uh run it so here it is saying to me I'm sorry I don't know in a real time as my training only include information up to the January 22 this that whatever getting my point yes or no tell me so it is not having uh this particular information if I'm asking to my chbt can you tell me who won the cricket World Cup recently now here see what I will get so here it is saying guys I don't have a real time information only includes data up to January 2022 or 20 20 2020 okay as my latest updated the most recent information cup was held in 2019 emerg as a champion defeating New Zealand in a thrilling final so it is giving me an information from the 2019 match I think India again uh uh like uh they out uh I think uh they uh they they got defe from the New Zealand itself right in a knockout match in a semi-final itself uh yes I'm able to remember it so here uh it is not able to give me an answer now let's ask the same thing uh through the openi so through the lench itself in my code I'm going to write down the same thing over here so here I'm going to create a prompt 4 so I'm asking to my model prompt 4 so here I'm asking to my model can you tell me who won the recent Cricket World Cup so this is the question and now let me ask it let me run it so what I can do I can write it down this client predict and here I can pass my prompt from four now see uh okay first of all I will have to run it p r o m PT p r o m PT now see guys uh it is saying that uh the 201 W by the England I'm asking about the recent World Cup but it is saying that uh the 2019 cricket World Cup won by the England only it's completely wrong right now here what I can do I can ask one more thing can you tell me the current GDP of can you tell me a current GDP of India can you tell me current GDP current GDP of India so let's see what will be the answer so here is what here is my promp five let me copy it let me paste it over here and here I can write down this PR five so as of 2039 the India GDP was estimated to be around 2.94 trillion actually it has been trained till 20 uh 22 data 2022 data right so till January 2022 data right so here it is not able to give me a proper answer U it is not able to give me a realtime answer so for that what I will do guys tell me so here I will use the agent I will use the concept of the agent which will extract the information from the third party API now here I'm going to use Sur API now here so for for extracting extracting or real time info real time info I'm going to use I'm going to use Sur API Sur API Now by using the Sur API Now by using now by using this Sur API I will now by using the Sur API I will call Google search engine and I will extract the information in a real time so here I have written this particular uh like a statement so I hope it is clearly visible to all of you now let me keep it in a markdown and it is clear so for extracting a real time info I'm going to use Sur API Now by using the Sur API I will call Google search engine and I will extract the information in a real time let's see how we can do it so here what I'm going to do so first of all I will have to install this particular Library pip install Google search result that is the first thing now install this library inside your current virtual environment so here what I'm going to do here I'm going to install this particular here I'm going to install this particular library in my current virtual environment where guys tell me in a current virtual environment clear fine now after that what I will do so after that I will create my Sur API key Sur API key because uh with that only I can access I can access a different different API now let me show you the surp API so just open the Google so here just open the Google let me show you from scratch so over the Google what you need to do you just need to uh okay so here what I'm going to do I'm going to write down the Sur API so let me write down this Sur API so once I will write surp API now now here you will get this very first link so what is a Sur API like uh we have a rapid API now in a similar way we have a Sur API so Sur API is a realtime API to access Google search result not from the Google actually any from any search engine Bing or maybe some other search engine even we can access the Wikipedia also right I will show you how so here uh if I will open it now so you just need to do sign in first you need to do register and then you need to do the sign I already registered so that's why it is giving me this particular page now just scroll down over here just see over here API documentation now in a over here you will find out a different different documentation related to Google search API Google Map API Google job API Google shopping API Google image API now apart from the Google you will find out the Bing Bing search API also Buu also BYU also it's a Chinese search engine now Doug dug go search API yaho search API yex search API eBay search API YouTube search API any API you can call by using this Sur API now just click over here API key and here is what guys here is my API key now you have to generate your own API key this is my API key now let me copy this API key from here and it is having some sort of a limitations actually you can just do a 100 search in a free version but in a paid version I think uh you can uh like increase the number of search so just see over here just open it and you will be able to find out entire detail so plan is a free plan price per month zero uh total plan search 100 plan search left 95 five I already did it and yeah this is it in a free version you can check with the plan so just go in the change plan and here you will find out the entire details so production plan developer plan big data plan all the plans you'll find out over here and by using this API you can access the Google search engine you can access the Google search API inside your application right now here what I need to do I just need to paste this API key in my I just need to give this API key in my variable till here everything is fine everything is clear now what I will do guys so over here I will I I have to like import few uh I have to import few uh like import uh statement basically uh I have to import few packages so agent type load tools and initialize agent so these are the these are the like these are the packages basically which I need to import agent type load tool and initialize agent so see guys uh let me import this particular thing first of all uh yeah it is working fine now first of all what I will do first of all I will create a ag first of all I will create a client means here I've created now this open a uh client this one this one okay let me use this one or I can create one more time not an issue as many as time you can do it so here what I'm going to do so here I'm going to uh paste this particular code here I'm going to create my client so this is what this is my client now after that I have to load the tools which tool tell me which tool which tool like we are going to load Sur API now we are going to use the Sur API now so that that's the only tool right so here what I'm going to do I'm going to create a object of this particular method sorry this particular class so here is what here is my object now this is what this is my tool now here I will mention something inside this tool now let me do it over here so let me um mention this particular thing so here I'm going to mention it so this is a thing basically which I need to keep Sur API uh first of all I need to paste the Sur API key and llm so here is what here is my llm already I have created this line I'm using open still I'm using open okay I didn't uh explain you the hugging face so far so this is my Sur API key and here is the name which tool you are using that's it in our square bracket you need to write it down the name you can find out each and everything over the lenion tut lent documentation everything is there everything is there I will come to that just wait so here is what here is my tool I created my tool now I have to inial I have to create my agent type so here what I want to do uh so here basically what I want to do guys tell me so here I want to create my agent type so uh here what I will do I will uh create an object of this initialized agent let me create the object of this initialized agent and here is what guys tell me here is my agent this is what this is my agent now inside this initialize agent again I will keep something so first of all the first thing which I will keep that is going to be a tool so the tool basically which I have created the second type will be a client means my model the third type will be a agent this agent this agent uh basically agent type actually and here we are going to talk about this zero short react description we are going to mention this zero short react description and bbos to means whatever information um what if I will run it now so whatever information will be in a back end I will be able to see not over the display there's the meaning of the bbos right so here I mentioned three parameters the first is tool the second is client the third is Agent and the first fourth is barbos great now let me run it so this is what this is my AJ now what I will do so here I will write it down agent and I will run so run now here I will ask the same question so my question was let me take this particular question from the chat GPT can you tell me the okay so can you tell me who won the recent World Cup so if I'm going to ask the same question now to my agent so here what I'm going to do I'm going to ask it and let's see what I will be what I will be getting so it is executing the agent and here is search here is action who won the Cricket World Cup and here you can see Australia won the Cricket World Cup it's a recent information it's a real time information which I'm getting now it is giving me many given me some other thing as well links and all because it is calling the Google API Google search engine actually in a back end and here you can see it is giving me answer as on the recent World Cup you can ask anything you can ask anything guys just just uh write it down over here so you can say that uh can you tell me five current can you tell me five top current offs EF I I RS so if I will learn it now it will hit the Google search engine and here it is saying that see uh so it is saying that top five current affairs and still it is running so read is not available tool try to open I should search engine to find out observations see here it is giving me some like top five current affairs International breaking news uh affairs from us Europe this is the second one a current affairs sub is one of the best known as a improv life jagran Jo affairs.com okay it has given me a different different website maybe or U it here is a news Okay so actually it is giving me a different different name it is it is not giving me a proper current affairs I will have to mention that I will have to write uh that particular prompt basically so let's do one thing now let's understand the Wikipedia also so how we can uh like call the Wikipedia so here what I will do I will be writing down pip install FIP install Wikipedia now I will have to install in a current virtual environment now if I will run it now pip install Wikipedia so let it run uh so here you can see I've installed the Wikipedia now what I will do first of all guys see tell me what is the first thing I have to load the tool so let me load the Tool uh so here is what guys see here is my tool and here is my llm means my client open a client that's it now my tool now what I have to do I have to create a agent so here is what here is my agent this is what my agent I have initialized the agent here is my tool here is my like model and here is my agent type zero short react I will come to that what is this react description and BOS equal to two once I will run it and here whatever I will run now see I'm going to write down uh agent dot run and here I'm asking can you tell me more can you tell me about this re uh okay can you tell me more about this resent Cricket c i c k e t Cricket World Cup so if I will learn it now it is going to extract the entire information from the Wikipedia okay it is it is taking from the 2019 World Cup okay it is taking from the 2023 World Cup itself the World Cup was the 39 Cricket World Cup which was held in India 5th October November 23 as on the tournament great so it is extracting a information from the uh recent one itself now here I can ask one more question to my just a second what I can do I can copy it first of all let me copy it this particular thing and here what I'm going to do here I'm going to pass a next question so the next question is so let me keep the question over here and let me run it it is taking the information from the Wikipedia itself are you getting it guys yes or no yes surf I explain you everything regarding the Sur API s if you here if you look into the Sur API right so each and every plan I have shown you and it give you the free access also but up to uh like it is having some limitation over there you can just hit 100 search you can just hit the 100 100 search in a free version if you're going to take a plan so in that case uh there will be a different uh number of search actually search plan is there different different plan is there see okay $2,500 per month $8,000 per month Cloud 4M plan many plans is there see guys how much plans is there uh which you will find out just just go through with it and let me give you this particular link inside the chat and don't worry each and everything will be available inside the resource section at the single place uh at the single place I will keep all the thing and I will give you that don't worry so now see it is extracting the entire information from the uh like uh it is going to extract the entire information from the Wikipedia so final answer the total National depb of the this one and here you can see this is the GDP of the uh USA and here observation and all everything everything now see action Wikipedia input GDP of United State observation page economy of United States summary this is the complete information complete information information which is going to fetch which it is fetching from the Wikipedia itself now tell me guys how many of you you are able to understand the concept of the agent so please let do let me know in the chat and then again I will revise it and I will explain you uh through the lch and documentation please do let me know in the chat fast if you are how many of you are able to understand the concept of this agent here from here I have started this agent tell me guys fast by using the Sur API we can uh access uh we can access a real time information and it is possible in a is possible in a length chain please do write it down in the chat if you're liking the uh session so please hit the like button also and I'm waiting for your response guys please do let me know sir please explain the logs which is coming from the agent so here uh I can explain the log so here is what here is my logs what is this uh what is it uh just check over here so it is saying entering new agent executor chain so after this I'm coming to the chain concept chain and memory two thing is remaining and the document loader three is remaining uh uh then uh you will be able to understand this chaining and all in a better way now here entering a new executor chain so action is what it just want to search now action input top current affairs so it is making observation it is searching everything from the Google then it is thinking something I need a narrow down the list of top five internally it is doing everything internally it is doing everything and it is giving you the final answer this one finished chain actually each and everything has been coded in the form of chain llm chain I'm coming to that chain and once you will understand that particular chain now this thing will be like pretty much clear to all of you believe me just just read it by yourself as well what is the use of client in this what is a just it's just a name now what is a client see I told you please learn the python first if your python uh topic is clear then definitely you will be able to understand this line of quote see someone has created a openi class somewhere in openi pack you just downloaded that you just downloaded that particular package by using pip install openi and now you are creating a object of that it is just is just a class and here is a object this is the object name you can keep it anything here you can give your name like whatever name your name just write it down your name this is what this is nothing this is the object of the openi class and here you are passing a different different parameter someone has created a class and you are just using it that's it nothing else so this is what this is my client and I think this is clear to all of you now coming to the next part so here first first of all let me show you the Lenin documentation so I'm going to write it down over here Lenin documentation now over here uh like uh you can see this is what there is nothing there a lent documentation and here is an introduction so they have given you the complete introduction of the lenen over here lenen Library lenen template Lang server Lang Smith everything you will find out over here and this document is a amazing one similar to this open AI uh so yesterday we have seen the openi documentation right so this length chain documentation similar to the openi documentation it's a pretty amazing each and everything you will find out over here itself each and everything you'll find out over here itself now let's start with the installation so how you can do that it is very very easy pip install L chain and pip install and all what is the meaning of this pip install hyph e dot so this thing we'll try to understand in our upcoming session once I will start with the end to end project now L server try to understand this also what is the L L server all L CLI so many like they have given you over here as of now this lench package is required that's why we are going to download it now over here we have a quick start so here you will find out the quickest start so you can go through with this quickest start and you can uh like you can take a glimpse of this Len chin so everything you will find out over here in a quick start itself pip install Len Chen pip install open a you can export the open I key and then you can use it and here is a different different thing which you will be able to find out whatever thing we are running so open a you can uh create object of this chat open also now here is llm model here is U you can use this particular class also chat open AI now human messages lch schema human messages there you can check with this what is this now you can create a prompt templates already we have created now just see over here what is a what is a PR prompt template most llm application do not do not pass user input directly into llm most of the application you will find find out you just require a single word I given you the example yes by using this prompt template you can achieve that particular functionality and here is a example for that got it now here is a chat comprom template so each and everything you'll find out over here and uh as uh like you will find out the latest version so there might be some sort of a changes in a code and all but don't worry the concept will remain same we'll find out some changes in a code in a classes the name of the class classes but the core concept will sa if you're getting any error in a new version then check with the like documentation and try to rectify it that's it so here is a quick start and you can go through with this quick start and you can understand a different different things now security wise they have given you the different different thing now let me come to the next part so over here just click on this G to started again they have given you the different different uh thing prompt is there model is there which model you going to use output parser entire pipeline okay R there they have included their RG also now okay so retrieve argumented generation so you can go through with this and you can understand what is this RG but don't worry I will cover this in my uh next class this RG it is I'm having this RG in my pipeline so I will try to cover it this uh uh in a live class itself in the jup notebook itself I will write it on the code now over here you can understand about a different different thing different different concept just just go through with this document it's amazing one now interface is there so prompt chat model llm out parts are retriever to these are the thing just just go through with this try to understand it now how to so here is a different different thing which they have mentioned Right add fallbacks bind R time runable Lambda many things right so here you will find out the cookbook so inside the cookbook everything they have given you everything prompt plus LM so the thing basically which we are going to do over here uh which we are going to do as of now they have mentioned it over here r r this was this was not there previously when I had checked recently they have added in a new version so R is there so here you will find out the code related to R see this one now here multiple chains chains I will come to this chain I after this one I will explain this change right so here you can see the change and all so each and everything they have given you but as of now we are trying to understand this particular part we are trying to understand this agent and we are trying to understand this model input output so prompt already we talked about chat model already I shown you by using the open a so this is like pretty amazing document guys so once you will go through with this document now you'll find out uh it is having so many things and they have given you the code and all each and everything they have provided you believe me guys so just go through with this one and try to understand uh different different thing or whatever thing basically is there so we going to understand this chain now and we'll be try we'll try to understand this memory but apart from this chains and memory it is having lots of things which uh we might uh we might use in our application if if you are creating application now so this concept uh like might come into the picture regarding the r or regarding a different different one different different topic basically which they have included but over here I would like to tell you one thing whatever I'm explaining you in a Jupiter notebook U if you are a beginner that definitely it's a more than uh it's more than enough for all of you and uh in the next class once uh when I once I will implement the project now then uh you will find out the importance of it and don't worry I will uh keep some latest thing also like R and all inside my project and inside my uh future classes and you will get to know that so here uh I have given the overview now let me talk about this uh agent type so there basically you have seen one thing that was the agent type now let me talk about this agent type what is this so here you can see guys in a agent itself you'll find out the agent type see agent type just just click on this agents and here you will find out the agent type now we have a different different type of Agent Zero short Agent Zero short react agent structure input react agent openi function yesterday I have talked about this openi function and now it's a legacy people are not using it people are using this agent concept from the lenion directly people are not using this open a function uh but still I have explained you that so here you will find out the conversation self assessor react documentation and all and this zero short is nothing it's a basic one so if you going to ask something to your llm model to your GPT model so you will use the zero shot react now here you will find out this this agent use a react framework to determine which tool to use based on a Solly on the tools description so whatever tool description you are giving based on that it will search the uh like compatible tool and it will provide the prompt to that particular search engine or to that particular tool and it will give you the out that's it zero short react now here this is the most general purpose action agent you can see the node so this thing is clear to all of you now let's start with the chains so are you comfortable till here and if you're not able to write it down the code along with me sometimes it happens in the live session don't worry just listen to me just listen to my words whatever I'm saying and practice after the class practice after the live session recording will be there and resources also will be there so let me write it on the Chain over here and let's start with a chain now so first of all tell me guys this part is getting clear how many days you will take to come up with an end to end project one day only one day I will take to come up with an end to end project so lench is only made for the NLP use case or any other compete capabilities also it is having as of now I have used this for the NLP use cases I will have to explore the recent uh thing whatever is there inside the Lenin maybe uh we can use it for the other uh like for the other task also but I haven't explored it for the other task I just use for the NLP once I will EXP explore it I will let you know that whatever recent update is there but if you want to know about it just go through with the recent documentation all the llm has only text or code generation capability yes but you can do many whatever NLP task is there now you can do by using the llm because it is having the code generation capability with that it can understand the pattern inside the data so you can f tune it it is uh possible you can f tune inside your CPU Itself by using your CPU I will let you know uh otherwise I will share the resources with all of you uh don't worry we will'll come to that and uh we'll try to talk about it uh not as of now later on but yeah uh I will give you the glimpse of that great uh I think now people are getting many things we are using uh not completely actually if you don't know about those thing you won't be able to understand this particular part that's why first I started from the basic from the opener itself otherwise directly I can start from the Lin and then again you will ask to me sun what is this uh what is this open Ai and what is this llm what is this the native AI I can even I can start from here itself from the L chain so but I started from the very basic okay so let's start with a new topic uh that's a chain so what is a chain so let's understand the chain so first of all I can uh show you the documentation and uh just a wait great so here actually what I did I kept one a simple definition of the chain and let me copy and paste it so here is a a definition just try to read this particular definition and try to understand the meaning of chain and it will be more clear once I will write it on the code so Central to Len chain is a vital component uh known as Lang chain chains forming the core connection among one or several large language model in such sophisticated application it become necessary to chain llm together either with each other each other or with other element so if you not able to understand by this particular definition so let me open the documentation for all of you so here in the go inside this more uh just click on this more and here is a chain just uh read about this chain so using an llm in isolation is fine for a simple application but more complex application require chaining llm either with each other or with other component now what is the meaning of it so just uh okay so I have uh explained you the agent that's why I explained you the agent at the first place and then I came to this chain now tell me guys this llm was not working over there so I changed what I did now I change I changed the terminology so what I did guys now I so this llm was not working for that particular prompt so after coming to this llm means let's say if I'm not getting any sort of outputs I came to this chain and this chain actually it was connecting to me me it was connecting to me to the surp API through the Sur API basically it was connected to me Google search engine getting my point so here what is the meaning of chain so chain is nothing okay if if you're talking about chain in journal so let's say this is a chain so something like this you will find out so what is this what do this guys tell me so chain is nothing which is uh like connecting a several components which is connecting a several component getting my point yes or no I think you are getting try to understand it what is a chain so chain is nothing it is just connecting a several component so here they are saying using llm in isolation it's fine but in complex application require chaining the example I shown you by using the agent if you will read it if you will read the answer of the if you'll read the answer of the agent agent I'm running agent on run and you are getting an answer so if you'll read that you'll find out it is chaining means for it's trying to find out somewhere else it's not able to get then again it is going to somewhere else and it's going to take an information then again it is going to call some other prompt and it's going to take a information so what is the chain so chain is nothing it's a collection of component now which component what component whatever component Maybe inside the uh like uh like whatever let's say we are using Leng chain and inside that we have a different different component I'm going to chain to those particular component and maybe I'm going to like connect with other llm so I can do that as well or maybe I'm going to connect any third party API I can connect that as well so I'm doing a chaining if I'm running chat agent. run now internally it is doing a chaining getting my point I think you're getting now let's try to understand in terms of python code so here first I will start with a very basic example so what I can do here so here uh first of all I can write it on my client so here is my client guys c r i e n t this is what this is my client now what I will do guys so here I'm going to import The Prompt template so this is what this is my prompt template and by using this prompt template I'm going to create I'm going to create uh I'm going to create one prompt so here is what here is my prompt so what is a good name for a company that makes a product so here I can run it and let's say uh I'm going to write it down any company name so okay I'm going to write down the uh actually I want a company name what is a good name for a company that makes a product so I'm just asking to my chat GPT okay I I'm making this particular product just give me a good name for this particular company so here I'm going to write down let's say wine so wi so here I uh I'm uh just just think that uh just think like that that I'm going to open a company uh and here I'm going to produce a wine and all uh okay so I want a name any creative name okay that I'm asking to my LM model now here if I will uh like close it so what I'm going to do so here I'm going to run it so uh prompt. format so this is what this is my prompt what is a good company name for a uh what is a good name for a company that makes a wine so that's going to be my prompt p PMT so this is what guys this is my prompt now what I will do so here actually I'm going to import the chain here I'm going to import this llm chain here I'm going to import the llm chain just just be with me just for uh next 5 minute everything you will get it's my promise to all of you I have uh simplified every thing every uh like every line of code just be with me next for 5 minute so here you can see we have a llm chck now what I'm going to do I'm going to create a object of this llm chain now guys uh here I'm not going to call a predict method I'm not going to call a predict method what I'm going to do so here in this llm Chan what I'm going to pass guys I'm going to pass client right and I'm going to pass my prompt that's it this two thing I'm going to pass so llm llm is what c l i n t and here I'm going to pass my prompt so p r o p Mt prompt is equal Al to prompt so I passed the client and I passed the prompt here now this is what this is my llm chain right I'm going to connect both component llm and my prompt now over here what I'm going to do so this is what this is my chain this is the object basically which I have created now here you can see it is saying that uh is giving me a why I'm getting it let me check with the prompt so here uh let me run it first of all what is a good new company that makes a wine okay from template I think I will have to use format I think I will have to use this particular prompt only uh this one this only uh let me delete it because it is asking I need to provide in the form of dictionary so I cannot pass a direct prompt over here here what is a uh because uh here whenever I'm running this uh whenever I'm calling uh the run method Now by using this chain then automatically it will uh like take the name from here itself so let me delete it let me delete this particular line I'm going to delete it guys this one so here is what here is my prompt now length chain llm chain and here now it is fine now what I will do here I'm going to write down chain and chain do run and here actually I need to pass the value so here I'm going to pass wi now if I will run it now see it is giving me answer the name of the company is what it's a uh sdip strip and is the name of the company is what Vintage Wines Winery so it has given me a name of the company like I want to create this particular product and here it has generated answer now I'm going to chain I I'm making a chain by using two components the first first one is llm model that is that I'm getting from the openi and which is available inside my client and the second is what second is a prompt which I'm passing over here so now I can directly run it by giving the keyword and here you can see I'm getting an answer so I'm chaining this two thing this is the simple this the simplest uh like uh there simplest example I given you now let come to the second example so over here what I'm going to do so here I'm giving the second example example two example two so I took one more example to for explaining uh this chaining part actually so here uh let me copy and P so here is what guys here is my prompt template this is what this is my prompt template now here I'm asking uh this is what is my template I want uh to open a restaurant for Cuisine Indian Cuisine Chinese cuisine Mexican Cuisine Japanese Cuisine American Cuisine whatever but that I want a fancy name this is my prompt template let me run it here I'm running it now if you will find out the prompt template so here you will find out the prompt template so this is what this is my prompt template got it now what I will do guys here I will make a chain so what I'm going to do so here I'm going to make a chain so let's say uh this is what this is my chain so llm chain and I'm going to combine two thing first is client and the second is what the second is prom template now if I will uh run it so here I'm getting my chain then I will write it down chain do run now I'm uh let's say I'm giving something over here let's say I'm giving uh Chinese so according to that it will give me answer so the answer which I'm getting the golden dragon dragon place so here what I'm getting guys I'm getting this Golden Dragon place so the emperor's kitchen there's the name okay if I'm writing over here uh Indian let's say what I will be getting so Indian so here actually I'm getting Maharaja Delight so just the name it is is suggesting me one name which I'm asking to my llm model that's it now let me show you few more thing over here now so here I'm getting a a response and the response is fine now let me come to the second thing second example so here what I'm going to do so here let me show you something so now over here if you want to see the detail actually so for that I have mentioned one more thing that is a verbos parameter as I told you earlier if I want to check all the detail whatever is happening in back end so for that there is a parameter veros is equal to true now if I will run it now see what I will find out uh let me predict with some name so let me uh check uh chain. run and here I can write it down let's say America so here it is saying that entering new llm chain prompt after formatting I want to open a restaurant for American food suggested a fancy name for this and here here is a name American spice Visto so you can see the complete detail over here what is happening by using the verbos true then till here everything is fine everything is clear now guys here uh this is a simple chain basically which I have created by using this two component now let me explain you One More Concept over here so here actually I have written one definition or I have written one text uh just let me explain you this particular part and then uh again I will try to revise you so here I'm going to to mark down it and here guys see what I'm saying if you want to combine multiple change and set a sequence for that we use Simple sequential chain simple as simple as that right so if you want to combine a multiple chain if you want to combine a multiple chain and set a sequence for that we use a simple sequential chain so let's try to use the simple sequential chain and let's understand what is it so for that basically I have designed one prompt okay just just understand over here so step by step we'll try to understand see I have already written a code in my doc I'm just copy and pasting so that I can save my time that's it everything is same see I can write it down the code in front of you also but it will take some time for writing this particular statement on all it's the same thing okay wherever I have to write from scratch I will do that now over here see uh let's try to understand step by step now over here this is what this is my uh second prompt so in the first prompt see in the first prompt The Prompt template which I have defined what I'm saying over here I'm saying uh I want to start a startup right I want a start a startup and suggest me a good name so here is my prompt now here you can see this is my input variable that is what that is a startup name yeah it's fine it's clear to all of you now here I've created a CH by using this model this is my model and this is my promt template okay this is the first shape now here I have created one more prompt now here I'm saying uh suggest some strategy for the name so whatever name whatever name I will get from here startup name name for that what I want I want some sort of a strategy let's say I'm going to open or I'm going to start my attech startup so for that what I require tell me so I for that basically I required audience I required my team I required my Marketing sales team if I want to open any fintech startup or if I want to start any consultancy or whatever right whatever uh like company which I want to start so regarding that what I want I want some sort of a stategy getting my point here yes or no so now what I will do I will come combine this two chain see here this this is my first change this this this is what this is my first chain this one and this is my second chain now I will combine this both Thing by using simple sequential chain I will making I'm making a sequence I'm trying to make a sequence between these two chain okay before I I was just running with a single uh like uh with a single chain only and where we were having only two component llm and my prompt now here I'm going to comp my true chain now just tell me guys here I'm using this particular llm can I use a different llm over here I can try with that I can check right so here I'm using the same model now I can check with a different LM also in this particular case so this chain is a pretty amazing thing it is connecting a homogeneous component or it is it can uh we can connect a hetrogeneous component also means a some other model as well you can test it with the other model uh so here you can see we are able to do it now guys here what I will do so here is my first template this is my first chain this is my second template this is my second chain now what I will do over here so here I'm going to import a sequence uh so here I'm going to import a simple sequential chain here I'm going to import this simple sequential chain now once I will run it so here I imported now let me create a now let me create a object of it so here guys here is is a object now inside this object inside while I'm creating object I will pass some sort of a parameter so it will call my init method okay in a backend now here I'm going to pass some sort of a parameter and that's going to be a very very easy and here is the parameter name so change first is name chain and the second is strategy so automatically see what will happen actually first it will call to this one it will uh generate a startup name automatically it will give uh it it will give name to this uh particular uh like a to this particular template automatically it will fetch from there itself and I will be getting this strategies I will be getting this particular strategies automatically chaining automatically chaining is happening okay this one now let me show you how so over here uh what I will do so let me uh create object and here I just need to call a method so here I'm going to call uh method that's going to be a chain do run now here I want to open uh startup let's say startup related to the artificial intelligence so here I'm going to write it down artificial intelligence now here once I will call it so let me run it and let's see what I will be getting over here so I'm making a sequence guys between a prompts so it is saying that uh develop a strong marketing strategy and some sort of a information let's let me print it uh so so that I won't get this s so here is my strategies stay informed and up toate on a latest AI train develop a comprehensive uh AI strategy utilize AI tools utilize data dri inside so these are some sort of a strategy actually see automatically I'm getting see this name now which which we have defined see startup name which is coming over here okay then whatever name is coming from there automatically is going over here this inside this name and we are getting a strategies we are chinning we are chinning right now this is a simple sequential chin now here uh here we have one drawback actually uh we it is giving me a final answer it is not giving me a answer uh it is not giving me answer related to the first prom it is not giving me it is not giving me that particular answer it giv me a direct uh the last one answer from the last uh like a prompt itself if you want answer uh like from the entire prompt so for that also we have one method okay uh sorry we have one more class let me show you that particular class now so here uh what we can do so I already return the name so let me give you that particular uh name and here is what here is a name guys so the name is what now let's try to understand the sequential chain so so far actually we have understand the simple sequential chain now we are going to understand the SE sequential chain and it is having a more power compared to this SE simple sequential chain where we can uh keep uh the sequence sequence of the different different prompts and the different different chains now let's try to understand this sequential chain and here what I'm going to do here I'm going to uh copy one more code now let me paste it over here so again I'm going to create okay already I have a client so let me remove it it is not required at all so here is my prompt template and what I'm saying saying here I want to open a restaurant suggest me a fancy name now just see over here what I'm going to do I'm going to mention one key over here that is what there is my output key and what is my output key output key is nothing it's a restaurant name right now now just see over here where I'm going to use this output key so here I'm going to Define one more parameter one more prompt template and here guys you can see so in this particular promt template prompt template name we have a prompt template and here input variable kin and this a template now here is my chain llm chain this is my model this is my prompt template and here we have a output key now output key is what restaurant name so whatever name basically whatever name I will get from here I will keep inside this restaurant name and this restaurant name I'm passing over here this restaurant name I'm passing over here and here whatever thing I will get from here from this particular prompt I'm keeping inside the menu item and if you are going to create the next prompt you can mention over there now let me run it and let me show you what will be the final answer over here so here I'm going to import the sequential chain and here you can see so this is what this is my sequential chain and now let me copy it and let me paste the final code and here is my uh object of the sequential chain so let me keep it in a single line so here sequential CH this is the object which I have created now chain what I want to chain means like in terms of what I want to make a chain so this is the first name name chain this is the one now second chain is what food item chain means I want a food item regarding that particular restaurant now over here this is my input variable and here is my output variable restaurant name and menu items this one Whatever output I'm getting from here I'm keeping over here inside this variable whatever output I'm getting from here I'm keeping over here inside this variable and I'm going to mention inside the output variable if you want to make a further change you can do it according to your problem statement now let me run it and let me show you the final answer and the final response so here I am going to call this method chain okay so this is what this is my chain and here let me run it and see what I will be getting so chain and I'm passing cuin Indian so it is giving me cuisin is what cuin is Indian and here is a restaurant name there's going to be a Taj Mahal Palace Taj Maharaja Palace and here is a menu item now so guys this is the response which I'm getting over here can you see over here the response which I'm getting all the thing all the thing in a sequence now let me revise this particular thing revise me this particular concept so chain what is a chain which is going to connect two component so here what I did see here I have connected two component first is model second is prompt now in example two you can see what I'm going to do so uh same thing I'm going to perform now in the third one uh with the entire detail actually with the entire detail now in the third one I'm calling simple sequential chain in that I'm getting a output from the last prompt but if we are talking about a sequential chain instead of the simple sequential chain I'm using sequential chain so I'm getting a entire output over here means from first template uh from first prompt template to last prompt temp temp plate and here you can see we are mentioning this output key so whatever answers I'm getting over here whatever answers I'm getting from this particular uh prompt right we are able to store it over here and we are passing to the we are passing to the next prompt we are passing to the next uh like a prompt basically over here you can see this one same restaurant name and we are going to combine it finally so guys tell me do you like it did you understand it I will come to that the purpose and all everything will be clarified right so uh we will talk about because everything should be connected now to each see whenever uh like if you're going to ask to anything uh to your chat GPD what do you think tell me so how this application is working we are are we are like uh what we are going to do guys so we are reaching step by step actually we are trying to reaching to our final application understand guys so here if someone has created this shed GPT it they have implemented everything whatever we are going to run by using this Len chain here you will find out the memory concept okay let me ask one question to my chat gbt so here here I'm asking can you tell me can you tell me about something Taj Mahal okay so here uh I'm asking this question to my chat jpd now here you can see uh uh like uh here is the answer now I'm asking to my chat GPT 2 + 2 how much so it is saying to me let me run it so here it is saying to me 2+ 2 is nothing it's a five okay sorry uh it's a four right now here if I will ask to my chat GPT how much 100 uh multiply by 1,000 now if I will run it so here you will get the answer now here if I will ask too much said GPT who uh build the Taj Mahal can you who build the Taj Mahal so here if I'm going to ask this particular question so here you can see the Taj m b by the moual emperor so actually it is not going to forget the context whatever you are asking now previously it is able to sustain the that particular memory it's a biggest power of the CH GPT so we are trying to reach like step by step we are going to we are trying to understand understand all sort of a thing by using this length chain and then finally we'll move to the uh the end like a goal the our end application now over here this chain actually is very important if you want to uh like a retain the information from the first prompt to the last prompt for that you can use this uh you can use this uh sequence chain I can understand you are uh trying to understand that where we are using in a real time in a application and all I will come to that part okay but just understand over here so I was running the Sur API so here actually once you will read the entire detail of this s PPI of this agent so you will find out that in like uh uh internally it is using the chaining it is trying to chain each and everything back in a back end basically they have implement the chaining complete chaining just just try to read it and finally it is giving me the the like conclusion over here so in a similar way here I just shown you the example a very basic example but by yourself what you can do guys so by yourself uh like you you can uh like create a different different prompts and you can implement this chaining concept over there and you can understand in a better way you can search about the applications and all getting my point yes or no tell me guys this thing is getting clear to all of you if it is getting clear then please do let me know in the chat so are you able to get it uh please do let me know in the chat guys if uh this thing is fine to all of you I'm waiting for a reply guys if you can write it down the chat and if you're liking the session so please hit the like as well great now let's try to understand uh One More Concept and then I will stop the session uh today I couldn't reach to the hugging phase but don't worry tomorrow I will show you that and memory also so One More Concept is there memory now let me show you the basic concept now the uh the very basic concept of the Leng chain which we are going to use in a future that is going to be a document loader so let me explain this document loader also so here uh what I'm going to do I'm going to uh show you that how you can read any sort of a document by using this uh by using us this length chain now once you will search uh let me search over the Google Document loader document loader Lang chain documentation so simply I'm searching about this uh document loader on top of the documentation so here uh let me open this document loader so once you will come inside this module now and here is a uh here is a like option retrieval now inside that you will find out a document loader so CSV file directory HTML Json markdown PDF or different different document you can load and it is required it is required I will show you where it is required and once I will reach to the Practical implementation once I will create any sort of a project okay so then I will show you how you can read a different different files and how you can utilize let's say uh you have one information some information inside the uh txt file or maybe in the format of HTML or Json or maybe CSV now you want to read it from there and you want to give it to you uh you want to give uh that particular information to your uh cat GPT or maybe GPD model so in that case you will have to use this document loader so let me show you how you can use this a PDF loader so here is what here is a PDF loader so for that first the first thing what you need to do you need to install this P PDF so just open your jupyter notebook and here write it down just pip install pip install Pi PDF so once you will write it down this pip install Pi PDF you will be able to install this P PDF inside your virtual current virtual environment now after that you need to lo you need to write it down this particular command uh you need to write it down this particular import statement from len. doent loader import P PDF loader right from the documentary itself I'm going to uh take it I I'm I'm not going to write down by myself here I'm showing you the power of the documentation so once you will explore it you will get many more thing from here itself right whatever like you want so here I'm going to uh what I'm going to do guys so here I'm going to mention this import statement now we have one uh ex uh now here actually we have to call this particular method sorry we have to create a object of this particular uh class and here let me paste it down so this is the pi PDF loader now I have to pass my PDF I have to give the uh I have to like write it down the my path whatever is there uh in my local system so inside my download let me check any PDF is there or not so let me check with the PDF LM here is a PDF machine translation attention so let me copy the path uh let me past it down over there let's see it is able to read it or not so where is a path guys here is a path let me copy the path and I have copied the absolute path now where it is here is my code so here I pasted my path and let's see it is going to load or not it's showing a uni code error so let me put the r over here and it is done now let me check inside the loader that what I have so here it is created the object now let me write it down the loader over here loader do loader so once I will write down this thing so here you will see that uh okay l a d r loader do loader P object no attribute loader uh what is this let me check the documentation here they are calling loader and split and that will give you the pages great so let me call this uh loader and split and here I have a Pages now let's see we have a Pages yes I got the entire detail so see I'm able to read the PDF by using this document reader why I've shown you this thing because uh it will be required we use now pandas do read CSV for uh like collecting any any sort of a data in the form of data frame right so if I want to take any data if I want to format any data in the form of data frame so we use this pd. read CSV or we use np. array similarly if you want to read any a document by using this L chain you can do it you can do it guys so here there is another one and uh you can take it as a assignment you can read the CSV there is a complete code here is a uh code for the file directory here is a like HTML here is a Json markdown is there there a different different uh like a uh different different document loaders you will find out now guys uh let's try to revise the thing let's try revise the session what all thing we have learned in today's class in today's session and then I will conclude it and in tomorrow's session I will start from the memory memory and finally hugging face sorry actually I went uh into some depth Okay I uh I try to explain you Concept in a detail way that's why I couldn't start with a hugging face API but don't worry in tomorrow's session I will uh show you how you can uh how you can uh download any open source model how you can use any open source model by using the hugging phase API and then uh right after that we'll try to create our application that is going to be a McQ generator we'll see that how you can generate McQ by giving any sort of a text and where this document loader where this chaining memory each and everything will come into the picture and even the prompt also prompt template right now let's revise the thing what all thing we have learned so let me revise it over here so in today's class uh we have talked about so where is my pen yeah so in today's class we have talked about this agent I have shown you that how to call a third party API so here we have seen how to call a Google search engine Google search engine API Google search engine API so let's say uh your chat GPT actually has been trained till uh September 2021 data so if it is not able to give the information in a real time in that case you can use this agent you can call you can use the concept of chain right you can use the concept of chain in which scenario so where you have a multiple prong which is connected to each other not a simple application not a simple prom just for the testing I'm talking in a real time so I'm talking in a real time oh just a wait uh now it is fine so here I was talking about this uh Google search engine and uh yep and then we have talked about the chain prom template also document loader now this uh two thing is remaining so in uh tomorrow session I will start from the memory uh in tomorrow session actually I will try to explain the memory concept and then I will come to this hugging face API got it guys yes or no so how was the session uh did you learn something new so please do let me know guys uh did you learn something new from here whatever I have explained and uh how was the session how was the contain uh please do write it down the chat should I add a few more things things if you want then uh please do let me know please uh write it on the chat I I'm like waiting for your replies and you you can comment also so if you are watching re-watching the video and if you want something from my side you can write it on the comment section you can tell me over the LinkedIn and yeah that's it so I hope you are liking my session so please hit the like button if you are liking the content if you're liking the session GB 3.5 get updated till yeah uh recently we have seen that uhuh look at today itself so why we are using Len chain and advantages over other API you will get to know more about it in tomorrow's session otherwise just try to revisit the session in a starting itself I have talked about the limitations of the open a and I talked about the advantage of the open a clearly I have written it over here so just try to revisit the session you will get it and here I have tried to explain you everything what is a len chain it's a rapper over the open and uh your app here is a len Chen which is a rapper now you can hit a multiple Thing by using this Len chin yes day three note day three notebook will be available in your resource section soon it will be available don't worry uh yeah so this is it guys from my side I hope uh like uh I already told you the tomorrow's agenda uh memory and the uh hugging phase right so thank you guys thank you byebye for joining the session if you have anything any uh doubt or any concern or anything in your mind so just uh do let me know please uh write down the uh please write down your thoughts in the comment section and you can ping me over my LinkedIn as well so thank you guys bye-bye take care have a great day ahead we'll meet you soon on the same time at 3 p.m. IST tomorrow thank you
Info
Channel: iNeuron Intelligence
Views: 9,154
Rating: undefined out of 5
Keywords: ineuron, ineuron generative ai, hugging face tutorial, Hugging face api, hugging face api tutorial, hugging face api key, hugging face api free, huggingface api token, how to use hugging face, hugging face langchain, what is hugging face, how to use hugging face diffusion model, hugging face models, huggingface, langflow, hugging face ai, prompt template langchain example, prompt template in langchain, how to use prompt template in langchain, #ineuron
Id: OSR9YUTGcFk
Channel Id: undefined
Length: 126min 14sec (7574 seconds)
Published: Thu Dec 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.