-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
74 lines (50 loc) · 1.76 KB
/
demo.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
67
68
69
70
71
72
73
74
#test-chatbot.py
import baker.trainer
import baker.bparser
import baker.chatbot
trainer = baker.trainer.Trainer('data.json')
parser = baker.bparser.Parser('data.json')
my_chatbot = baker.chatbot.Chatbot("MyChatbot")
my_chatbot.session(trainer, parser)
#test-functions.py
import baker.bparser
response_file_name = "data.json"
parser_instance = baker.bparser.Parser(response_file_name)
parser_instance.export_responses(export_file_name="data2.json")
baker.bparser.Parser.reset_responses("A_User_Question")
parser_instance2 = baker.bparser.Parser("data.json")
user_input = "Hello"
response_to_remove = "Heyy"
parser_instance2.remove_response(user_input, response_to_remove)
parser_instance3 = baker.bparser.Parser("data.json")
user_input = "Hello"
count = parser_instance3.count_responses(user_input)
print(f"Number of Responses for '{user_input}': {count}")
#test-loop-trainer.py
import baker.trainer
trainer = baker.trainer.Trainer('data.json')
trainer.loop_training()
#test-parser.py
import baker.bparser
def test_chatbot(bot):
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
print("Testing session ended.")
break
response = bot.get_response(user_input)
print("Bot:", response)
bot = baker.bparser.Parser('data.json')
test_chatbot(bot)
#test-trainer.py
import baker.trainer
import baker.bparser
import baker.chatbot
bot = baker.trainer.Trainer('data.json')
user_input = input("You: ")
response = bot.get_response(user_input)
print("Bot:", response)
# Train the bot with a new response
new_response = input("New response: ")
bot.train_response(user_input, new_response)
print("Bot has been trained with the new response!")