覆盖 ChatterBot 中的预定义答案

Overriding pre-defined answer in ChatterBot

我想针对使用 ChatterBot 库编写的聊天机器人的特定问题指定我自己的答案。这是我的代码

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)

运行这段代码后的输出是

谁啊?谁不过是一个遵循什么功能的形式

而不是

我是一个友好的聊天机器人

所以看起来图书馆中嵌入了这个问题的预先指定的答案。如何配置只使用我的答案的机器人?

@DavidBankom 该机器人将仅使用您的数据进行训练。代码片段还从 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')

我认为您所看到的行为是由于 pertained database exists 在您的环境中造成的。

能否请您尝试删除您的 sqlite 数据库文件,我认为在您的情况下可以 db.sqlite

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

如果您需要任何帮助,请告诉我。

您可以使用特定响应适配器。下面是示例代码。您可以在 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' }