Search code examples
pythonchatbotchatterbot

Overriding pre-defined answer in ChatterBot


I want to specify my own answer to a particular question for a chat bot written using ChatterBot library. Here is my code

from chatterbot import ChatBot

# Create a new chat bot named Charlie
chatbot = ChatBot(
    'Charlie',
    trainer='chatterbot.trainers.ListTrainer'
)

chatbot.train([
    "who are you?",
    "I'm a friendly chat bot"
])

# Get a response to the input text 'who are you?'
response = chatbot.get_response('who are you?')

print(response)

The output after running this piece of code is

Who? Who is but a form following the function of what

instead of

I'm a friendly chat bot

So it looks like there is a pre-specified answer to this question embedded in the library. How can I configure a bot that will use only my answers?


Solution

  • @DavidBankom The bot will train only with your data. The code snippet also tells same thing from source code.

    # Use specified trainer or fall back to the default
    trainer = kwargs.get('trainer', 'chatterbot.trainers.Trainer')
    TrainerClass = utils.import_module(trainer)
    self.trainer = TrainerClass(self.storage, **kwargs)
    self.training_data = kwargs.get('training_data')
    

    I think the behavior your are seeing due to pertained database exists in your environment.

    Could you please try to delete your sqlite database file, I think in your case it could db.sqlite

    default_uri = "sqlite:///db.sqlite3"
    

    Let me know if you need any help.