How do we create prompts with long chain?
If you remember, prompts are simply what we tell a language model, and we know that this input will
guide how this language model responds.
We know as well that there are many types of prompts, and in fact, long chain has a repository of
useful recipes for prompts.
Here you have a link, uh, to see that it's interesting.
It's not super fantastic, but well, it's a good reference to use when you have to create a complex
problem.
So you have a lot of examples there.
It's interesting to pay a visit at least.
What are prompt templates.
So prompt templates are very frequently used when we create applications with long chain.
And the goal of the prompt templates is to, uh, let's say to complete 90% of the final problem.
So we as a LM application developers are going to build most of the prompt like you have here.
Tell me a joke about.
Something, right?
So we are not a completing the prompt.
We are just, uh, entering some information and we are going to ask the user to fill the gaps.
Right.
So these are prompt template.
Uh, in this exercise we are going to create a prompt, uh, for an LM model and also a prompt for a
chat model.
You will see the process is very similar.
The case of the chat model has a couple of different things.
A little bit more sophisticated than than the regular LM model.
So a in the first case we of course, you know, we we connect with the dot m file, uh, in order to
get the credentials for the OpenAI API.
And then what we do is we load the OpenAI module, we create a new instance of the LM a and then we
import the prompt template module.
And there you see, how do we create the final product.
So our final product is going to be the result of combining the initial template with the user input.
In this case, the user is interested in having a joke about French people and he wants to it to be
funny.
Just funny.
Right?
So we are going to combine these user input with the template we have.
So the final problem is going to be tell me a funny joke about a topic.
So as you can see in this template we are including a couple of variables.
We can name our variables whatever we want.
In this case we have called adjective and topic.
Right.
So once we have this template, we need to build a prompt template according to long chain standards.
And in order to do that we have to tell okay we are going to use the prompt module, the prompt template
module.
And here we are going to say okay you need to use this template.
And this template has these two variables.
So we have to be explicit about that.
And then we need to combine this prompt template with this user input.
And we do that in order to create the final prompt.
So the final prompt is going to be a combination of the prompt template with the user input.
Okay.
So uh this is the final prompt.
We get to the language model.
And if we print the response we are going to see here it is the joke about French.
So we can do the same for a chat model.
In this case it's going to be a little bit different because as you remember we are going to need chat
OpenAI instead of OpenAI a module.
And then we have a couple of modules.
Modules that are specific for chats.
But the process is very similar.
We have the user input and we have the chat prompt template, and we combine both of them with the,
in this case the format messages function.
If you remember, in the LM we were using format.
And in the chat model we are using format messages.
Okay.
That that's that's the main difference.
So we will see that uh most LM applications build with lang chain.
Make some use of prompt templates or chat prompt templates.