#import chatterbot and chatterbot trainer from chatterbot import ChatBot from…
- User
#import chatterbot and chatterbot trainer from chatterbot import ChatBot from chatterbot.trainers import ListTrainer
#create chatbot
#create trainer
#create greetings list
#create jokes list
#train your chatbot
#use a while loop to generate conversation until the user chooses to exit #reminder: use bot.get_response(user_input) to get the chatbot's response
import chatterbot train it 3 greetings- 3 jokes 3 story-
- Assistant
import necessary modules
from chatterbot import ChatBot from chatterbot.trainers import ListTrainer
create chatbot
bot = ChatBot('MyChatBot')
create trainer
trainer = ListTrainer(bot)
create lists for greetings, jokes, and stories
greetings = ['Hello!', 'Hi there!', 'Hey, how can I help?'] jokes = ['Why did the math book look sad? Because it had too many problems.', 'What do you call an alligator in a vest? An investigator.', 'Why did the bicycle fall over? Because it was two-tired.'] stories = ['Once upon a time, in a faraway land, there was a magical unicorn...', 'In a small village, there lived a wise old owl who was known for giving great advice...', 'On a dark and stormy night, a group of friends gathered around a campfire to tell spooky stories...']
train the chatbot with the lists
trainer.train(greetings) trainer.train(jokes) trainer.train(stories)
start conversation with the user
print("Welcome to MyChatBot. How can I assist you today?") while True: user_input = input("You: ") if user_input.lower() == 'exit': print("Goodbye!") break response = bot.get_response(user_input) print("ChatBot:", response)
- User
MAKE THE JOKE ABOUT HOW SONIC VOICE GUY VOICED TWO PARTS OF HIM
- Assistant
add the joke about Sonic voice actor
jokes.append('Did you hear about the Sonic the Hedgehog voice actor who also played two other characters in the movie? He really knows how to hedge his bets.')
retrain the chatbot with the updated jokes list
trainer.train(jokes)
start conversation with the user
print("Welcome to MyChatBot. How can I assist you today?") while True: user_input = input("You: ") if user_input.lower() == 'exit': print("Goodbye!") break response = bot.get_response(user_input) print("ChatBot:", response)
- User
import chatterbot train it 3 greetings- 3 jokes 3 story- with the whole code
- Assistant
Sure! Here is the complete code with training for 3 greetings, 3 jokes, and 3 stories:
# import necessary modules from chatterbot import ChatBot from chatterbot.trainers import ListTrainer # create chatbot bot = ChatBot('MyChatBot') # create trainer trainer = ListTrainer(bot) # create lists for greetings, jokes, and stories greetings = ['Hello!', 'Hi there!', 'Hey, how can I help?'] jokes = ['Why did the math book look sad? Because it had too many problems.', 'What do you call an alligator in a vest? An investigator.', 'Why did the bicycle fall over? Because it was two-tired.'] stories = ['Once upon a time, in a faraway land, there was a magical unicorn...', 'In a small village, there lived a wise old owl who was known for giving great advice...', 'On a dark and stormy night, a group of friends gathered around a campfire to tell spooky stories...'] # train the chatbot with the lists trainer.train(greetings) trainer.train(jokes) trainer.train(stories) # add the joke about Sonic voice actor jokes.append('Did you hear about the Sonic the Hedgehog voice actor who also played two other characters in the movie? He really knows how to hedge his bets.') # retrain the chatbot with the updated jokes list trainer.train(jokes) # start conversation with the user print("Welcome to MyChatBot. How can I assist you today?") while True: user_input = input("You: ") if user_input.lower() == 'exit': print("Goodbye!") break response = bot.get_response(user_input) print("ChatBot:", response)