-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbuddy2.py
More file actions
36 lines (30 loc) · 971 Bytes
/
chatbuddy2.py
File metadata and controls
36 lines (30 loc) · 971 Bytes
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
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
import yaml
import random
# Create chatbot instance
chatbot = ChatBot(
"ChatBuddy",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
database_uri="sqlite:///chatbuddy_database.sqlite3"
)
# Load bot questions from YAML
with open('bot_questions.yml', 'r') as file:
data = yaml.safe_load(file)
bot_questions = data['questions']
# Create trainer
# Create trainer
trainer = ChatterBotCorpusTrainer(chatbot)
# Train chatbot with your custom YAML
trainer.train("./train.yml")
# Pick a random first question
first_question = random.choice(bot_questions)
print(f"ChatBuddy: {first_question}")
# Chat Loop
print("Type 'exit' anytime to quit.\n")
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
break
response = chatbot.get_response(user_input)
print(f"ChatBuddy: {response}")