How do I teach my bot when it gets the wrong answer?

54 views Asked by At

I am working on a game and I am using AIML to make a chatbot that goes with the game.

I want the user to be able to edit the chatbots responses in a simple an effective way to fit their play style.

Here is an example conversation of how the system should work.

USER: Hello my name is Robert. CHATBOT: Hello Robert, nice to meet you. USER: Wrong you should have answered "Hi Robert, how you doing?" CHATBOT: Okay next time you say "Hello my name is Robert." I will answer "Hi Robert, how you doing?" is this correct? USER: Yes that is correct.

(The user should be able to write multiple responses for the chatbot so that when the question/statement is written again the chatbot can have a random answer to pick from)

Then the user can go on talking to the chatbot. I have looked everywhere for a solution and I just can't find one. Can it be done? Any help would be greatly apriciated.

I have tried using the "set" tag, the "get" tag to save and use the users responses but it does not work at all, or at least not the way I would want it to.

1

There are 1 answers

4
Steve Worswick On

You need to user the <learn> tag of AIML to create a new category.

<category>
    <pattern>HI MY NAME IS *</pattern>
    <template>Hello <star/>, nice to meet you.</template>
</category>

<category>
    <pattern>WRONG YOU SHOULD HAVE ANSWERED * OR *</pattern>
    <template>
        <think>
            <set name="userinput"><input index="2"/></set>
            <set name="newresponse1"><star/></set>
            <set name="newresponse2"><star index="2"/></set>
        </think>
        Okay next time you say "<get name="userinput"/>" I will answer "<get name="newresponse1"/>" or "<get name="newresponse2"/>" is this correct?
    </template>
</category>

<category>
    <pattern>YES</pattern>
    <that>_ I WILL ANSWER * IS THIS CORRECT</that>
    <template>
        <learn>
            <category>
                <pattern>
                    <eval><uppercase><normalize><get name="userinput"/></normalize></uppercase></eval>
                </pattern>
                <template>
                    <random>
                        <li><eval><get name="newresponse1"/></eval></li>
                        <li><eval><get name="newresponse2"/></eval></li>
                    </random>
                </template>
            </category>
        </learn>
        New responses now learned.
    </template>
</category>

This will allow the following conversation.

enter image description here

This AIML code allows 2 responses, but you can add more by creating predicates called newresponse3, newresponse4 etc and amending the code.