Aan de slagGa gratis aan de slag

Pending actions II

Having defined your policy() function, it's now time to write a send_message() function which takes both a pending action and a message as its arguments and leverages the policy() function to determine the bot's response.

Your policy(intent) function from the previous exercise has been pre-loaded.

Deze oefening maakt deel uit van de cursus

Building Chatbots in Python

Cursus bekijken

Oefeninstructies

  • Define a function called send_message() which takes in two arguments: pending and message.
  • Pass in the interpretation of message as an argument to policy() and unpack the result into the variables action and pending_action.
  • If the action is "do_pending" and pending is not None, print the pending response. Else, print the action.
  • Inside the definition of the send_messages() function, call your send_message() function with pending and msg as arguments. Then, hit 'Submit Answer' to send the messages and see the results.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Define send_message()
def ____(____, ____):
    print("USER : {}".format(message))
    ____, ____ = ____
    if ____ == "____" and pending is not None:
        print("BOT : {}".format(____))
    else:
        print("BOT : {}".format(____))
    return pending_action
    
# Define send_messages()
def send_messages(messages):
    pending = None
    for msg in messages:
        pending = ____

# Send the messages
send_messages([
    "I'd like to order some coffee",
    "ok yes please"
])
Code bewerken en uitvoeren