1. Messages array
A few-shot prompt is just a messages array that includes example turns before the real question.
const messages = [Typorithm · medium
Step 1 of 8 · intro card
Prompt Engineering
Few-shot prompting puts example user/assistant turns in the messages list to steer format and behavior, while chain-of-thought asks the model to reason step by step to improve accuracy on hard problems.
Few-shot prompting means including a few example turns — a sample question and its ideal answer — before the real request. The model imitates the demonstrated format and style.
Chain-of-thought (CoT) asks the model to reason step by step before answering. Surfacing the intermediate steps reliably improves accuracy on math, logic, and multi-step problems.
You can also prefill the start of the assistant turn to constrain the output — beginning the reply for the model so it continues in exactly the shape you need.
Few-shot: example turns steer format and behavior.
Chain-of-thought: 'think step by step' improves reasoning.
Prefilling the assistant turn constrains the output.
const messages = [
{ role: "user", content: "2+2?" },
{ role: "assistant", content: "4" },
{ role: "user", content: "Think step by step: 17*23?" },
];
// few-shot examples steer format; CoT improves reasoningConnect each part of the code to the concept before you type.
A few-shot prompt is just a messages array that includes example turns before the real question.
const messages = [An example user turn shows the model the kind of input it will be asked about.
{ role: "user", content: "2+2?" },The paired assistant turn demonstrates the exact answer format you want back.
{ role: "assistant", content: "4" },Asking the model to think step by step elicits intermediate reasoning, improving accuracy on hard problems.
{ role: "user", content: "Think step by step: 17*23?" },Few-shot examples shape the output format while chain-of-thought improves the reasoning behind it.
// few-shot examples steer format; CoT improves reasoningRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.