This repo demonstrates how we can create a simple chatbot that responds to user inputs using the Elasticsearch engine. We use Elasticsearch as it is fast and efficient and has built-in methods for searching texts.
Before we can run the code, we have to install and run the Elasticsearch server. For simplicity, I recommend using the official docker of Elasticsearch. Execute the following to pull the Elasticseach docker image:
docker pull docker.elastic.co/elasticsearch/elasticsearch:6.5.4
Then run the following to start the server:
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.5.4
Please refer to this reference for more info about the Elasticsearch docker.
Now that we have the Elasticsearch engine running, we can run our python script. But before that, please make sure that you have the required packages installed by running the following command:
pip install -r requirements.txt
Ok, now run the following to start the program:
python main.py
Go to http://127.0.0.1:5000/ and start chatting with the bot :)
You can add a new input-output pair to the knowledge base by sending the /learn
command to the bot and following the on-screen instructions. To stop the learning mode, send /stop
command.
The dataset that I used here is the Chatterbot's English corpus which is translated from English to Persian by: Saeed Torabzadeh, Alireza Davoudi and Ebrahim Soroush