Building Chatbots in Python
Alan Nichol
Co-founder and CTO, Rasa
responses = { "what's your name?": "my name is EchoBot", "what's the weather today?": "it's sunny!" }
def respond(message): if message in responses: return responses[message]
respond("what's your name?")
'my name is EchoBot'
responses = { "what's today's weather?": "it's {} today" }
weather_today = "cloudy" def respond(message): if message in responses: return responses[message].format(weather_today) respond("what's today's weather?")
"it's cloudy today"
responses = { "what's your name?": [ "my name is EchoBot", "they call me EchoBot", "the name's Bot, Echo Bot" ] }
import random
def respond(message): if message in responses: return random.choice(responses[message])
respond("what's your name?")
"the name's Bot, Echo Bot"
responses = [ "tell me more!", "why do you think that?" ]
import random
def respond(message):
return random.choice(responses)
respond("I think you're really great")
'why do you think that?'
Building Chatbots in Python