1. Learn
  2. /
  3. Courses
  4. /
  5. Building Chatbots in Python

Connected

Exercise

Putting it all together I

It's time to put everything you've learned in the course together by combining the coffee ordering bot with the ELIZA rules from chapter 1.

To begin, you'll define a function called chitchat_response(), which calls the predefined function match_rule() from back in chapter 1. This returns a response if the message matched an ELIZA template, and otherwise, None.

The ELIZA rules are contained in a dictionary called eliza_rules.

Instructions

100 XP
  • Define a chitchat_response() function which takes in a message argument.
  • Call the match_rule() function with eliza_rules and message as arguments. Unpack the output into response and phrase.
  • If the response is "default", return None.
  • If "{0}" is in the response, replace the pronouns of the phrase using replace_pronouns(), and then include the phrase in the response by using .format() on response.