Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

python - How do I make my Chatterbot reply with the default message?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...