我要通过聊天机器人做一个聊天机器人。我面对的问题如下:
SquirralBot:...SquirralBot.py文件中的第5行,SquirralBot bot =Chatbot中的第6行(“SquirralBot”,NameError: name 'Chatbot‘)中的文件“./ScapralBot.py”
上述代码如下。我在编程方面非常新,所以代码可能有点混乱。请随时纠正。非常感谢。
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]))发布于 2019-06-05 13:41:51
导入语句提示具有大写ChatBot B的类
从chatterbot进口ChatBot
变化
chatbot = Chatbot("SquirralBot",...)至
chatbot = ChatBot("SquirralBot",...)请注意ChatBot中的大写B。
https://stackoverflow.com/questions/53978292
复制相似问题