Python Forum
How to add multiple lines response in chatterbot?
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add multiple lines response in chatterbot?
#6
Sorry for the typo of append, I just edited it.

(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.
Reply


Messages In This Thread
RE: How to add multiple lines response in chatterbot? - by killerrex - May-16-2018, 01:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Amazon AWS - how to install the library chatterbot wpaiva 9 3,930 Feb-01-2020, 08:18 AM
Last Post: brighteningeyes
  Scrape multiple lines with regex greetings 2 3,075 Jul-04-2018, 09:09 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020