Learning LLM Agents. How does it actually work? LangChain, AutoGPT & OpenAI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi you guys I have been learning a lot of things about llms AI in a recent weeks months now llm agents are pretty cool and I just want to share just want to share with you let's go maybe first of all what what am I talking about what I'm talking about is is when these chat engines actually go beyond simply extending uh you know beyond extending the text and completing it we're actually using some sort of tools in this case you see it did not only understand my text it understood what to search for and then understand understood how to generate a good answer for me that I would understand and to me so that takes several operations and simply querying open AI doesn't answer this didn't answer to me I was I was curious how do I actually what's behind this how do I do this now the plugins came out the chat GPD plugins and for example here I asked it to make some tips for me the pink soup a pink Lithuanian soup I love it um it have had all the ingredients uh listed you know that's something by we expect by now and then asked me do you want me to add this to instacart so that means it had to not only write the text not only complete you know the text but also that to somehow convert it into machine readable I guess code and just run something to ship it to instacart so that I have I have the card in my uh I have the items in my cart that was interesting again I wanted to know how that works um another thing I saw is Lang chain they've been working on this for a while now and they introduced this concept called agents so this is where um how I'm using this this word and I don't know how much it's used elsewhere but I think this is where it takes this pretty well and that is Agents so for example here you can see you simply ask it a question it tries to understand what's in that question and what kind of tool it needs to pick up to answer your question in this case it needs to do search because it needs to find DiCaprio's girlfriend's name so it does the search function and finds the name sweet then it thinks it says oh I think I think that um that yeah that's her name and then it's like what am I what else am I missing oh I still need to do some search what's your age that's her age and now the final tool actually picked up was a calculator so he did some math operation here um yeah so that's very interesting I like this they make it very easy to actually do this to you but I wanted to see how it works behind the scenes and hopefully you want to and the last cool things that I've that I've seen has been blowing up in the last couple days it's is this Auto GPT an autonomous gpd4 experiment uh where you simply Define the name the the role of AI and then you define its goals so here you just say hey invent an original recipe for something for an Easter and then describe multiple goals and it just keeps on going until it actually finishes that task that means it goes on looks what kind of tools it needs to use it picks up that tool it picks up the other tool um and you know until it completes its goal and it keeps on evaluating whether it reached its goal or not um so it's very very interesting it's wanted to see at least the principle and and yeah and and this is what I did this is what I tried to do essentially uh you know let's I did a little bit of a a little technical graph for you so do you get it you're welcome yeah so what I what I built out is this you know you come in with a question a question comes in I asked the AI to say what is this question about so that I understand which functions to run and I run those functions the outcome of that is evaluated by AI again and then if it's okay then it's made readable uh and returned as in the answer so I think that that's the sort of structure where this works but again this still doesn't feel that practical and but when you put it in code actually it is a very it became becomes very clear so first the very basics this is how you ask a question not on chegebd but with code and that's extremely simple you simply say for the system you feed in the instructions and for the user you feed in the question that's it so you basically can do this uh you know because we defined as gpd4 do it the instruction is due and the content the user question is it and it does not understand what I'm talking about very good good AI good bot uh we continue here let's define the instructions to make sure it really works you know the instructions are helpful assistant that's what usually you define it as and question in this case please give me three random names of a puppy so we have some from my testing day time so let's see what comes up now okay actually came up with a very similar suggestions but hey so now we know how to ask GPD questions uh we'll ask it to essentially improve itself understand whether it's reached its goal or not that's that's what we're going for so now let's make it think let's go let's do it so first let's define the tools you know we want it to decide what tool to use in this case I thought it would be the most simple to say here are three tools one is addition subtraction and multiplication and you know that requires two inputs each so it's all very simple but I wanted to see if at least this can work um and yeah so we run it we make sure it's defined so now we have these functionalities and if you know code you know that this can be literally anything and I think this principle would work on any kind of function that you any kind of tool that you build for AI to be able to use um yeah and here's how we how we actually instruct AI to say you know hey determine which tool do you need to use this is exactly how it works so as you saw in the instructions right we set here to be helpful instead we can do some prompt engineering so I guess this is where the prompt engineering comes in you simply say determine the appropriate category you know it can only be one of those three based on the user input and extract two numbers because we can only use two numbers that's the limitation what we're playing with now and then format the answer in a specific way provide Json only because this is what computers can understand so that will feed that instruction to it and now here's the question now we can just phrase this in any way you want we want uh we say two uh times seven right and then let's see now you see I printed thinking so it seems like it's actually it's actually thinking it's very good and it printed out this is what it printed out so now it printed out a machine readable piece of string in this case but it's just it's machine readable and it knows that it's a multiplication what if we just change they took five apples from me I had ten how many do I have let's see so now if everything works correctly it understood that this is subtraction and it's you know subtract from 10 it's 10 minus five essentially now it understands my request and we can do it in many different ways and it is strictly instructed to be adding everything in this way okay that's great so now um now that it we we have the answer we don't we want when we actually printed we want this to sound like it actually had some observation so we simply said you know instead of printing this out you know while we're working on it just tell us what the observation is in human words and you see we just asked we just said basically human used human words to describe what it found um so that's good now we run a simple simple uh essentially python code to use this information to decide which tool to use so in this case we know that it has to be a subtraction so we're gonna have to use this tool and we run um and we run again so this is where we're going to run it you see so it was trying to find the matching operation it found that it needs to be subtraction and then it executed it which is this and it found the answer to be 5. so 10 minus 5 equals 5. so it got the answer which is 5. that's great so now we have the answer but maybe we do want to just respond with answer is 5. we actually want that to be more readable so you see you have found the answer on customer's question phrase it in a nice sentence that's another piece of prompt engineering we feed in the question that was originally asked and we feed in the center which is five yeah please just make it nice make it readable you know so it and so it actually will phrase it in a nice way like we saw Bing um do you now have three apples remaining after the customer took five from your initial count of 10. see so it phrased it according to the context and now we had AI consult itself look for tools use those tools and then rephrase the answer and just make it appear like yeah it was uh yeah it's very smart now you know once you see this once you see this once you understand how this works you can even extend it a sort of infinitely um and and you can make it you know not only just decide which code to run but also just make up their own code and and Etc and etc etc and you can also make it you know check make its check that this actually answer all these questions in this case we only asked one question but we could you know have instructions saying hey you know the answer is five but what if there was an additional question there did you answer all those questions and and then you know you can sort of detect like yes oh yeah everything is answered or no it wasn't and it all depends on how good you you redesign this uh you redesign this prompt so it's you've got to be good at English and talking to the computers not necessarily in code so let's try and see this so I had an additional question added it's gonna do the thinking and here I strictly asked only to return the SVC so there's no mention of Saturn in here and that's a problem the user expects all these questions and it's just going to go along solve that problem that it can't solve which is just five apples and ten Apples and it's going to resolve that I'm going to resolve this and I'm going to find the answer which is five so still nothing changed and now yeah so now it's gonna and so now we have the answer five but did it the question is did it actually answer all the questions we can say you have to make sure all the questions are already answered and your question is this and the answer that say either yes or no and which questions were not answered and you see it says yes all questions are answered so it seems like I phrased something incorrectly now let me just try and find a version where it actually works yeah so I I rewrote this making it a bit more explicit but there's still a lot of room for improvement but here I said you have to make sure all customer questions are answered at the beginning I preface that and then it it actually understood that hey no not all the questions are actually answered we only answered the math question but not really the Saturn question yeah and yeah but there's it's a whole another topic the prom prompt engineering um but yeah but here you can see how we can make a seemingly thinking AI provided with tools and it keep on um yeah keep on going becoming your personal agent I think I think this is awesome yeah I hope you liked it bye
Info
Channel: Arnoldas Kemeklis
Views: 10,101
Rating: undefined out of 5
Keywords:
Id: mb_YAABSplk
Channel Id: undefined
Length: 13min 23sec (803 seconds)
Published: Tue Apr 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.