Hello bot!

Open in Colaboratory

In [1]:
!pip install -q deeppavlov

Import key components to build HelloBot.

In [2]:
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.

In [3]:
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.

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

Give the floor to the HelloBot!

In [5]:
agent(['Hello', 'Bye', 'Or not'])
['Hello world!', 'See you around', "I don't understand, sorry"]