ComenzarEmpieza gratis

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

Ver curso

Instrucciones del ejercicio

  • Get a response and phrase by calling match_rule() with the rules dictionary and message.
  • Check if the response is a template by seeing if it includes the string '{0}'. If it does:
    • Use the replace_pronouns() function on phrase.
    • Include the phrase by using .format() on response and overriding the value of response.
  • 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")
Editar y ejecutar código