ELIZA IV: Putting it all together

ELIZA IV: Putting it all together

_______________________________________

Problem Statement:

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 the phrase.
Include the phrase by using .format() on the response and overriding the value of the response.

_______________________________________

Problem Solution:

def respond(message):
# Call match_rule
response, phrase = match_rule(rules, message)
if '{0}' in response:
# Replace the pronouns in the phrase
phrase = replace_pronouns(phrase)
# Include the phrase in the response
response = response.format(phrase)
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")

_______________________________________

Last modified: Monday, 26 December 2022, 3:17 PM