Few-Shot Prompting
Few-shot prompting shows the model a handful of input→output examples so it infers the pattern, then gives it a new input. It's one of the most powerful techniques for steering output format.
We want output like:
Input: hello
Output: HELLO
Input: bye
Output: BYE
Input: cat
Output:
Your task
Write fewShot(examples, query) where examples is an array of
{ input, output } objects. Render each example as Input: x\nOutput: y,
join examples with a blank line (\n\n), then append the new query block
\n\nInput: {query}\nOutput: (note: nothing after Output:).
⚡ 35 XP
solution.jsRuns in your browser
Loading editor…
Tests1 to pass
builds a two-shot prompt
Run your code to check these.