ELIZA IV: Putting it all together
Now you're going to put everything from the previous exercises together and experience the magic!
The match_rule()
, send_message()
, and replace_pronouns()
functions have already been defined, and the rules
dictionary is available in your workspace.
Your job here is to write a function called respond()
with a single argument message
which creates an appropriate response to be handled by send_message()
.
Este ejercicio forma parte del curso
Building Chatbots in Python
Instrucciones del ejercicio
- Get a
response
andphrase
by callingmatch_rule()
with therules
dictionary andmessage
. - Check if the
response
is a template by seeing if it includes the string'{0}'
. If it does:- Use the
replace_pronouns()
function onphrase
. - Include the
phrase
by using.format()
onresponse
and overriding the value ofresponse
.
- Use the
- Hit 'Submit Answer' to see how the bot responds to the provided messages!
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# Define respond()
def respond(message):
# Call match_rule
____, ____ = ____
if '{0}' in response:
# Replace the pronouns in the phrase
phrase = ____
# Include the phrase in the response
response = ____
return response
# Send the messages
send_message("do you remember your last birthday")
send_message("do you think humans should be worried about AI")
send_message("I want a robot friend")
send_message("what if you could be anything you wanted")