Command Palette

Search for a command to run...

Hectal
Phase 2: Streaming Fundamentals
AI Frontend · Exercise 3 of 4 PreviousNext
Intermediate

Say Why the Answer Ended

readSSE is ready: it yields { type: "text", text } and { type: "finish", reason } parts. Two buttons ask the route a short and a long question.

Show the answer in #answer as it arrives. When the stream finishes with the reason length, show the sentence This answer was cut short. in #note. For a normal finish #note must stay empty. Clear both at the start of each question.

What Check tests

  1. A short question shows its answer and leaves #note empty
  2. A long question shows the cut text and the note This answer was cut short.
  3. Asking a short question again clears the note

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.