Command Palette

Search for a command to run...

Hectal
Phase 4: Conversation State
AI Frontend · Exercise 2 of 5 PreviousNext
Beginner

Resend the History

The route /api/chat replies with how many messages it received. Type a question into #prompt and click #send: show the reply in #answer.

The model has no memory, so the request must carry the whole conversation so far: every earlier question and every earlier answer, then the new question. Keep the conversation in the history array.

After the first question the reply says I received 1 message. After the second question it must say I received 3 messages.

What Check tests

  1. The first question gets I received 1 message.
  2. The second question sends three messages: question, answer, question
  3. The third question sends five messages
  4. An empty question sends nothing

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.