Beginner
Buffer the Events
The route /api/chat streams the answer Chai is tea. in the chat format, cut into small packets so lines arrive in pieces.
When #ask is clicked, read the stream and put the answer text into #answer. Each event ends at a blank line, and its JSON holds the next piece at choices[0].delta.content. The last event is [DONE], which is not JSON.
What Check tests
#answeris empty before the click- After the click,
#answershowsChai is tea. - A second click clears the old answer and shows it once, not twice
- The code keeps a buffer between packets
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.