May-16-2018, 01:53 PM
Sorry for the typo of append, I just edited it.
For what I saw in the docs (never used chatterbot) ListTrainer just need a list of strings, does not care about how you store them.
Just to build your full code, it shall look something like:
(May-16-2018, 12:11 PM)PrateekG Wrote: I think the ListTrainer of chatterbot will not work for files other than txt.
If anyone can try with my code given above and get succeeded let me know.
For what I saw in the docs (never used chatterbot) ListTrainer just need a list of strings, does not care about how you store them.
Just to build your full code, it shall look something like:
from chatterbot.trainers import ListTrainer from chatterbot import ChatBot bot = ChatBot('MyBot') # Prepare the trining data with open('chats.txt','rt') as fd: conv = [] last = '' for line in fd: # Remove newline and whitespaces only from the end of the line line = line.rstrip() if line.startswith(' '): last += line else: if last: conv.append(last) last = line # Add the final string... last will be '' ony if the file is empty if last: conv.append(last) bot.set_trainer(ListTrainer) bot.train(conv) while True: request = input('You:') if not request: break response = bot.get_response(request) print('Bot:', response) print("That's all Folks!!!")I also corrected the last while loop, that was not reporting the result of each request, just the last one.