16. Making Dialog Dynamic

Repeating is boring. In this session we will learn how to make dialogs dynamic with random.

The Problem

Let's have a look at cells we created in the previous sessions.

Example 1. Static response

    • <nerve>itemInClassroom</nerve>
    • <strong/>what s in the classroom
    • Good! Next?
              <think><set-context>what s in the classroom</set-context></think>
           

The cell will produce chats as below.

  • Log 1
    • What's in the classroom?
    • A picture.
    • Good. Next?
    • Two blackboards.
    • Good. Next?
    • Many desks.
    • Good. Next?
    • ...

The conversation is not natural at all because the Tutor always say "Good/Next." If she were a human, she would give some dynamic expressions from "Good", "Very good" to "Good job." Can our Tutor simulate human behavior to make students feel better?

The Solution

Use rand element, which each time returns a random item from the given list.

Example 2. Dynamic response

    • <nerve>itemInClassroom</nerve>
    • <strong/>what s in the classroom

    •         <rand>
                <i>Good job! </i>
                <i>You're right! </i>
                <i>Well done! </i>
              </rand>
              <think><set-context>what s in the classroom</set-context></think>
           

      Next?

The Tutor will give changing replies as the students answer her questions.

  • Log 2
    • What's in the classroom?
    • A picture.
    • You're right. Next?
    • Two blackboards.
    • Good job! Next?
    • Many desks.
    • Well done! Next?
    • ...

To make it even more dynamic, we may use multiple rand elements.

Example 3. Output with two rands

    • <nerve>itemInClassroom</nerve>
    • <strong/>what s in the classroom

    •         <rand>
                <i>Good job! </i>
                <i>You're right! </i>
                <i>Well done! </i>
              </rand>
              <rand>
                <i>Next? </i>
                <i>And? </i>
                <i>More? </i>
              </rand>
              <think><set-context>what s in the classroom</set-context></think>
           
  • Log 3
    • What's in the classroom?
    • A picture.
    • You're right. Next?
    • Two blackboards.
    • Good job! More?
    • Many desks.
    • Well done! And?
    • ...

Tips: For contextual conversation, use <set-context/> element to provide consistent context while using rand.

Things to Keep in Mind

  • Use rand where you want to make responses dynamic.