使用chatterbot时出错

时间:2018-01-19 01:39:04

标签: python-3.x chatterbot

我正在尝试使用Python chatterbot创建一个简单的QnA程序。

# -*- coding: utf-8 -*-
from chatterbot import ChatBot

bot = ChatBot(
    "SQLMemoryTerminal",
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    logic_adapters=[
        {
            "import_path": "chatterbot.logic.BestMatch",
            "statement_comparison_function": 
"chatterbot.comparisons.levenshtein_distance"
        },
        {
            'import_path' : 'chatterbot.logic.LowConfidenceAdapter',
            'threshold' : 0.3,
            'default_response' : "Sorry. I can not find the exact answer."
        },
        'chatterbot.logic.multi_adapter.MultiLogicAdapter',
    ],
    input_adapter="chatterbot.input.TerminalAdapter",
    output_adapter="chatterbot.output.TerminalAdapter",
    read_only= True
)

print("input question")

while True:
    try:
        print("Q : ",end="")
        bot_input = bot.get_response(None)

    except (KeyboardInterrupt, EOFError, SystemExit):
        break

但是,当我尝试使用chatterbot中内置的multiadapter函数时,我收到错误。

Traceback (most recent call last):
  File "C:/Users/KPvoice/PycharmProjects/Contact/ChatterbotTest.py", line 
30, in <module>
    bot_input = bot.get_response(None)
  File "C:\Python36\lib\site-packages\chatterbot\chatterbot.py", line 113, 
in get_response
    statement, response = self.generate_response(input_statement, 
conversation_id)
  File "C:\Python36\lib\site-packages\chatterbot\chatterbot.py", line 132, 
in generate_response
    response = self.logic.process(input_statement)
  File "C:\Python36\lib\site-packages\chatterbot\logic\multi_adapter.py", 
line 52, in process
    output = adapter.process(statement)
  File "C:\Python36\lib\site-packages\chatterbot\logic\multi_adapter.py", 
line  89, in process
    result.confidence = max_confidence
AttributeError: 'NoneType' object has no attribute 'confidence'

我不知道如何解决它。

工作环境是Windows 10,Python 3.7

1 个答案:

答案 0 :(得分:1)

MultiLogicAdapter通常不会以这种方式直接使用。

您添加到logic_adapters=[]的每个逻辑适配器将由ChatterBot内部MultiLogicAdapter处理,无需明确指定。