LangChain App in 3 minutes - with LangChain Templates, CLI & LangServe

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi today I want to show you the quickest way to create a Leng chain application with the new Leng chain CLI which uses Leng serve under the hood so let's first create a new virtual environment with python minus MV and then the name of the virtual environment so we have to install pentetic version one so penic V2 does not work yet in combination with the Lang CLI let's Now activate the virtual en so we CD into the app folder then into the script folder and then run the activate script on Windows we CD back and then we install the Leng chain CLI so Leng chain minus CLI and then in Brackets serve because we use Leng serf to create our API after installing the package we can now use the Len chain CLI and we run Leng chain app and we want to create the new app so we also use the new keyword and then we Define the name of the app so let's just call it my app and now we've got a new folder called my app so we have to CD inside that folder so before we continue we we'll have a look at the my app folder and here is a subfolder code app and inside that subfolder is a server.py so this is how the API is created so we use fast API we create an app instance and here we can add routes So currently we don't have any routes because we did not add a package yet so this is the next step we will do and after that we will just run uicorn which runs our API so but first let's add a template so we can again use the Leng chain CLI so we use length chain and then app and then add so add adds a package and we make use of the pirate speak template so this will now download the pirate speak template into our repository you can see this is where it gets downloaded from so we have to install it so run it yes and then after a few seconds we get asked if we want to generate the router code for the package so we also say yes and now we have to copy that router code so we first copy the import statement and copy it here and then we will just add the rout so we delete this and add the other rout so this is a an error here so we have to make it a back slash otherwise it would not work and then maybe also use the correct virtual environment here for vs code so now we have to set the openi API key so on Windows you just run the set set command on Linux or Mac you run export so I API key equals my API key and then we use the Leng chain C and run Leng chain serve so this now starts our application as we can see Lang serve started the server and we can go to slash pirate speak SL playground so I had some issues the first time I tried this and as you can see this is the way it looks like in my browser and in vs code there I can see the error so this is a this is an encoding error and I can show you a quick way to fix it but currently this is deeply implemented in the package so we have to change the source code of the package so to fix it we can import from Lang serve. playground we can import the playground prompt template and actually just overwrite the code here so there's nothing you would do in production but it works with a quick fix here so let's scroll down to with open and here we can set an encoding so here we set the encoding to equals utf8 and now if we save that and just run the code again so let's refresh it and now we we can see our length of playground works so let's test it and just run hello my friend then we click on start and as you can see now we can see what's actually going on here that's quite nice to see the code that is actually executed and now we can see yeah this is the way our pirate speaks a whole my mate so this works but maybe let's have a look at the code that is actually running behind it so to get a better understanding so let's first go back here and close the virtual en and then we have a look at the packages so we can add multiple packages here and inside the private speak package we've got this chain and this is what's responsible for the behavior so we create or import a chat prompt template then we create a prompt and here we can see this is the system message translate user input into pirate speak and that's the human input so very simple prompt and we use chat OPI as model and then we use the Lang chain expression language to create our chain this chain is then imported to the server so we imported from here from pirat speak. chain we import the chain and give it an alas name and then we add the chain to this route function so we first have to pass the app and then runnable so this is the chain and this is the path and then we can access this endpoint in the UI so yeah that's it as you can see this is a very quick way to create a prototype with length chain and length serve so if you like the video feel free to subscribe to my channel and like it of course thank you bye-bye
Info
Channel: Coding Crashcourses
Views: 1,613
Rating: undefined out of 5
Keywords: langchain, langchain cli, langserve
Id: chPYTQyYXF4
Channel Id: undefined
Length: 6min 12sec (372 seconds)
Published: Wed Nov 08 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.