2 Basic prompting and DSPy
This chapter covers
- Common prompt components
- Our first DSPy application
- Overview of DSPy main concepts
In this chapter, we’ll look closer at the prompts sent to LMs when working with an LM-based application. When interacting with an LM through voice or a GUI hosted by the LM provider, we usually use a short, simple prompt and, if necessary, can rephrase this a few times until we get a suitable response. But when software makes the LM calls, we can’t repeatedly reword the prompt until we get a good response; the calls have to be reliable. As indicated in chapter 1, this tends to result in longer, more carefully created prompts. These are the situations where either prompt engineering (manually tweaking the prompt through trial and error) or automating this through prompt programming are often necessary.
In these situations, the prompts tend to have a number of standard sections (and often some less-common sections) added to help ensure the LM responses are reliable. Examples include indicating high stakes for the task, asking the LM to adopt a persona, providing examples (aka demonstrations), and so on. The ideal sections to include vary from one task to another and from one LM to another, but they are somewhat standard. New sections are also added to our repertoires occasionally as new prompting techniques are discovered. Soon, we’ll look at sections that are, at least currently, reasonably standard.