简体   繁体   中英

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?

@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.

You can use Specific Response Adapter. Below is the sample code. You can find more on this link: http://chatterbot.readthedocs.io/en/stable/logic/index.html

{ 'import_path': 'chatterbot.logic.SpecificResponseAdapter', 'input_text': 'Help me!', 'output_text': 'Ok, here is a link: http://chatterbot.rtfd.org ' }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM