Creating a personality

Building Chatbots in Python

Alan Nichol

Co-founder and CTO, Rasa

Why personality?

  • Difference between a command line app and a chatbot
  • Makes chatbots and voice assistants more accessible and fun to use
  • Your users will expect it!
Building Chatbots in Python

Smalltalk

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'
Building Chatbots in Python

Including variables

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"
Building Chatbots in Python

Choosing responses

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"
Building Chatbots in Python

Asking questions

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

Let's practice!

Building Chatbots in Python

Preparing Video For Download...