-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchably.py
42 lines (34 loc) · 1.32 KB
/
chably.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
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from chatterbot.response_selection import get_first_response
from chatterbot.comparisons import levenshtein_distance
import logging
logging.basicConfig(level=logging.CRITICAL)
#utilizzo della classe "chatbot" per istanziare il bot
bot = ChatBot(
"Chably", #nome che assegniamo al bot
storage_adapter="chatterbot.storage.SQLStorageAdapter",
database="./db.sqlite3",
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter",
logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function": "chatterbot.comparison.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
}
]
)
with open("C:/Users/Mario/Desktop/chably_bot/conversazione.txt") as f:
conversation = f.readlines()
trainer = ListTrainer(bot)
trainer.train(conversation)
#utilizzo del ciclo while per rendere la chat continua...
while True:
try:
user_input = input("Tu: ")
response =bot.get_response(user_input)
print("Chably:", response)
except(KeyboardInterrupt, SystemExit):
print("ciao ciao!")
break