LangChain Deep Dive: 5 FUN AI App Ideas To Build Quickly and Easily

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so in the previous videos we had an introduction to Lang chain which is an amazing framework in order to build AI apps and ever since I published that video we had a lot of questions from people in terms of what Lang Chang can do why should people be using it etc etc and so in today's video I'm going to be giving you five real world apps that you can build with a lang chain and then later in the video I'm going to be showing you how you can integrate a lane chain app with a null code Builder such as flutter flow so this is going to be a value packed video today watch it until the end you're gonna get a ton of value now before we begin as always all the apps that I demonstrate and or build in all of my videos are available to view and or clone from my patreon page and you can learn more about it and perhaps become a member in the description just below the video now before we look at some of the app examples let's have a quick refresher or what exactly Lang chain is after you watch this part of the video everything is going to be a lot clearer and you're definitely gonna see the value that lane chain provide and so here's a diagram that I created to kind of explain to you what is the value proposition of Lang chain what is you know what does it do how does it help us because you know we have all of these no code Builders uh we have all of these tools at our disposal we have chat GPT we have you know GPT models we can use all that so what exactly is Lang chain bringing to the table well it's actually very very simple what Lane chain brings to the table is it allows us create different components around these uh llms these large language models and so instead of you having to do all of that by yourself and Grant that it's easier with all of these no code tools but you still have to do a lot of work and all of this work is done for you uh if you use this framework okay so as you can see in this diagram like the main star here right the main thing that makes it all possible is the nlm okay because we are building new types of apps right we're not building you know these uh traditional apps okay we are building apps that get input as just language right they're not getting input as something specific where the user does this does that they're getting input when the user is talking to the app essentially right so this could be like English language right maybe the user is saying hey you know calculate this data summarize this and you know find out the weather you know in this city you know in this uh in this place um they're essentially speaking uh using regular language whether it's English or or another language right and so this is what Lang chain is all about right Lang chain is about having components that are kind of talking and interacting with the large language so in the center we have this llm which is this large language model and you can use different llms but in my videos right now I'm just using open AI because that's what you know most people are familiar but this is just one component of the overall pitch because we also have problems we have you know short-term memory we have long-term story we have different tools we have document loaders and we also have agents okay and so what are all of these things do well the prompts is a way to structure you know how we are going to be interacting with the large language model okay because they're all about prompts you basically tell it what you wanted to do and if you give it a high quality prompt you're gonna get a high quality result if you give it a low quality problem you're going to get a low quality result and so this part and many times it's also very repetitive right you know you just have to you know enter that prompt over and over again so it's nice to decouple you know this thing from you know having it hard coded here and this is exactly what it's doing and same thing for you know things like memory and storage and stuff like that you know you are you're interacting with the chat model so it needs memory but in some cases it also needs some storage right you may want to store something uh you know for later where you're going to be storing maybe maybe a conversation you had an interaction and then later you're gonna you know retrieve that data so all of these are the cup right all of this is important and it's kind of painful to do programmatically I actually had a video where I did embeddings and Vector storage and all that and that was painful to do right you know I needed the script I needed this I needed that lots of little moving pieces and Lane chain takes care of um all of these things for us right this includes memory short term it also includes things like embeddings right so I can add another little module here right embeddings which are essentially ways of storing data where you can compare one piece of data to another and figure out how related they are together very very powerful concept but very simple to do with something called embedding so you can actually add a video where I talked about that in Greater detail and that's not all right we have things like tools that allow you in allow the model to access the internet allow the model to do things that it can't really do before we have things like document loaders right and this is where you can actually give it a document that maybe in your possession maybe a private document a company document and you can you know set the model to kind of talk talk to you and you know read the document and and you know be a chat bot uh specific to that document which is awesome and I'm actually going to have an example a little bit later in the video where I'm going to show you how you can create a chat bot with a PDF and tie that to flutter flow so stay tuned for that and last but not least we have things like agents and these are essentially modules whose job it is to create different tasks and essentially to do stuff on your behalf so in many cases you know you can create things like Auto GPT baby AGI and essentially what they're doing is they're generating a list of tasks and then they perform those tasks on your behalf okay and we're gonna get to that a little bit later as well so lots of things happening here but really the star is the large language model which is the real breakthrough in a sense that you can talk to it in in pure you know English or whatever you know language uh that that you want to talk to it in and that really changes everything and that is why Lane chain makes this process of talking to large language models simpler than if you had to do everything by yourself even if you were using like a no-code tool Builder because no code tool Builders are designed for building apps they're not designed for you know simplifying dealing with large language models they're not designed for that and that this is where Lang chain comes in alright so now that we had a little refresh of what Lang chain is and what it brings to the table let me show you some some examples starting from some simple ones leading to more complex ones so we are going to be using a tool called flow wise Ai and I covered this tool in my previous video so if you have not seen my previous video definitely check it out but in two words uh flowwise AI is essentially a tool that allows you to build a lane chain apps uh visually by dragging and dropping okay makes it a lot easier and it's perfect for us because we're building apps without any code and so this tool makes it a lot easier now the first example I want to show you is a very very simple example but still an example that you can easily build a very very useful app around okay and this is a product name generator so if I click on this I'm redirected to kind of a canvas and I have different modules kind of happening okay and so this is exactly what it talked about in the beginning of the video where we have this main module which is our interface to open AI in this case this is open AI which is a large language model and I provided an API key I also picked the model here this is the default model and I have a temperature and on this side I have a prompt template and this is exactly what I talked about in the beginning of the video because for this specific app the purpose of this app is to come up with good names for products that we're gonna specify in the prom so let's say I have a product that's a tool for helping people build with firestore DB as an instance right I don't need to specify all of that all I need to do is specify the name of my product and it has the prompt already and so I don't need to repeat myself over and over again and this is what this prompt template does it simplifies me dealing with prompts you can think of it as kind of prompt management which makes things a lot easier and tying these two things together we have something called an llm chain right and if you click here you can see that we have many many chains and their job is to tie things together they're chaining things together and you can chain you know a couple of modules you can also chain multiple modules or like sets of modules together to another set of modules so it's very very powerful and so once we've set up everything here you can click here and you can interact with this Lane chain app here and because we have this prompt template already configured and already kind of set for whatever we need to do we don't need to type at all you know every single time we need to interact right all we need to do is give it a product so let's say my product is uh you know software that helps users Firebase projects or something right I just send answer that and I get a response Firebase Builder okay very very generic but I can try something else how about software that helps people learn foreignly okay press enter language learning helper okay fairly generic but you know still a name how about something like a tool that helps you know parents raise kids or something like that let's raising right parenting toolkit okay so you know raising right actually that has a nice ring to it okay it's still fairly generic but it does have a nicer nice ring to it okay and so this is an example of a very very simple app now obviously you can customize this you can customize the behavior by changing the prompt here okay so if you change it to something like this and you enter something like you know shoes okay it's gonna come up with a name okay there you go and you can take it as far as you want it's a very very simple example and you can obviously tie it to an app that you're building you can simply click here and you have API access right this is the same thing as done by clicking here where I'm you know typing something in all I need to do is copy this paste it into my you know no code Builders I'm going to show you at the end of the video and then here you can send your request and so when I'm saying something like shoes or computer that's essentially what you're going to be doing as an API call using this format here so question would be shoes or computer and now you have a fully functioning app that you can expose using an API it's a very very simple example but at least it should show you some of the potential now the next example I want to show you is a little bit more complicated and this example is right here and so in this example what we have here is we have our instance of our chat open AI which is our chat bot and we are using a GPT 3 3.5 turbo right which is what a lot of people are using uh in chat GPT next we have something called buffer memory and we also have something called the conversational agent that uses something called a get okay that's one of the tools and there are many tools that it can use and so at first glance it could be a little confusing in terms of what's Happening Here okay so let me show you exactly what's going on now before I actually run this app here I want to show you something else so right here we have a URL that gives us back some random data and in this case it's basically facts about cats and here I loaded up this data and this URL gives us back Json data and in this case it gives us five facts about cats in Json format so here we have Fact one fact two fact three a very strange one and then another fact and then the last one here now let let's say you want to feed this data into chat GPT and have chat GPT tell you something about this data Maybe summarize it or do something with it well you can't do that right now because Chad GPT does not have easy access to the internet that might be available in in the not so distant future but right now it's not possible to do well you're in luck because this app here right this flow here in fact does have access to the internet and it has access to the internet because it uses something called an age okay and so remember we talked about agent and agents they are modules that do tasks on your behalf okay so in this example we have an agent that takes an input uh chat model it takes memory right because it needs to uh keep state right it's a chat model right this is a conversational agent so it obviously needs memory to keep track of the conversation and last but definitely not least this is the most important thing is that we give tools that it can use in order to reach a certain objective to get the data that we need and right now we only give it one tool which is the ability to get data using this get module okay and so now I can chat with it and I can actually tell it hey there is this file which is a list of you know a list of facts or having to do with cats you know why don't you go out and you know download this data and tell me something you know that I might need to know about this data in this file out on the internet okay and so I can paste this request right here I just say tell me about this list from etc etc I can even do something else I can do what this file what this list is about and then I specify the URL so I'm going to execute that and it fetch the list it analyzed it and it told me the list is a collection of cat facts each item in the list contains a fact about cats along with info information the source and the status of the fat so how about something like this tell me an interesting from this list okay so something like this and let's see what it does cats make about 100 different sounds dogs make only about 10 and this is actually one of the fats I bought this one right here this is the first fact here okay I can say something like this sell me another interesting fact okay domestic cats spend about 70 percent of the day sleeping and fifteen percent of the day grew me and so if you load it up this is the second fact right here and so as you can see it was able to get this external data and now we can talk to it as though you know it it knew all this data all along which is actually pretty cool but this is not even the the best part right the best part is we can attach more tools to it and this agent will figure out where to go in terms of what kind of data it needs okay so as an example we can just come in here we have two we're gonna go into tools and we have various tools so things like AI plugin we have a calculator we have a chain two we can read uh but an interesting tool that caught my attention is this one right here this is a serp API okay so we're gonna drag and drop it we're gonna put it right here and then we're gonna connect this and now this conversational agent has access to a serp API now what exactly is a serp API well serp s-e-r-p stands for search engine result pay and what this allows us to do is it allows us to query Google directly and parse the results and use it inside of our blank chain app now before you can use it you need to get your API key from the service uh called serp API and you can actually get it for free without entering any credit card details or anything like that I have a free plan and so you can go to serpapi.com and you can get your free API AI key in order to query everything Google and once you have your key you can query you know Google search API you can query Maps API jobs API every everything pretty much Google and also other services right like go by do Bing eBay YouTube all kinds of interesting things but in this tutorial we're only going to be querying uh Google in fact the agent is going to figure out where you know what's the best source to get the data that we need okay so once you've gotten your free API key go ahead and go into your account copy your API key and then paste it in here right you're gonna paste it in here and now this conversational agent has one more tool that it can query in order to get the right data and so now we can just save this new flow here remember always save it and so if you do not save it and you added a new module the you know when your chat chatting with it it's not going to know that you added a new module and you might not get the results that you're expecting okay so now we can come in here and we can say something well what's the weather San Diego right now we can do that and now it has access to Google and it should know that for this kind of information I need to talk to Google this is what this agent is doing and so this is the results the weather in San Diego right now is mostly cloudy with a high of 66 Fahrenheit Southeast winds are shifting to West at 10 to 15 miles an hour so 66 Fahrenheit is like 20 degrees Celsius which sounds about right and so 66 degrees Fahrenheit sounds about right for San Diego but to double check that I can go back into my serp API dashboard and I can see that here we have weather in San Diego that I just searched so it actually went ahead and it executed the search and it realized that you know it needs to go out and you know execute the search in order to get me the data that we need very very smart now remember you can add more tools to you can come in here you can go into tools and you can add more tools right so for instance a calculator and the reason you may want to add the calculator is that llms large language models are not really designed to calculate things they're really good at you know doing completions that is essentially generating text knowing what came before it and they will know what came after it but they're not really good at math related Tech and so you can drag and drop a calculator here and you can connect it and then you can ask you know various math questions and get interesting results knowing because this conversational agents now has access to different URLs has access to Google and it also has access to a calculator as well now the next example I want to show you is a bit more complicated than the previous example and I want to show it to you because I want you guys to see some of the possibilities that you can do using Lang chain and this is this chaining example so if you open it up you can see that we have quite a few things going on here on the screen but most importantly I want you guys to take a look and see that we have this thing here and we have this thing here and we can chain them together actually remove the chain but we can chain them together and these are two independent uh kind of executions or completions if you will okay so we have open AI we have a chain that links them together and we have our prompt template remember we talked about this uh as one of the first examples one of the initial example and then we have another one and so what's happening here is in the first one we are giving it a prompt and we are saying uh you are an AI who performs one task based on the following objective and we give it an object respond with how you would complete this task okay and then the second um area here the second part what we are doing is we're giving it a prompt you are a task creation AI that uses the result of an execution agent to create new tasks with the following object right okay so that's the problem but we also give it the prompt before the last completed task has the result result based on the result create new tasks to be completed by the AI system that do not overlap with result return tasks as an array now this result here is actually set here right and so if we link them together we this second module is going to have access to that first uh to the res to the result in the first part right so if you see that right if we don't link them together we open that there is nothing there is just the question which is the objective that we specified but if we link them together and we open this up we all we now have access to that first chain we can just copy it here and paste it in here okay and now this Pro prompt takes the values from here right so remember we have this objective and result and that's actually pulling in the very uh the values uh from objective and result and result is actually taking it from this result here so let me show you how this works without changing it and then I'm going to show you how it works with chaining it so if I break the chain it's only going to execute this part here it's not going to execute this because there is no chain there's no link okay and so I can come in here and I you know and I want to maybe give it a task to do right this is you are an AI who performs one task based on the following objective so what is the object the objective may be um you know create a weather report or San Diego California okay so we're gonna do that and it's gonna come up with list of tasks that it needs to do in order to create this report all right so it's finished and it gave us a list of things that it needs to do 2 in order to do this report so there's many many steps okay so it gave us a list there are 10 things analyze the current weather conditions compare the current weather identify any potential weather related hazards in San Diego create the forecast etc etc so this create a weather report right it's not you know something that you do and it creates it right it actually gave you a list of things that it needs to do in order to do now if we link it together you will see the difference it's actually going to be creating tasks instead of just bullet points it's going to go one step forward because we have now two execution and so first is going to create you know this list that it just created but it's also gonna create now specific tasks that it needs to do in order to actually generate this report so I'm going to execute this we're going to wait a few moments all right so it came back with a list of tasks this time right this is the next step this these are more concrete right in the beginning we had like an outline of things that it needs to do potentially in this case we have specific tasks that it needs to go out and do more concrete examples we're getting closer to our end point right this is kind of what it's all about and now we have task one gather historical weather data for San Diego from the past month analyze the data to determine the average temperature uh compare the current weather conditions to the historical data to identify new trends etc etc and then task five create a visual representation of the weather report for San Diego California right so this is more specific right it's it's more specific it kind of gets us closer to the end goal if you will and we are going to be covering these kind of steps and having um these uh these models these Lang chain apps uh do all of these tasks for us uh when we're going to be talking about Auto GP T and baby Aji and I'm going to be covering them in the series that's probably going to be one of the next video but right now the takeaway I want you guys to have is that this is kind of the next step we sell AI create you know an outline of what we need to do and then take that outline create a bunch of tasks and so the next step will be to take those SAS and actually do the task and give us the result that's kind of what Auto GPT does on baby AGI that's kind of what the you know the the meaning is kind of what they're trying to do with um with those models right they're they're autonomous agents meaning you give them something and they go through all of these steps and they get you the end result because essentially that is what you'll have to do uh by yourself right if you were gonna do that you know if you were gonna do that from scratch you're gonna create a list you're gonna go through the things you're gonna you know go through each of the tasks you're gonna maybe you know combine the data that you're getting combine all the results and stuff like that whereas here it doesn't it all for you so a quick example where you can chain things and have one completion as an input for the next completion obviously you can chain more of these you can chain as many as you want you know as many as the memory allows you in the system to kind of chain together but that is a great example that you can use to build apps that generate some kind of reports something more sophisticated something more complex and last but not least I want to show you an example that I think many of you have been waiting for and I think an example that many of you are gonna absolutely love and I can see many of you also uh building apps around this exam and this is a chat PDF example so if we click here we have here A Lang chain flow Lang chain app that allows you to upload a PDF and then create a bot around it so I'm going to show you exactly what's happening here and then we're going to jump into flutter flow and I'm going to show you an app that I built very very quickly that interacts with this model and as a result you have a very very nice chat bot where users can communicate with a specific PDF file and if you stick around until the end I'll also show you how you can create chat Bots not just around a PDF file but also around different entities around different pieces of data so definitely stay tuned for that now the first thing that I want to bring your attention to is this PDF file module right this is kind of the star of the show we have a PDF file module and I actually created a PDF file which is a lease agreement that looks something like this very very generic lease agreement and if you're not familiar with what a lease agreement is it's essentially a contract that people that at least something in this case maybe they're renting apartment they sign with the apartment owner and so this has things like you know the the kind of apartment they're renting um you know the cost of the the rent the deposit the terms and things like that and the reason I decided to use this example is because um a lot of these you know leases and agreements and these contracts they have a lot of you know legalese right these are like legal terms and a lot of people get confused you know can I you know can I do this can I do that well it's all in the lease except it's kind of hard to understand it if you're not a lawyer and that is why building chat Bots around these uh legal documents is very very popular uh because it allows people to to find out what's happening right allows them to kind of understand what's happening and so we have here a sample lease agreement there's you know conditions for deposit you know how big is the deposit um you know the the stipulations for if you are you know if you don't pay the the rent on time uh you know when can you get a deposit back etc etc lots of little things and so for instance it says here if the rent if rent is not paid by the fifth of the month it shall be deemed late and tenants shall pay a late fee of thirty dollars and also we have damage deposit 500 so all of these things are here and you can actually chat with it okay so once I had that lease agreement I essentially uploaded here I said usage as one document per page and I also have this character text splitter that I'm using chunk size of a hundred uh chunk overlapped one and these are just defaults right these are defaults you don't have to worry about it and what it's doing is it's splitting it up and it's connecting it to something called an in-memory Vector store so remember from this diagram we have memory and we have store so in memory Vector store is memory right and it's it's only set it's only available for the um for the runtime of the app so as long as the app is running that data is available when the app is exited it's not available anymore you have to load it back again ah there's also something called long-term memory which is storage and you can use app uh tools like pine cone which I talked about in one of the previous videos for that so you have a couple of options here and so I'm using this and I'm also connecting embeddings right I talked about embeddings in one of the previous videos you should definitely check it out but essentially what embeddings are is that if you give a different text different sentences maybe paragraphs and you convert it to embeddings and later on you will be able to compare those embeddings that represent different you know strings different pieces of text in order to realize how related they are and this is useful when we are creating chat Bots right because we're going to be asking questions and we need an answer that's the most related out of all the other you know pieces of text so the question that the user okay and that is why we always you know with Vector store you're always going to be using embedding so we have open AI embeddings we have this document that one on one side we have the document on the other side we have embeddings that are linked to this in-memory Vector store which in turn is linked to this chain remember we always have to use a chain to chain you know the input to a model right so we have this something called the conversational retrieval q a chain that's perfect for creating chat Bots right so we have a chain and the chain wants a vector store that is going to be talking to and it wants an llam which is exactly what we have here and so now you can kind of talk to it and you can say like what is the deposit okay so you can say you can ask it something like that and there it is the deposit is 500 500 and you can ask it something like uh what is the late fee for you know paying rent okay and here you see the late fee for not paying rent on time 30 dollars and this is exactly what's stipulated in the rent agreement right except it's legal lease and here it's nice and English all right which is awesome and obviously you can continue asking it more questions in order to kind of understand what the document is about but the real value of this is building an app around it and that is exactly what I did I built a little flutter Flow app that interacts with this model and so here's the app that I built and before I show you how I built this app let me run this app so that you can see exactly how it works and then we're gonna jump back in and I'm gonna show you how exactly I build this app so you can do the same as well so we're gonna create a new test session here now here is the app and on this page we have a list of different chats and we only have one chat in this example this is this lease agreement chat yeah I know it sounds kind of generic but I couldn't think of a better name so if you click here you can kind of chat with it right so you can say something like how much is the deposit us how much is the the pot you can send it's going to send requests to our model and hopefully get the right result okay there you see the deposit is 500 another thing that you can say is what is the late fee for paying rent late right okay the late fee for paying rent late is thirty dollars uh is the tenant responsible for utility yes the tenant is responsible for utilities okay and so you can keep chatting with it you can keep asking it different things about this PDF document but as you can see it seems to be working fine and now that you've seen the app let's jump back into our flutter flow UI and let me show you exactly how I built this app if you've seen uh some of my previous videos where I built different chat Bots I think the design here and the way I build this app should be already familiar to you but if not definitely pay attention uh in this next part and so here's the app the first thing that I did is I connected Firebase to it okay so I have Firebase connected to it firestore DB and this is the scheme I have users chats messages set up and if we go into my firestore DB here I have chats I have one chat document I have an image I have a name and then I have different messages to it right these are the messages that I was asking so I asked three messages I got three replies for uh for a total of six months and so if we go back here we have this setup and now we have kind of the main app and it's actually very very simple it's a very simple app we have a bunch of screens I have login and profile these are just standard screens because we need the user to be authenticated so these are just standard screens but the main screens are these two right chats where we're listing the the main chats and then chat messages so chats is simply a you know it's just a list it's just a list view of different chats that we have right so this is this list view we have a backend query chat list of documents and obviously we're just displaying the um the name of the chat and the image which are the only two fields on that chat on on those documents that collection of documents they only have two Fields here right these are right here these two Fields here that is kind of what we have now when we click on that we are redirected to the chat messages which is another list view here and this is where we display the messages now I'm doing something interesting I'm using a stack and the reason I'm doing a stack is because uh a stack in flutter flow means that you can display different things underneath that could be the same and uh in this case I have two rows right I have row other and row me and these are displayed conditions so row other is the row that's displayed left Justified row me is the one that's displayed right Justified so if I come in here and I actually display well I don't you know I just don't display this one you can see this one is left Justified and that is how you display Bots right you left Justified whereas uh text from the user you write just the time that is kind of how all chat apps work and you know at least the chat apps that I use telegram iMessage WhatsApp etc etc and essentially what I'm doing is I'm checking is this a a bot message is this a user message and if it's a user message I display it on the right hand side if it's a bot message I displayed on the left hand side now the key here is this thing right here the send here right so if you go to the send we have four actions uh the first thing is we need to save the message this is what create document we're creating a message as the user entered something we want to save it right away and then we have a back-end call and this is where we do the API call remember for all of these apps right that we have here um you can just click here and you can access this using an API right so this is an API here you you can just specify the question that you have this text that you want you know the question about the PDF document and you're going to get back a response with the answer right so if you go in here right you can see this right here and you can actually test it so how much is the deposit we can do a test API call and you see you're getting the response back and what's nice about it is this is a direct response uh you don't need to parse it like you typically do with um you know with uh with jsons where you have all of these you know like very intricate data and so you don't need to do that at all you just get back a response right there and so what we're doing is we're creating the user's message we're executing the API we're checking if it's succeeded if it is we are saving the response we're saving it and that means it's going to automatically show up in that list because that list is dynamically updated and then we're just clearing the text fields and that is all you have to do when it comes to flutter flow and why is that because all the complicated things is done in Lane chain and because Lane chain is a framework that allows us to kind of do all of this very very quickly and easily it would be a pain to do all of this in flutterfly actually did something similar uh directly in flutter flow and you can find the video I had a video where I built all of this in Florida flow you can watch some videos back but this is so much easier because all I need to do is create this link chain um app here and then all I need to do is access you know things that I need communicate with it using an API very very convenient very very awesome and so that's why I highly recommend to you guys to get up to speed with Lane chain and kind of understand that because it makes creating AI apps actually fun and painless it's a lot easier to do it using this visual drag and drop interface as opposed to doing it all in code even if you're using no code tool now as mentioned earlier if you are interested interested in viewing and or cloning this app as well as getting access to all the flutter flow apps that I did on this channel plus extra content then you should consider joining our amazing amazing patreon community and you can see a link to it in the description below this video now if you guys enjoyed this video and you're looking to learn more about link chain check out another Link Chain video that you're gonna see in the corner of your screen right now
Info
Channel: James NoCode
Views: 6,746
Rating: undefined out of 5
Keywords: langchain tutorial, langchain nocode tutorial, langchain modules
Id: mPYEPzLkeks
Channel Id: undefined
Length: 40min 31sec (2431 seconds)
Published: Thu May 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.