Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Watch the Partner Forget Your Name

In this video, you ran Mei’s whole practice session through the partner, one call per message, and watched it forget her name one message after she gave it. Then you sent the earlier turns with each call, and the partner used them.

Key Points

  • A practice session is a conversation. Mei’s session has two messages. First, she introduces herself by name. Then she orders a green tea and asks the partner to write her name on the cup.
  • One call per message is the natural first attempt. It follows how a chat window feels. The script loops over Mei’s messages and prints each one. It calls streamAnswer() with that message as the input, then writes the reply as it arrives and keeps a copy as before. To keep the loop short, it leaves out the try and catch from the last video.
  • The partner forgot Mei’s name. The first reply greeted her by name. The second reply asked what her name was, so it could write it on the cup. Nothing crashed and both calls finished, so a member would only notice that the partner forgot her. Your run’s words will differ.
  • Each request carries everything the model sees. The first request carried the partner’s instructions and Mei’s first message, with her name in it. The second carried the same instructions and her second message, without her name. The model generates each reply only from the text in that one request and has no record of earlier calls.
  • A chat window seems to remember because the app sends the earlier turns again with every message.
  • Send the earlier turns every time. In a first rough form, the turns go into one history string. Before each call, the member’s message is added to it with a Member: label, and the input is the whole history.

The loop already collects the reply as it prints. After the loop, a reply that finished is added with a Partner: label.

The second call’s input held Mei’s first message, the partner’s reply, and her new message, and the second reply wrote Mei on the cup. - Only a finished reply is saved. A reply cut off at the limit stays out of the history, so the next call never builds on half an answer. - This history is rough. It’s one string, and only the labels mark who said what.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Your partner script streams the reply to one message, Amara’s first. But a practice session is a conversation, with several messages in a row. In this video, you’ll run a whole session through the partner and see what it does with the earlier messages.

00:15 Mei’s session in the club’s data has two messages. First, she introduces herself by name. Then she orders a green tea and asks the partner to write her name on the cup.

00:27 The natural way to code this follows how a chat window feels, with one call for each message. The script finds Mei’s session and loops over her messages. For each one, it prints her message, calls streamAnswer() with that message as the input, and writes the reply as it arrives, keeping a copy as before.

00:45 To keep the loop short, it leaves out the try and catch from the last video. The first reply will greet Mei. Will the second reply know her name? Your turn: pause the video and predict.

01:09 It doesn’t. The first reply greets Mei by name. But the second reply asks what her name is, so it can write it on the cup. Your run’s words will differ.

01:21 Nothing crashed, and both calls finished. A member would only notice that the partner forgot her, one message after she said it.

01:31 To see why, look at what each call sent. The first request carried the partner’s instructions and Mei’s first message, with her name in it. The second request carried the same instructions and her second message.

01:44 Her name isn’t in it. The model generates each reply only from the text in that one request. It has no record of earlier calls, so for the second reply, Mei never introduced herself.

01:58 A chat window seems to remember because the app sends the earlier turns again with every message. Each request carries everything the model sees.

02:09 So the script has to send them. In a first rough form, the turns go into one history string. Before each call, Mei’s message is added to it, with a Member label.

02:20 And the input is now the whole history.

02:24 The loop already collects the reply as it prints. After the loop, a reply that finished is added to the history too, with a Partner label. A reply cut off at the limit stays out, so the next call never builds on half an answer.

02:39 Run it. Here’s the history string the second call sent as its input: Mei’s first message, the partner’s reply, and then her new message. Her name is in the request now.

02:53 And the second reply writes Mei on the cup.

02:58 So the model keeps nothing between calls. Each request through streamAnswer() carries everything the model sees, so your code has to send the earlier turns every time.

03:09 This history is rough. It’s one string, and only the labels mark who said what. Next, in the lesson Keep the History and Send It Every Time, streamAnswer() takes the turns as a list of messages, each marked as the member’s or the partner’s.

Become a Member to join the conversation.