-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
learning_new_response.py
55 lines (41 loc) · 1.48 KB
/
learning_new_response.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
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
# Uncomment the following line to enable verbose logging
# import logging
# logging.basicConfig(level=logging.INFO)
# Create a new instance of a ChatBot
bot = ChatBot(
"Terminal",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
input_adapter="chatterbot.input.TerminalAdapter",
output_adapter="chatterbot.output.TerminalAdapter"
)
trainer = ChatterBotCorpusTrainer(bot)
trainer.train("chatterbot.corpus.english")
def get_feedback():
text = input()
if 'yes' in text.lower():
return False
elif 'no' in text.lower():
return True
else:
print('Please type either "Yes" or "No"')
return get_feedback()
print("Type something to begin...")
# The following loop will execute each time the user enters input
while True:
try:
input_statement = bot.input.process_input()
response = bot.generate_response(
input_statement
)
bot.output.process_response(response)
print('\n Is "{}" a coherent response to "{}"? \n'.format(response, input_statement))
if get_feedback():
print("please input the correct one")
response1 = bot.input.process_input()
bot.learn_response(response1, input_statement)
print("Responses added to bot!")
# Press ctrl-c or ctrl-d on the keyboard to exit
except (KeyboardInterrupt, EOFError, SystemExit):
break