Hello bot!

Open in Colaboratory

!pip install -q deeppavlov

Import key components to build HelloBot.

from deeppavlov.skills.pattern_matching_skill import PatternMatchingSkill
from deeppavlov.agents.default_agent.default_agent import DefaultAgent
from deeppavlov.agents.processors.highest_confidence_selector import HighestConfidenceSelector

Create skills as pre-defined responses for a user’s input containing specific keywords and regular expressions. Every skill returns response and confidence.

hello = PatternMatchingSkill(responses=['Hello world!'], patterns=["hi", "hello", "good day"])
bye = PatternMatchingSkill(['Goodbye world!', 'See you around'],
                           patterns=["bye", "chao", "see you"])
fallback = PatternMatchingSkill(["I don't understand, sorry", 'I can say "Hello world!"'])

Agent executes skills and then takes response from the skill with the highest confidence.

agent = DefaultAgent([hello, bye, fallback], skills_selector=HighestConfidenceSelector())

Give the floor to the HelloBot!

agent(['Hello', 'Bye', 'Or not'])
['Hello world!', 'Goodbye world!', 'I can say "Hello world!"']