This notebook will tell you how to use prompt templates that have few-shot examples.
Let’s first look at a very simple example of how a FewShotPromptTemplate can be used to format a prompt:
To get started, we can create a list of few-shot examples. Each example is a tuple that contains the input first and the formatted output next.
Now, we define the input that we will pass along with the few shot examples. We use Python’s f-string as the template format for prompt templates.
This can then be passed into model input.
FewShotPromptTemplate
Finally, create a FewShotPromptTemplate
object. This boject takes in the few-shot examples, as well as the main template.
Note that we also pass in introduction
, an optional parameter simply used to clarify the central theme of the examples if needed.
Now, we use the format
method to create a prompt with new content as shown below.
This will give us the following output:
This notebook will tell you how to use prompt templates that have few-shot examples.
Let’s first look at a very simple example of how a FewShotPromptTemplate can be used to format a prompt:
To get started, we can create a list of few-shot examples. Each example is a tuple that contains the input first and the formatted output next.
Now, we define the input that we will pass along with the few shot examples. We use Python’s f-string as the template format for prompt templates.
This can then be passed into model input.
FewShotPromptTemplate
Finally, create a FewShotPromptTemplate
object. This boject takes in the few-shot examples, as well as the main template.
Note that we also pass in introduction
, an optional parameter simply used to clarify the central theme of the examples if needed.
Now, we use the format
method to create a prompt with new content as shown below.
This will give us the following output: