Few Shot Prompt Templates
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:
Creating Examples
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.
Defining the Main Template
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.
Feeding the Examples and Main Template to 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.
Formatting the Template
Now, we use the format
method to create a prompt with new content as shown below.
This will give us the following output: