-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
66 lines (56 loc) · 2.26 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from microsoftbotframework import ReplyToActivity
import celery
from chatterbot import ChatBot
#from chatterbot.comparisons import jaccard_similarity, synset_distance, sentiment_comparison
import os
import subprocess
import logging
logger = logging.getLogger(__name__)
@celery.task()
def chat_bot_respond(message):
if message["type"] == "message":
chatbot = get_chatbot()
if message['text'] == '!train_smart_harry':
ReplyToActivity(fill=message,
text='I am learning!').send()
train_smart_harry(chatbot)
ReplyToActivity(fill=message,
text='I think I got smarter.').send()
else:
message_response = chatbot.get_response(message["text"]).text
ReplyToActivity(fill=message,
text=message_response).send()
def train_smart_harry(chatbot):
# Chatterbot Corpus
process = subprocess.Popen("git clone https://github.com/gunthercox/chatterbot-corpus.git", shell=True)
process.wait()
chatbot.train('chatterbot-corpus.chatterbot_corpus.data.english')
subprocess.Popen("rm -R chatterbot-corpus", shell=True)
# Ubuntu Corpus
#chatbot.train()
def get_chatbot():
return ChatBot(
'Smart Harry',
trainer='chatterbot.trainers.ChatterBotCorpusTrainer',
storage_adapter="chatterbot.storage.MongoDatabaseAdapter",
database=os.environ['MONGO_DATABASE_NAME'],
database_uri=os.environ['MONGO_DATABASE_URI']
)
# def get_chatbot():
# return ChatBot(
# 'Smart Harry',
# storage_adapter="chatterbot.storage.MongoDatabaseAdapter",
# #database=os.environ['MONGO_DATABASE_NAME'],
# database='test_twitter',
# database_uri=os.environ['MONGO_DATABASE_URI'],
# logic_adapters=[
# 'chatterbot.logic.BestMatch',
# ],
# filters=["chatterbot.filters.RepetitiveResponseFilter"],
# twitter_consumer_key=os.getenv("CONSUMER_KEY"),
# twitter_consumer_secret=os.getenv("CONSUMER_SECRET"),
# twitter_access_token_key=os.getenv("ACCESS_TOKEN"),
# twitter_access_token_secret=os.getenv("ACCESS_TOKEN_SECRET"),
# trainer="chatterbot.trainers.TwitterTrainer",
# logger=logger,
# )