Easiest Way to Use GPT In Your Products | LangChain Basics Tutorial 🤖

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] Ty has clearly taken the World by storm but how do you actually think about getting started building GPT or more broadly large language models into your own application that's the question we'll be answering today I have Harrison here and we're going to be covering the basics of Lang chain Harrison is the founder of link chain an open source Library focused on making it really easy to develop applications with large language models like gpt3 I'm Rachel founder of the AI exchange and we're a community of people who are actively applying AI in their work and products and we're super excited to go through this tutorial today Harrison do you want to introduce yourself yeah I'm Harrison I'm super excited to be here I started lingchain a few months ago with the goal of really making it easy to develop applications with large language models and have enjoyed it chatting with Rachel a bunch over the past few weeks and months because we clearly have a lot of shared goals and so I'm very excited to do this video awesome so how we're going to do this is we're going to walk through some of the basics Harrison has a collab notebook already prepared um and we're going to go through and do a little bit of a popcorn q a on some of the concepts that are most important to go ahead and get started Harrison do you want to kick us off and start walking us through the beginning of this notebook absolutely so we're gonna get started by just installing what we need um and so both the open AI SDK for interacting with GPT and other models like that we're going to use that and then we're also going to use the link chain python package both of these are available on Pi Pi for easy installation and download I've already done that and so that's step one in terms of getting started it is install these packages for step two we're going to set some environment variables um this is hidden enough because it has my API key but you can see that after that we're going to set the openai API key in the environment openai requires an API key to interact with their models like this gets piped through link chain to them and with them there the first thing that we should probably understand how to work with is with large language models lom's this is what we're importing right here from lanechain.lm's import openai and so this open AI class is a wrapper around the openai API for interacting with large language models and specifically the probably the most important interface to understand the language models interface of text in and text out and there's there's a bit more complications and you can access more kind of like ingredients but at the core level that's the most important thing to understand you can pass in a string and you can get back a string here we're just calling it very simply we initialize the wrapper and then we're telling it uh tell me a joke and so let's run it and let's see what it comes up with uh what the fish say when it hit the wall damn okay a very very funny joke so this is step one of basically building applications with large language models being able to interact with the large language models and at the at the core kind of like principles large language models are text in text out style things um and that's that's how we're going to interact with them one question if you haven't used a large language model before how do you go ahead and get this API key can you describe that process at a high level yeah there's a website on open AI where you can go and sign up you can just log in through Google once you're in there you can play around they have a nice little interface for interacting with this directly on their website they also have a place where you can generate and use an API key to give you 18 free dollars I believe each call to the API uh costs uh a cent a few cents a fraction of a cent something like that so they give you enough to kind of get started and playing around with it um and it should be pretty easy to find on the open AI website and I'm sure we can link to that in the description awesome sounds great the other thing that I'll add while we're talking about language models is that open Ai and GPT are not the only large language model out there there are lots of other language model providers some behind apis like cohere and others that are open source models on hugging face and so one of the benefits that lane chain does provide is a standardized interface for interacting with all these language models and that makes it really nice and convenient because some of these language models are better than others at certain things and you might want to switch between them really easily and so having this standard interface makes it very easy to do that and so you can swap them out pretty easily one one for another we'll probably use openai and GPT for most of the examples here but I just want to make a note that it's not the only one that you can use awesome what are the other most popular large language models that you've been seeing people use with link chain I think uh cohere and hugging face are probably the next two most popular ones um I think hugging face in particular they since it's open source you can download the models and run them locally and that's really popular when you don't want to send your data over an API call Fantastic all right so we've got these large language models they take in string and they output string um pretty simple to work with right and they are pretty simple to work with but when you start to develop applications you're probably doing more than just taking in a string and outputting a string I think one way to think about that is um let's imagine you're developing an application for coming up with a name for companies where people can type in kind of what their company builds what their company product is and you come up with a name for it as a simple application but let's use this as an example when you interact with the language model you're going to want to tell it some instructions for what it should do but then you're also going to want to combine it with user input and so it's a combination of these two things that's eventually getting fed into the language model and again this is a pretty simple example so there's only one piece of user input but you can imagine that there might eventually be many pieces of user input and so you've got to basically take these pieces of user input and format them in in a template to produce that final string that you pass into the language model and and so the concept to help with this that we have in link chain is a prompt template so prompt comes from basically the prompt is the final string that you pass into the language model and a prompt template is basically a template for constructing that um and so that's the next concept that we're going to cover and uh that's this uh cell right here so we're going to import The Prompt template from link chain and we're going to have this template string and so you can see here there's a bunch of instructions telling the language model that we want it to act as a naming consultant for new companies and then there's also this these curly brackets around product and this denotes kind of like a user input variable that we're going to take and we're going to format it into this template and you can see down here we now construct we now initialize this prompt template with input variables equal to product because we're only taking in one input variable and then this template here so let's run this cell and then if we've tried to use this we can do prompt dot format we can pass in product equals colorful socks and now we can see that this the string it spits out is exactly this with colorful stocks substituted in for product and so the prop templates are basically useful ways for taking user input or other arbitrary uh input that's kind of like defined at runtime combining it with an existing template that contains instructions on what to do how to do it Etc and constructing a final string a final prompt that we can set into the language model awesome um you mentioned an example use case here being if you wanted to take in variables of input from an end user is that the most common use case or are there other common use cases that you've seen for prompt templates prompt templates can get pretty complex pretty fast so I think the most common is taking in user input I would say another very common thing to take in is basically context that you pull in based on the user input I think we'll probably cover this in in a future video but basically you can imagine doing question answering over some documents and you can't pass the whole document or the whole set of documents into the language model so you want to pick the sections that are most relevant so in that case you're taking the user input you're taking the most relevant paragraphs you're putting them into this prompt template and you're passing it on a third like really interesting way to put things into this prompt template is the concept of examples where you're showing the model what to do this is the thing that can get complicated pretty fast because you can imagine first you just have like one or two examples and so you hard code those but you can imagine if you grow those set of examples you may want to dynamically select those examples based on the user input this is a bit more of an advanced concept and so maybe we can cover this in a future video but I think that the selection of examples is another pretty common and pretty important thing that you can format into these prompts dynamically at runtime awesome so it sounds like prompt templates are a good thing to learn no matter what your use case is because they're a really great and flexible building block for a multitude of applications that's exactly right cool all right what's next awesome so the prompt templates and the language models are the two most important things to know when building language model applications I would say I think the next most important thing and the final thing we'll cover here is basically the combination of them it's pretty simple but you basically just take a prompt you take a language model and you combine them in the way that you now have this interface which takes in user input or takes in other things formats it into a final string and then passes that string to the language model and so we call that an llm chain here if we run this cell we can see that we initialize it with the above language model and the above prompt and now we have a chain and this chain exposes an interface where we can pass in a variable and because there's only one variable as input we know that it's the product variable and so we can pass in this variable it's going to format it into the prompt and then it's going to pass it to the language model so when we run this we're not going to get the formatted prompt but we're going to get the language models response to this formatted prompt so it should hopefully be a good name for a company that makes colorful socks let's see what actually happens bright socks that sounds colorful and related pretty good name so yeah so yeah I think this isn't a super complex idea but I think this is just putting together two of the most fundamental and important building blocks um and just wrapping them up in a nice interface and this will be the primary way that other more complex chains and other more complex applications interact with with language models awesome now um I think this is a great overview of the basics which is the goal of this video but could you tell us and just give a little bit of a preview of why people should maybe watch other videos that we do of deeper tutorials or experiment with Lane chain like what does this unlock what are the possibilities yeah so speaking of things that we briefly touched on I think the prompt templates are one of the more basic yet complex things that you can have and so there are really complicated and interesting ways to construct these prompts I think that unlocks a lot of personalization and improved performance and so I think we should absolutely do a video on prompt templates alone this is a really simple chain that just kind of combines these two components you can imagine hooking them up to each other and having one chain that generates a title of a company or five potential titles and then another chain that for each one kind of like writes a blurb about it or writes a marketing copy for it and so you can connect these chains in really interesting ways this chain is stateless right now if I run this again it won't remember anything about the previous run and that's good for some applications but for other applications like chat Bots you want to remember what was mentioned previously and so there's a concept of memory which can be very simple where you just remember the previous line of conversation but it can also get really complex where you're picking out specific things about uh different entities and where they belong and the last thing that I'll mention and this might be the video that we do right after this so it's a very good segue into that is this language model right now is operating entirely on kind of like language or on information that it knows about so everything that it knows about and everything that's talking about is stuff that's when the model Waits and so you can imagine that through different input variables and I think I mentioned this a bit before but through different input variables you can start injecting more context into the language model and so you can start getting language model applications chat like applications that can talk about specific documents that the language model wasn't originally trained on I think these core components of prompt templating and then passing it to the language model allow you to develop personalized language model applications that can be really powerful awesome can't wait for future videos because I think that's the number one topic on most people's minds is how do you go from having Chachi BT which is this really powerful technology something that's more custom and usable and applicable into your business or your product so really excited for the next videos that we're going to be filming anything else you want to add to close this out Harrison I'm excited as well it's a fun time cool all right thanks we hope this was helpful and definitely check out our future videos foreign [Music]
Info
Channel: Rachel Woods
Views: 9,193
Rating: undefined out of 5
Keywords:
Id: fLy0VenZyGc
Channel Id: undefined
Length: 13min 21sec (801 seconds)
Published: Tue Feb 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.