-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
64 lines (54 loc) · 1.92 KB
/
bot.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
from chatterbot import ChatBot,response_selection
from chatterbot.trainers import ListTrainer,ChatterBotCorpusTrainer
from chatterbot.comparisons import levenshtein_distance
from chatterbot.comparisons import JaccardSimilarity
from chatterbot.comparisons import sentiment_comparison
from chatterbot.logic import LogicAdapter
from chatterbot.conversation import Statement
import logging,datetime
import logging
import DepositWithdrawAdapter
import RatcliffObershelp as ratcliffobershelp
logging.basicConfig(filename='chatbot_bot.log',level=logging.INFO)
d_response=["i am in beta version, i don't know a lot.",
"Maybe you can ask something else.",
"i am sorry but i didn't really get your point."]
chat_bot = ChatBot(
'Angelium',
read_only=True,
preprocessors=[
'chatterbot.preprocessors.clean_whitespace',
'chatterbot.preprocessors.convert_to_ascii',
'chatterbot.preprocessors.unescape_html'
],
logic_adapters=[
{
'import_path':'DepositWithdrawAdapter.DepositWithdrawAdapter',},
{
'import_path' : 'chatterbot.logic.BestMatch',
'statement_comparison_function' : ratcliffobershelp.Ratcliff_Obershelp,
"response_selection_method": response_selection.get_random_response,
"default_response":d_response,
"maximum_similarity_threshold":0.80
},
]
)
def is_balance(text):
words = ['my', 'balance']
if all(x in text.split() for x in words):
return True
else:
return False
def final_response(text):
if is_balance(text):
return "Your total balance is $##TOTAL_BALANCE##"
else:
response = chat_bot.get_response(text)
return response
print("\n\n\n\n you can talk to chatbot and type exit to quit.\n\n")
while True:
input_text = input("you : ")
if(input_text == "exit"):
print("chatbot : Nice to meet you")
break
print("chatbot :", final_response(input_text),"\n")