LLM In-Context Learning Masterclass feat My (r/reddit) AI Agent

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what you see here is kind of how I built the brain for my Reddit AI agent so today I'm just going to go through kind of how I thought about this how I kind of built it and put everything together so that my AI agent can go onto Reddit answer poorts it should have knowledge about so I think we just going to get straight into it here so you can see I had to start by selecting some kind of topics I wanted my AI agent to have knowledge about so we can give good responses to these posts on Reddit so you can see uh some examples here I wanted my agent to have knowledge about let's say CLA 3 the term AI agent mrol 7B and a whole bunch of other keywords I will show you later so what I did uh I went ahead and kind of created something I called brain content for these topics right so it consists of kind of a knowledge base we have some rules that the agent has to follow we have example pairs of like uh ready comments and answers I have given there and I I Tred to I have started to include some bad examples of what I don't want and all of this brain content here is going to be of course fed into context into our prompt so you can see this is kind of how I set it up we're going to take a look at the prompt after but we have like example comments and then we feed in our example pairs we have the knowledge base we feed in our knowledge base and the prompt gets very big right but we are using a sheep model so it doesn't matter too much and here we have kind of an example of what I can feed into our brain right so all about AI Chris favorite model for coding at the moment so here I kind of said CLA Opus and I wrote something about CL Opus what I like about it uh I gave some factual information about CL Opus so the context window potential uses differentiators the highest intelligence than any other model available and I have some information about the price right for CLA three Opus and this kind of I did for uh a lot of these AI models so let me just show you a quick draft of kind of my brain so here we are kind of into the file I have called the knowledge base so you can see there's a lot of information here 565 lines so if you go at the bottom here I put in some information about rag so that's retrieval augmented generation right and yeah we have some information about here I kind of want our agent to know about if we go on top you can see all about AI creas knowledge about AI models so we have close Source models so Google Gemini 1.5 Pro it has a 1 million context window we have CLA gp4 turbo we have CLA 3 hiq and yeah just go on and on and feed in a bunch of information here and we have let's say here you can kind of see we have I think we have closed open source models so you can see down here open source models m mol 7B mixol and yeah you kind of get the point we feed in a lot of different stuff here and I even included some information about Nvidia Hardware so Nvidia Blackwell gpus h100s b200s so all the kind of the topics I want my AI agent to have information about that we can use to answer Reddit comments and you can see we have the information about the latest lmc's chat Arena leaderboard so I kind of fed in all of that you can see cloy Opus on top here and we have yeah you can see information about llama index Lang chain and all the things I could think of that an AI agent that's going to go onto Reddit and look at a few specific topics has to have knowledge about to give a good answer right and here you kind of see I have I think it's 15 comments so far 16 comments I kind of like so I gave like this pair example so we have the post title we have the post content and I kind of included the response here from me so this is all responses that I think was very good and I kind of want the AI agent to mimic when it respond to different comments on Reddit right and again kind of same here here some rules I want the agent to follow so you can see try to promote your YouTube channel all about AI where you do experiments demos with llms and AI where it fits so this is kind of the the part of the agent that I wanted do some kind of promotion for my YouTube channel right but in a very subtle way a good tip I want to give you if you want to build your kind of brain is I use perplexity doai to kind of let's say here I said explain what rag is for me and then I got a pretty good answer here about retrieval augmented generation and this is something I can just feed straight into my brain so a good tip is to use perplexity to kind of uh create the content for your brain right so for me I think that worked out pretty good but I also tried to add some of my own knowledge so the bot gets a bit more personal right so yeah that is basically how I built this up uh we're going to take a quick look at the prompt for we kind of need a full prompt to see how this works in practice right but if we move on and take a look at how the agent works here because this is the other part right so this agent is kind of built up to search and fetch a Reddit post uh so we fetched the title and we fetch the p uh content from these keywords with search for and these keywords will of course have to be uh the topics we have information about so we're going to take a look at that soon too and I added a feature that uh if the post contains a URL or an image it doesn't have any like content like text it just have a URL or an image uh we're going to scrape that URL and try to bring that into the content and we're going to use the CLA 3 image elevation model to look at the image and get a description back so this goes over to kind of our uh python code I just call it agent system here and it sends this post out to the claw 3 I'm using the Sonet API very happy with that here it's kind of cheap and it produces good results so this this kind of gets combined with our AI agent brain to construct the comment we will have then again post on Reddit or respond to the Reddit uh Post in like a comment form right uh so basically it's a pretty easy setup the actually agent part the hard part is going of create a brain uh or a system that generates good answers right kind of the agent part is pretty easy to set up uh but yeah that is basically how it works I think we just going to go through a few lines of uh key lines in the code and then we're going to do some testing I'm going to show you some examples of what kind of results uh this whole system did produce right so I just want to start by showing you this is kind of a setup I have for keywords or topics so I have selected a few different subreddits so we are on the singularity open Ai and local llama subreddit uh for now that is what I have been testing on and here are the topics or keywords we are searching for when we are looking at uh looking for post to make a comment on so let's say we have Opus rag in context training hiu Claude Nvidia gp4 yeah we have we have a few keywords here right AI agent Lang chain llama index you can add as much as you want here right so that is kind of a key line so this is something you have to adjust as you go to kind of Select what kind of server edits and post types you want to look for next up is kind of the prompt we use this is of course very important so the way I set this up is I have context here this is going to be what I'm calling the in context training because this prompt is going to be very big so I just want to quickly show you how big this prompt is going to get so you can see here I pasted a full prompt into this token cter and we ended up on 9,000 tokens so every single API request is going to contain 9,000 tokens so yeah you can see this could get expensive if we are using like the big models like Opus and gd4 but if you're using cheaper models this doesn't matter too much and if we answer like 10 comments that's just going to be a few cents right but yeah it's going to be a very big input prompt of course and yeah you kind of get the reason for this because we feed in every single thing we have in the brain so we feed in example comments we fed in the knowledge base the rules the bad examples and here we kind of fed in the the post title from the Reddit post we fetched we feed in either the post com uh content the URL uh scrape content or we feed in the image description and then we follow kind of our prompt so learn from the context above write a comment in lower case uh from the task in the same length style as the example commands uh yeah provide a brief yeah you can kind of read this prompt yourself if you want to but I try to always reference back to these uh uh variables up here that contains some kind of information from our brain right so that is kind of how I built this up and yeah so far it's been working pretty good and yeah quite happy about it the final key lines of the code I wanted to show you is this elapse time I created so this is going to do like a random wait time between 30 and 60 Minutes uh for now I am thinking of increasing this to between 60 and 120 minutes so we're only going to post like a comment like once an hour or like once every 2 hours because there's no point in spamming uh that was not the idea behind this and yeah we have like a countdown that kind of counts down how much remaining time it is until we're going to do the next comment and so on right and and yeah there's one more thing that is quite important let me just quickly show you that and that is kind of the part you see here so we have a load replied post and save replied post because we want to save the IDS of the post we already have uh did did a comment on because we don't want to do comments on every uh multiple comments on one post so every time we make a comment now on a post we save that ID and each time the script starts again we're going to load those posts post and we going avoid them when we search for new posts right and that was quite important because other than that I just kept ended up spamming the same post with comments that was quite a horrible but uh this kind of solved this so I think that's it for the code like always if you are interested in getting access to this code yourself uh just follow the link in the description become a member of the channel I'm going to post this on our community GitHub you will get access to the full code and you can adjust the brain to your needs and you can start us using this uh yeah AI agent for Reddit so let me show you how this works now uh it's pretty easy basically we just have to start a script so yeah and it's going to start searching uh using our keyword so it's searching the serate singularity and it's going to look for those keywords and it's going to find a post with those keywords inside the title and it's going to use our brain to create a comment so you can see here and here we kind of are waiting to do a comment again so here we kind of answer this the post here let me zoom in a bit and here is our answer right so I've been waiting for CLA to get tool use capabilities been able to interact with external apis and data sources is huge and yeah something about this and you can see at the end here I do a lot of AI llm stuff on my YouTube channel all about AI feel free to check it out we're almost at 150k Subs now so that was kind of my sub promotion so let's over to uh ready it and kind of see if we actually did post this comment right and yeah you can see over here on Reddit we commented this 3 minutes ago if we click on the post here you can kind of see this was a URL I don't know if we did scrape this I'm not sure to be honest but it's on X I don't think we did but uh we got a big title here so we kind of could U do an answer just from the title so you can see yeah we got the comment out here and yeah that worked pretty good if you ask me let's check out a few other comments I made using this system so here is kind of a it's someone asking about a 3090 versus a 40 super TGI getting started on my own build for the first time uh and it's asking about this gpus so it says hey there for your local home setup with llama 13B 70b and voice craft I probably go with the RTX 3090 24 GB that extra weam will come in super handy for those massive models especially if you want to run multiple instances plus the the 39 is just a beast in general the 4070 is never uh is newer and more efficient but 16 GB vram might feel a bit tight just my two cents of someone who plays around with llms a lot from my YouTube channel all about a that was a subtle promotion again but I was pretty happy with that this answer so I can if I want to I can take this post and this answer and feed it back into my brain as an example of comments I like right just one more quick example here so you can kind of see uh some of my comments have been really much uploaded so this have 11 uploades so that was pretty interesting I didn't kind of kind of expect that but uh yeah pretty cool yeah that is kind of what I wanted to share with you today had a lot of fun building this AI agent brain and of course if you want access to the full Reddit agent code I'm going to be posting that to the community GitHub so just follow the link in the description and become a member of the channel and you can yeah try this out for yourself uh but yeah I learned a L from this actually and uh just treating data and collecting data and kind of structuring data I felt alert a lot about that and this a good beginners project if you kind of want to get into data collection and trying to Cipher data and see kind of how that works uh while actually building something that is slightly useful I think uh but yeah thank you for tuning in have a great day and hopefully I see you again on Wednesday also so don't forget to leave a like and a comment if you thought it was pretty cool so yeah see you soon
Info
Channel: All About AI
Views: 7,573
Rating: undefined out of 5
Keywords: ai agent, ai agents, llm, ai brain, build ai agent, claude 3, reddit ai agent, ai engineer, ai engineering
Id: sc5sCI4zaic
Channel Id: undefined
Length: 14min 33sec (873 seconds)
Published: Sun Apr 07 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.