Hugh Murrell / Sep 07 2019
Remix of Python by Nextjournal

Dueling Chatterbots

based on a Gunther Cox's ChatterBot from https://github.com/gunthercox/ChatterBot

Remix this to get started with ChatterBots

pip install chatterbot
pip install chatterbot_corpus
import chatterbot
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot import filters
from chatterbot import comparisons
from chatterbot import response_selection
import time
import nltk
chatbot1 = ChatBot(
    'Slinky',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    database_uri='sqlite:///chatbotinkydb.sqlite3',
    filters=[filters.get_recent_repeated_responses],
    logic_adapters=[
        {
            "import_path": "chatterbot.logic.BestMatch",
            "statement_comparison_function": comparisons.levenshtein_distance,
            "response_selection_method": response_selection.get_random_response
        }
    ],
    tie_breaking_method="random_response"
)
chatbot2 = ChatBot(
    'Blinky',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    database_uri='sqlite:///chatbotblinkydb.sqlite3',
    filters=[filters.get_recent_repeated_responses],
    logic_adapters=[
        {
            "import_path": "chatterbot.logic.BestMatch",
            "statement_comparison_function": comparisons.sentiment_comparison,
            "response_selection_method": response_selection.get_random_response
        }
    ],
    tie_breaking_method="random_response"
)
# create trainers and train the bots (only needs to be done once)
trainer1 = ChatterBotCorpusTrainer(chatbot1)
trainer2 = ChatterBotCorpusTrainer(chatbot2)
trainer1.train("chatterbot.corpus.english")
trainer2.train("chatterbot.corpus.english")
# start the convo
seed="Hi, how is it going?"
print(seed)
response1 = seed
# kick off a chat loop
count = 0
while count<10:
    response2 = chatbot2.get_response(response1)
    print(chatbot2.name," --> ",response2)
    print()
    time.sleep(0.5)
    response1 = chatbot1.get_response(response2)
    print(chatbot1.name," --> ",response1)
    print()
    time.sleep(0.5)
    count = count+1
chatbot1.name
'Slinky'
chatbot2.name
'Blinky'