LangChain Guide: Building & Chaining Models

Summarize the following. Use a bulleted list for all key point. Do not include introductory material. If code is explained, use speech to text and extract the code into a code block. If you can Identify what models, tokenizers, embeddings or other files mentioned, create a list in the footer.
Title: “LangChain Quickstart Guide | Part 1”
Transcript: “hello guys welcome back let’s start exploring Lang chain as I said in my earlier video I will go through each and every step of line chain documentation and I will cover the python documentation this is the main website of Langston and if we click this python docs it will take us to the python documentation page so for me at least when I start exploring some wave Frameworks I want to go through the getting started or quick start guide as it is mentioned in the website also in the first link here it says quick start guide right first go through all the different aspects so that I get the claims of what a land chain can do this quick start guide is little bit longer so in this video I will go through the building or language model application llms and in the next video I will go and explore the chat models let’s get started now let’s explore the first part B building or language model application allowance right this is the quick starter we get the high level idea of what blank chain is as I said before first we need to install all the packages I have already done this for you you can just run this command and we need the API key right in order to interact with the hogging face or open AIS platform we need to have the API keys of those platforms so you can go to this link here and take the open ai’s API key as well as the hogging face Hub API keys and you can just place in this place folder I have already drawn this command after this let’s go and create the prediction model first that get get prediction from the language model right so for that we can import the open Ai and hogging face Hall after I import that we can just now initialize the wrapper here I have open Ai and I give the temperature 0.9 so temperature is just how we can control the level of Randomness it’s you can go and return more into here and we just provide the text what would be a good company name for a company that makes colorful socks if I provide that text into the large language model then it will provide me some output right so it says rainbow tools okay great so now this is as I said as I said here in the documentation open ai’s API is not free but initially they will give you some credit about hogging face hob API is free so if you prefer going in that way it’s fine I’ll also give you one example here but it doesn’t work with all the different models here I have just Chosen One modal flan T5 XL and for that is the same process you just write the wrapper here is hogging his half and I just passed the repo ID model arguments temperature 0. 9 max length is 64. if I run the same text into this it will provide me the sock monkey what I noticed is always the hogging face hob and this Google this model provides the same result but open AI provides different results each time iron just to show you if I run this again it shows you okay colorful quotes but if I run the hugging phase one it will so again the soft monkey now let’s go and see what is prompt template so this is really the good concept of a lion chain instead of hard coding the text we want to ask we can use from templates to manage the prompts for example it works similar to python Fe strings as you can see it in Python F strings we just provide the name of the variable and then we pass that into the F string and if I run this it will just pass the name of the framework in the string as a variable right similar to that in length chain also we need to import from Land chain prompts import prompt template how we do is we just say prompt equals to prompt template and we pass the input variable so it will be in a list here I said product and the template itself is what is the good name for a company that makes before we said socks right but here we are just passing the products so if I run this it will create the instance for us and now we can just run this with the dot format method so here it says prompt which we just mentioned here and Dot format and we just say the product right so what do we want the output to be I said here colorful socks you can just pass anything you want if I run this command then it says what is a good name for a company that makes colorful socks right if you change these to something else the something else will be output here let’s say if I write sort not see it right sorts and if I run this what is the good name for a company that makes sorts right but now let’s go with the throttle socks if I run this is it will say colorful socks this is how easily because before in the first example we need to go here and write all the sentence right but if you are creating an application there should be something easier and convenient to do so now you can just replace the name here and all the things will be in that format okay in the beginning we interacted with the last language model and then we create a prompt right but they work separately in real applications using the last language model in isolation is okay for some applications but instead in most of the applications you need chaining right hence there is a change in the Lang chain so how it works is it’s the same way that we initialized before here we have large language model we have the prompts same as before so I can just run this again it does nothing but it’s just the same what we did as before now we can import the llm chain from LinkedIn here it says from Land chain.chains We import the llm chain and we said llm10 equals to llm chain prompt equals to prompt and llm equals to llm before we did separately like there is a large language model output and there is the prompt but now we chain that together meaning that we create a simple scene that takes user input format The Prompt with it and send it to the llm so if I run this command now it is being initialized now we can run the chain with llm chain dot run you see here I just passed the name here colorful socks and now it gives me the output that is how easy you can same different things here we are changing the last language models and the prompt together so you get the idea how we are slowly building blocks one after the another and this is really good and so far I am actually enjoying creating this content and also learning myself in the like chain okay now there is another building block called agents I hope if you have watched the auto GPT videos or also something like that there are different agents talking to each other right there are AI agents so dynamically called chains based on user input so far what we did was we run the chains in a predetermined order but agents can use an llm to determine which actions to take in what order and action can either be using a tool and observing its output or returning to the user it actually takes a tool llm and agents there are three different genes like in order to load the agents understanding the following concepts is crucial so the tool is what is tool a function that performs a specific duty is called the tool this can be like Google Source database look or python Ripple or other chains and the llm is of course the large language model powering the agent and there is the agents agents invoke and large language model making decisions about which actions to take we don’t have to determine the predetermined action now so how it works if you want to go you can click the link here but as I said this is just a quick start video I will go through this in depth in my upcoming videos but if you want to know more you can just click this link here but in this example what I am going to do is do a Google search so for that you need to install Google sorts results python package I will run the command but for this we need the sort API API key right for that you need to go to this pi. com you need to create an account to verify yourself and if you just click this link there will be API key I have already passed the API key this is really cool how it works I will show you now what I did here I just imported the necessary modules and first let’s load a language model here I just did what we did before right open Ai and I just keep the temperature zero for now now there is the tools part as I said here we have llm tools and agents right of course there is the llm and then the tools we just load the sword API right and there is the agent now we initialize the agent with tools and the llm and the agent is Agent type.0 sort react description and we want the variables true meaning that we want to see what it will output what I am saying here is what is Lang chain because the model the open AI model don’t know what is length in rice because the open ai’s training data was cut off in September 2021 line chain just appeared we’ll see six months ago it does not know what is line chain right but if I run this what it does let’s see the output also here it says entering the new asset executed chain I so resource this to find out more information there is the Action Now search and then there is the Observer and there is action input which says Lang chain and observation is length chain is a framework for developing applications powered by language models and there is the thought process also with the AI itself this looks like a good source of information and there is again the action okay Source action inputs Lang chain applications observation and it provides something here there is the thought process again going on and there is the final answer and it provides the final answer for us this is how cool we we actually because now there is already the plugins in charge GPT also but that is only for pro version not in the or not in the free version right but here with the help of Agents we can do a Google search and find the latest information this is really cool okay so now comes the memory part we can add state to the chains and the agendas so far for all the chains and agents we have gone through they have status right what of phone you want to have a chain or agent to have some concept of memory right in chatbot case you want the conversation or the chat about to remember the audio conversation so that there is a short term memory and there is the long term memory meaning that it most somehow remember of the key pieces of information over time right you have a chat and let’s say you started a conversation with chatbot and you have 10 different conversation with the chatbot and if you ask what I asked in the beginning meaning the chatbot must remember all the things right that that is where the memory comes into action here they just go with the simple simple example from Land chain import open Ai and conversation chain so first we have the model of course and then there is the conversation we just pass the last language model into that and the output is conversation. predict and here which is high there that is what we provide information to the chatbot right and we print the output let’s run this first now you will see that entering a new conversation chain and prompt after formatting the following is a friendly conversation between human and AI right and human says hi there and there is the part of the AI now right it says finish the chain and hide there and it’s nice to meet you my name is AI what’s your name so it is actually providing the information here right but instead of saying what’s my name I I just want to make the conversation go along and I said conversation.redict input I am doing well right just having a conversation with an AI if I pass this now let’s see what AI does you see the memory part here it goes all the way upright there is the current conversation there is human High there the first one and then there is the AI High there it’s nice to meet you this is what we already did in the previous round right it also takes that into account and I said I’m doing well just having a conversation with an AI and now the AI is part it’s a that’s great it’s always nice to have a conversation with someone new what would you like to talk about so you can continue this this is kind of having a conversation with the AI this is really good and this is all the parts in the quick start in the next video as I said before I will go with the chat morals part it is similar to this if we go to the documentation and the chat models here they say that similar to what we did you can also have a chat models instead of llms and they have also mentioned that chat model apis are fairly new so we are still figuring out the correct abstractions I hope you learned something if yes please give thumbs up and if you haven’t subscribed do so thanks for watching and see you in the next video”

– LangChain is being explored in a series of videos, starting with the quick start guide.
– The quick start guide provides an overview of LangChain and its capabilities.
– Installation of packages and obtaining API keys for OpenAI and Hugging Face is required.
– Building a language model application involves importing OpenAI and Hugging Face, initializing the wrapper, and providing input text to generate output.
– Prompt templates can be used to manage prompts dynamically, similar to Python F-strings.
– Chaining language models and prompts together simplifies the process and allows for easy customization.
– Agents are introduced as dynamic chains that make decisions based on user input and invoke language models.
– A demo is shown using a tool (Google Search) and an agent that interacts with the language model to perform a search.
– Memory can be added to chains and agents to enable short-term and long-term memory capabilities.
– An example of a conversation chain is provided, where the AI remembers previous interactions and continues the conversation.
– The next video will cover chat models, which are similar to language models but with specific APIs.

Models/Tools Mentioned:
– OpenAI
– Hugging Face Hub
– LangChain
– Google Search API