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.core.agent import Agent, HighestConfidenceSelector

Create skills as pre-defined responses for a user’s input containing specific keywords. 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 = Agent([hello, bye, fallback], skills_selector=HighestConfidenceSelector())

Give the floor to the HelloBot!

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