2

I want to make a chatbot,so my doubt is how can i respond in multiple ways for a single pattern in aiml ? for example if the user asks whats next the chat bot should respond step1 if again he asks whats next it should respond step2.

4 Answers4

2

You can use "that" tags in the template, which remember the last bot statement and answer accordingly, although this gives you just one level of control. If you want more levels, a better way is to set topics using the "think" tags, and then defining topic specific templates which will be used first.

riddle
  • 153
  • 7
0

To have multiple responses for a single <pattern>, you can use the <random> and <li> tags:

<category>
         <pattern>WHATS NEXT</pattern>
         <template><random>
             <li>Step 1</li>
             <li>Step 2</li>
         </random></template>
</category>

However, the responses will be generated randomly and not in a certain order.

For instance, if the user inputs "What's next?" for the first time, the response might be "Step 1" and the next time the user inputs the same keyword, the response might still be "Step 1".

tyn
  • 21
  • 2
0

First you need a category that knows the steps, and returns the answer in a defined format. In my example the format is

MAKE TOAST STEP * *

where the first star is the step number and the second star represents the remainder of the returned text. Here is the category:

<category>
         <pattern>MAKING TOAST STEP *</pattern>
         <template>
             <set var="step"><star/></set>
             <condition var="step">
                 <li value="1">Make toast step 1, get some bread</li>
                 <li value="2">Make toast step 2, put the bread in the toaster</li>
                 <li value="3">Make toast step 3, wait until it pops up</li>
                 <li>Make toast step 4, eat the toast</li>
             </condition>
         </template>
</category>

Then you need a category that calls the next step but only if the previous answer was a toast-making question. This category uses the that tag to ensure it is activated only during the toast making conversation. It uses thatstar to get the previous step number, then adds one to the step number:

<category>
         <pattern>WHAT IS NEXT</pattern>
         <that>MAKE TOAST STEP * *</that>
         <template>
             <set var="step"><calculate><thatstar/>+1</calculate></set>
             <srai>MAKING TOAST STEP <get var="step"/></srai>
         </template>
</category>

Then you need a category to kick off the whole sequence:

<category>
         <pattern>HOW DO I MAKE TOAST</pattern>
         <template>
             <srai>MAKING TOAST STEP 1</srai>
         </template>
</category>

The caveats with this approach are (1) it uses the calculate tag which is not standard AIML but should be coded quite easily. (2) It uses AIML v2 elements such as variables used with get and set. (3) I have not tested it, but I am confident the process should work.

Ubercoder
  • 711
  • 8
  • 24
0
  <category> 
      <pattern>TEST SPLIT</pattern> 
      <template> 
        I don't want to talk about that now. 
        <split/> 
        I would rather talk about you. 
      </template> 
    </category>

Do <split/> Output Reference

So Kratos
  • 1
  • 1