GrokItBot: A Python, AIML and Bayesian IM bot
Features
The main difference between GrokItBot and other AIML bots is GrokItBots' ability to
learn on the fly.
![GrokItBot can guess at the topic of conversation and respond appropriately. GrokItBot in action](/archives/suttree.com/code/GrokItBot/images/training_goodbye.jpg)
If GrokItBot encounters a topic it has no knowledge of, or if it has no response to an input, it will ask for clarification and enter training mode. In training mode, you can tell it that x means y and GrokItBot will learn and remember that. Due to the nature of AIML, learning doesn't have to take the format of a strict syntax. When GrokItBot asks you what you mean, you can tell it that 'x means y', or that 'it means y' or just 'y'.
There is also a 'learn' command that use can use to feed knowledge to the bot without having to wait until it asks for help. Since humans are not perfect, mistakes may happen. So it is only natural that GrokItBot can forget facts as well.
GrokItBot uses Bayesian guessing to associate words with topics. In the example above, the Bayesian guesser would associate 'lo', 'hi' and 'yo' with 'hello'. This keywords is then set as an AIML topic predicate, meaning that the AIML kernel will search for an appropriate response where the topic is specified as 'hello'. Download GrokItBot and you'll find a hello.aiml file in the data/aiml/ folder. Once the bot has learnt to associate enough words with the topic of hello, it will be able to guess the correct responses to 'hello there' and 'lo again' inputs,
replying with the appropriate response from hello.aiml.
These are callbacks that can be set within the AIML file allowing you to set
conversational triggers that execute your own Python code. A simple example of this is provided in the data/aiml/example.aiml file. To initiate a callback, first you have to teach the bot that 'example' associates to the AIML topic example. Do this by saying 'learn example'. When GrokItBot asks what it means, respond by saying 'example'. Once you get an OK from GrokItBot, try saying example again. This time you shoud see that the on_EXAMPLE callback in GrokItBot.py is called. Setting up callbacks is a three step process. First, create an AIML file using example.aiml as your template. Modify this line:
<think><set name="handler">EXAMPLE</set></think>
Replacing EXAMPLE with the name of your yet-to-be-written calback method.
Next, open up GrokItBot.py and create a callback method using on_EXAMPLE as your template. Your callback could be a wrapper around the Google API. It could supply you with some server stats, or a to-do list, for example.
Finally, run GrokItBoy.py and start talking.
GrokItBot is designed to be highly extensible in a number of ways. Firstly, by being able to train your bot so that it
accurately guesses at the
meaning of your conversations, it is possible to tune each bot you create accordingly to the AIML files you give it. Secondly, by providing callback support from within the AIML files, you can create custom bots without the need to code an IM bot every time. Finally, AIML also supports a degree of extensibility through the use of system tags. The data/aiml/tools.aiml file contains an example of extending GrokItBot in this way, returning the ouput of the
'uptime' command.
Usage
$ ./GrokItBot.py
Installation
You will need to install Py-TOC, PyAIML and Reverend Bayes before trying to run this. Once you have done that, GrokItBot.py can be run from anywhere.
Download
GrokItBot can be downloaded from here:
Download GrokItBot
Or you can try it out a very limited version of GrokitBot here:
AIM GrokItBot
Suttree Beatniks with better clothing, brought to you by Duncan Gough. About Archives Casual Game Dev Code Disclaimer EcoLocal Music Knows PMOG Tumblee