Package: django-simple-chatbot
Django Simple ChatbotIt's a very basic Chatbot for Python Django including NLTK and
Django-REST-framework. This Chatbot is currently working without
Machine learning algorithms. Decisions are made by simple statistic evaluation.The Algorithm is based on labeled data on your Django Database and the tool
is supporting continuous labeling.RequirementsPython (3.7, 3.8, 3.9)Django (2.2, 3.0, 3.1, 3.2)DependenciesDjango REST-Framework - Awesome web-browsable Web APIs.NLTK - the Natural Language ToolkitInstallationInstall usingpip...pip install django-simple-chatbotaddsimple_chatbotto yourINSTALLED_APPSsetting.INSTALLED_APPS = [
    ...,
    'simple_chatbot'
]Note:Make sure to runmanage.py migrateafter changing your settings.
The simple_chatbot app provides Django database migrations.QuickstartCreate aresponse.pyfile inside of an already installed app.from simple_chatbot.responses import GenericRandomResponse


class GreetingResponse(GenericRandomResponse):
    choices = ("Hey, how can I help you?",
               "Hey friend. How are you? How can I help you?")


class GoodbyeResponse(GenericRandomResponse):
    choices = ("See you later.",
               "Thanks for visiting.",
               "See ya! Have a nice day.")Add this Response to yourSIMPLE_CHATBOTsettingSIMPLE_CHATBOT = {
    ...
    'responses': (
        ("YOUR_APP.responses.GreetingResponse", "Greeting"),
        ("YOUR_APP.responses.GoodbyeResponse", "Goodbye"),
    ),
}Go to your Django admin and creategreetingandgoodbyetags.
Your response options will be selectable via choices.Go to your Django admin, write some patterns and label them. You can just use
the following labels:[Greeting]
"Hi, how are you?", "Is anyone there?", "Hello", "What's up?!", "hey there!"

["Goodbye"]
"Bye", "See you later", "Goodbye", "I need to go now."NoteIf you do not want to write that patterns by yourself, use a commandmanage.py simple_chatbot_initial. You need to label them after initializing.The package will automatically tokenize the input and map tokens to labels.Add simple_chatbot url to your routings:from simple_chatbot.views import SimpleChatbot

urlpatterns = [
    ...
    path("simple_chatbot/", SimpleChatbot.as_view())
]Make a Post request to your new endpoint:curl \
    -H "Content-Type: application/json" \
    --data '{"message":"how r u?"}' \
    http://localhost:8000/simple_chatbot/The response should look like{
    "tag": "Greeting",
    "message": "Hey, how can I help you?"
}Raw DocumentationDatabase ModelsPattern- message which might be send by a user. Add a tag to the pattern
for being able to identify and response to that messageTag- includes information about Response class for a specific methodToken- tokenized words which are referencing to different patterns. The
user-input will be identified by different tokens.UserMessageInput- new inputs from production. It contains information
about chosen pattern. You can label that messages later and include them
into the system.settings optionsYou can add following options to yourSIMPLE_CHATBOTsetting:STEMMER_MODULE: nltk package for stumming your strings -
default:nltk.stem.lancaster.LancasterStemmer.responses: choices for your tags. It should reference to a response class.WarningYou won't be able to create tags without response classes.Response ClassesThesimple_chatbot.responsespackage provides currently following response classes:BaseResponseGenericRandomResponseBaseResponseIt's just an abstract class for require a specific shape of your response
classes. If you are creating a new response, you should inheritance from that
class.GenericRandomResponseIt will choose a generic answer from class propertychoices.ViewsThissimple_chatbot.responsesincludes a single viewSimpleChatbot.
This view is reusable. The most important changeble option:save_pattern: if True each message will be saved and you can post label
the incoming messages. defaultTrue.SimpleChatbot API DocumentationRequired Request type:POSTpayload:{message: "YOUR MESSAGE"}response:{tag: 'TAG', message: 'RESPONSE'}AboutIt's a very basic Chatbot decisions are made with tools by NLTK which follows
basic preprocessing for NLP of tokenization and stumming.This package is inspired by the Chatbot Tutorial of Tech witch Tim.
Checkout his blog:https://www.techwithtim.net/tutorials/ai-chatbot/In my opinion the used script is teaching important concepts but it's
overtooled by using Deep-Learning algorithm on that small amount of data.Real NLP's and Deep Learning algorithms needs a large amount of data. One
problem in smaller and beginning projects: You won't have that amount of data
by starting your projects.This package gives you possibilities to work with a small amount of data and
it helps you to collect new data for being able to use deep learning
algorithms one day.ContributingFork the repo and get stuck in!