LangChain Series: Prompt Tools 101 - Simple Prompt Templates

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody and welcome back my name is Chris and this is going to be the first of many videos these videos are going to be shorter than my usual videos as we're just going to talk about one simple concept per video So today we're gonna get started and the best place to get started with Lang chain is to get started with prompting we're going to be leveraging the tools that lanechain gives us to build a prompt template so that we're able to prompt our model however we see fit now we're going to be in the prompt chain for the next few videos so part one is going to be entirely dedicated to prompting so in this video we're going to discuss prompt templates in the next video we're going to expand that out to fuse shot and then we're going to eventually wind up at Chain of Thought or more complex prompt chaining but we'll just get started by scrolling down and getting our dependencies so we are going to be using the Falcon 7B instruct model as our Base llm today so we're not going to be leveraging any resources from openai you will need to run this in collab with a GPU but you can use the free GPU as it's only used 14.3 of the 15 gigabytes of GPU Ram provided to you from the collab T4 you'll want to make sure that you just get some of these dependencies first once we have those we use hugging face to load our open source model again we're going to be using the Falcon 7B instruct model I know a lot of people are excited about that model and they want to get building with it and hopefully this serves two purposes both as a way to Showcase how you can leverage this model and also to Showcase how you can leverage it with simple prompts templates the key things to look out for here is that you have the text generation task we're going to pass our model as this address to hugging faces Falcon 7B instruct model repository the tokenizer is just going to be pulled from pre-trained we do want to use B float 16 this is in order to ensure that we can fit it onto the T4 we have to use trust remote code because there is some remote code since the Falcon 7B model architecture isn't in the Transformers Library yet reuse device map Auto this helps us load it and ensures that we don't exceed capacity on our GPU and then we want to pass some model quarks quarks just means keyword arguments and so we're going to pass in a dictionary temperature and just have that be equal to zero and then max length and have that be equal to 128 new tokens this is going to be depreciated soon and we'll use another way to get extra tokens later but for now we're just going to stick with this method once our model is loaded we're just going to put it into the hugging phase pipeline in order to set it up as our llm so this is a very straightforward process thanks Lang chain and basically what it's going to do is let us slot this in wherever we normally slot in an llm so you might have seen open AI before but today we're going to be using that hugging face Pipeline and now we can get into the meat of it right so what is a prompt template well you can think of it as like a editable prompt so prompt that isn't decided until you actually execute it so this is super useful if you have some boilerplate prop that you want to wrap your users requests in so as you see here we have this you are an expert in Python Programming and then we have this query now this query is dynamic it's going to be set at the time that we call format on our prompt so in order to take advantage of this we just want to set up our prompt template we're going to set it up from template and this is our template here and then this prompt is going to be able to be formatted and we can take a pic and we can take a look at that here so we have prompt.format and then we use the query parameter to insert this text into this query brace and that's really what prompt templates are it's a very simple thing but it's a very powerful thing right so in essence these are just glorified strings right that we're able to add information to so it's not like um you know a crazy technology but it is an incredibly powerful design pattern that we can extend to do some pretty awesome stuff you'll notice that we don't have to specify to write a python function because we have this prompt boilerplate here now we can include more than one input into our template so we have the programming language as well as the query here when we're setting this up we just need to ensure that we have this input variable list of strings you don't technically have to do this you could rely on langchain to automatically decide what input variables it wants or needs but for this purpose we're just going to be explicit about it so you can see what's happening under the hood so we pass in our input variables as well as our multi-input template and then now when we format this we can pass the parameters by their name along with whatever we'd like so we have here our JavaScript so it says you're an expert in JavaScript programming and then our query write a function that determines the nth Fibonacci number which we put into our query here now we have a simple chain we're going to kind of glaze over this chain part for now all you need to know though is that it accepts our prompt template as well as our llm that we set up earlier and then we can just go ahead and run it we do have to make sure that we're passing because there are multiple inputs this dict that has our programming language and query as keys and values when we do that though we see the correct response so this is Falcon 7B instruct which is giving us this function we ask it to write a function that determines the nth Fibonacci number and we know that the boilerplate for this prompt is your expert in programming language programming and we've passed python so it gives us a python compatible answer we can run it just by copying and pasting it to see that it is indeed correct and then we can change it so that it does the same thing but for JavaScript again just to ensure that you're passing the programming language and query as key value pairs into your dot run method it gives us this JavaScript which we just run in our browser and we determine is absolutely correct and that is it for prompt templating again this video is short but they're intended to just go through exactly one concept so if you're if you already knew all this stuff that's fantastic but if you're just getting started you know we want to start from the bottom and build up Lang chain is an impressive tool but it does have some complexity so thanks so much for watching I hope you appreciate the video if you do please click the like And subscribe button and we will see you in the next one where we're going to talk about fuse shot one shot and Selected Few shot examples all right have a great day
Info
Channel: Chris Alexiuk
Views: 8,203
Rating: undefined out of 5
Keywords:
Id: xnZfTuvVVIY
Channel Id: undefined
Length: 7min 46sec (466 seconds)
Published: Thu Jun 29 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.