I want my ChatterBot Logic Adapters to use the default response when the user's request is below some confidence score, say 80%.
from chatterbot import ChatBot
chatbot = ChatBot(
'MyChatBot',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapters=[
'chatterbot.logic.BestMatch',
{
'import_path': 'chatterbot.logic.BestMatch',
'default_response': 'I am sorry. I am still learning!',
'maximum_similarity_threshold': 0.80
}
],
# database_uri='sqlite:///database.sqlite3'
)
# Training With Own Questions
from chatterbot.trainers import ListTrainer
trainer = ListTrainer(chatbot)
training_data1 = open('training_data/stories.txt').read().splitlines()
training_data2 = open('training_data/places.txt').read().splitlines()
training_data3 = open('training_data/questions.txt').read().splitlines()
training_data4 = open('training_data/personal.txt').read().splitlines()
training_data = training_data1 + training_data2 + training_data3 + training_data4
trainer.train(training_data)
# Training With Corpus
from chatterbot.trainers import ChatterBotCorpusTrainer
trainer_corpus = ChatterBotCorpusTrainer(chatbot)
trainer_corpus.train(
'chatterbot.corpus.english'
)
I have used the following method to get the bot's response, but it isn't using the default_response value at all.
def get_bot_response():
userText = request.args.get('msg')
if userText.confidence < maximum_similarity_threshold:
return str(chatbot.default_response)
else:
return str(chatbot.get_response(userText))
question from:
https://stackoverflow.com/questions/66057426/how-do-i-make-my-chatterbot-reply-with-the-default-message 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…