Any examples of using multilogicadapter in chatterbot?

1.8k Views Asked by At

I am trying to combine multiple logic adapters in Python chatterbot. I cannot seem to get it right. I tried this:

english_bot = ChatBot("English Bot", 
storage_adapter="chatterbot.storage.SQLStorageAdapter",
multi_logic_adapter = [
    "chatterbot.logic.MathematicalEvaluation",
    "chatterbot.logic.TimeLogicAdapter",
    "chatterbot.logic.BestMatch"]
)

Only BestMatch seems to be active And I tried this:

english_bot = ChatBot("English Bot", 
storage_adapter="chatterbot.storage.SQLStorageAdapter",
logic_adapter = [
    "chatterbot.logic.multi_adapter.MultiLogicAdapter", 
    "chatterbot.logic.MathematicalEvaluation",
    "chatterbot.logic.TimeLogicAdapter",
    "chatterbot.logic.BestMatch"]
)

But I get this error: AttributeError: 'NoneType' object has no attribute 'confidence' and none of the logic_adapters seems to be active.

Thanks, Herb

4

There are 4 best solutions below

1
On

BestMatch

Adapter is the default adapter for chatterbot, You don't need explicitly specify that. More information http://chatterbot.readthedocs.io/en/stable/logic/index.html#best-match-adapter

And you code should like this

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

bot = ChatBot(
    "English Bot",
    logic_adapters=[
        "chatterbot.logic.MathematicalEvaluation",
        "chatterbot.logic.TimeLogicAdapter"
    ]
)

# Print an example of getting one math based response
response = bot.get_response("What is 4 + 9?")
print(response)

# Print an example of getting one time based response
response = bot.get_response("What time is it?")
print(response)
0
On

Multi Logic adapter is an inbuilt class and is not explicitly defined in the code.You can see this statement in the introduction part:"ChatterBot internally uses a special logic adapter that allows it to choose the best response generated by any number of other logic adapters" This is the link - http://chatterbot.readthedocs.io/en/stable/logic/multi-logic-adapter.html

Also, similar query is already available on stackover flow. Refer this as well. Error while using chatterbot

0
On

Every logic adapter in logic_adapters=[] is automatically processed by MultiLogicAdapter. You might need to tweak the confidence levels though.

More info about the MultiLogicAdapter here: http://chatterbot.readthedocs.io/en/stable/logic/multi-logic-adapter.html

0
On

The MultiLogicAdapter typically doesn't get used directly in this way.

Each logic adapter that you add to the logic_adapters=[] will get processed by the MultiLogicAdapter internally by ChatterBot, no need to explicitly specify it.