我正在通过 Chatterbot 制作聊天机器人。我面临以下问题:
- 当我运行代码时,它显示错误,但 ChatBot 一开始是从 chatterbot 导入的?
文件“.../SquirralBot.py”,第 5 行,在 SquirralBot 类中:文件“...SquirralBot.py”,第 6 行,在 SquirralBot 中 bot = Chatbot("SquirralBot", NameError: name 'Chatbot' is not defined
我想让聊天机器人区分特定的文本然后触发特定的语料库,我该怎么做?“chatterbot.conversation.Response(text, **kwargs)” 类是为了这个目的吗?例如,当用户输入“我要离开”时,会触发调用训练集“chatterbot.corpus.chinese.squirral_bye_conversation”?
如果我可以将回复专门存储到数据库中,例如不同用户的 MongoDB,是否有可能?例如当用户A回复“我生病了。我发烧流鼻涕”时,系统将“生病”存入“状态”,将“发热”和“流鼻涕”存入用户A的数据中的“症状”中,以便内部数据库就像 JSON:
{“用户A”,“性别”:“男性”,“记录”:[{“日期”:“25-12-2018”,“状态”:“罚款”,“症状”:“”,},{ “日期”:“26-12-2018”,“状态”:“生病”,“症状”:“发烧”,“流鼻涕”} }
是否可以让聊天机器人在特定时间范围内向用户发送短信?
上述代码如下。我是编程新手,所以代码可能有点乱。请随时纠正。非常感谢。
import sys
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
class SquirralBot:
chatbot = Chatbot("SquirralBot",
logic_adapters=[
{
"import_path": "chatterbot.logic.BestMatch",
"statement_comparison_function": "chatterbot.comparisons.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
}
],storage_adapter = "chatterbot.storage.JsonFileStorageAdapter",database = "./SquirralBot_DB.json")
def __init__(self):
self.chatbot.set_trainer(ChatterBotCorpusTrainer)
self.chatbot.train("chatterbot.corpus.chinese.squirral_greeting", "chatterbot.corpus.chinese.squirral_bye_conversation", "chatterbot.corpus.chinese.squirral_normal_conversation", "chatterbot.corpus.chinese.squirral_rabbit_bye_conversation", "chatterbot.corpus.chinese.squirral_rabbit_conversation")
def getResponse(self, message=""):
return self.chatbot.get_response(message)
if __name__ == "__main__":
bot = SquirralBot()
print(bot.getResponse(sys.argv[1]))