📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

Getting Started with LangSmith (3/7): Prompts

LangChain3:37

Transcription

In this video, we're going to be talking about the Prompt Tub. The Prompt Tub is a feature in LangSmith that allows us to save inversion prompts that we've been iterating on and refining. Once we've saved a prompt, we can then also pull it locally into our application and reuse it in our code.

To show you how to do this, we're going to continue with our example with our parrot named Polly. As a reminder, Polly is a parrot, and Polly has some facts that she can use to answer users' questions about herself. Let's pretend that we've iterated on this prompt for some time now, and we're pretty happy with it and ready to save it for reuse.

It's probably not a good idea to save this prompt with these inputs hardcoded in and also with this question from the user hardcoded. What we can do is we can replace these facts with an input variable. This essentially allows the user to, at runtime, pass in the values that they want to use for both the facts that Polly has access to and the question that the human asks. Cool.

Now, let's go ahead and save this prompt. We can click on this save icon here, and this will allow us to save a prompt either privately or for public consumption. Let's go ahead and name this PollyPromptOne. Cool. This takes us directly to the Prompt Tub. We can see for PollyPromptOne that we have a defined chat template, and this includes those variables that will be passed in by the user. We also see that we've saved the model configuration here, and this includes both the model as well as the temperature and a series of other fields. Finally, we have this code snippet that we can use to pull this prompt directly into our LangChain code and use it in our application.

Let's go ahead and try this out. I'm going to copy this snippet, and I'm going to pivot over to a notebook. This notebook should be very similar to what we've looked at previously, and essentially the main difference is that the prompt here is going to be pulled directly from the Hub. Let's go ahead and run this step. Cool. We can see that the AI message successfully prints out that Polly likes animal crackers.

Now let's say we want to go and iterate our prompt a little bit. If we go back to the Prompt Tub and we click "Edit in Playground," we can now edit this prompt. Let's continue on with this toy example where we say, "You are a French parrot and can only speak French." When we commit this new change, we can commit to our same prompt, and if we go look at our prompt and we look at our commit history, we can see we've just added a revision.

In order to use this revision in our code, we can copy this line. This looks the exact same as the line before, except we have this commit hash appended to the name of our prompt. Now, if we run this cell, we'll respond in French according to the instructions, or rather, it's commit one. Thing to note is that, uh, if we don't provide a commit hash, we will pull the latest version of the prompt every time, and to that end, we will still respond in French.