...

/

Building Chatbots with Rasa and Python

Building Chatbots with Rasa and Python

Learn how to create a Rasa chatbot with a Gradio frontend.

Let’s pick up where we left off. After running rasa init, we are provided with the basic files needed to create a chatbot. We can keep the default functionality for now and add our new features on top. While we'll eventually create an educational chatbot, let’s keep it simple for now. In this lesson, we'll create a chatbot that will answer some simple questions about Educative subscriptions.

Creating intents

Recognizing the user’s intent is key. Rasa stores intents in the nlu.yml file in the data directory. By default, Rasa has some basic intents, such as greet , goodbye, affirm and deny. An intent is created by first defining the intent, followed by a few examples of phrases categorized under that intent. The widget below contains a nlu.yml file with a new subscription intent.

Press + to interact
version: "3.1"
nlu:
- intent: subscription
examples: |
- How can I buy a subscription?
- How much does Educative cost?
- What payment methods do you accept?
- subscription
- payment
- cost
- buy
- intent: greet
examples: |
- hey
- hello
- hi
- hello there
- good morning
- good evening
- moin
- hey there
- let's go
- hey dude
- goodmorning
- goodevening
- good afternoon
- intent: goodbye
examples: |
- cu
- good by
- cee you later
- good night
- bye
- goodbye
- have a nice day
- see you around
- bye bye
- see you later
- intent: affirm
examples: |
- yes
- y
- indeed
- of course
- that sounds good
- correct
- intent: deny
examples: |
- no
- n
- never
- I don't think so
- don't like that
- no way
- not really
- intent: mood_great
examples: |
- perfect
- great
- amazing
- feeling like a king
- wonderful
- I am feeling very good
- I am great
- I am amazing
- I am going to save the world
- super stoked
- extremely good
- so so perfect
- so good
- so perfect
- intent: mood_unhappy
examples: |
- my day was horrible
- I am sad
- I don't feel very well
- I am disappointed
- super sad
- I'm so sad
- sad
- very sad
- unhappy
- not good
- not very good
- extremly sad
- so saad
- so sad
- intent: bot_challenge
examples: |
- are you a bot?
- are you a human?
- am I talking to a bot?
- am I talking to a human?

Our examples consist of common questions and phrases with the intent of learning about the subscription details.

Creating stories

Now that we have defined our new intent, we can create our stories. A story in Rasa is a sequence of actions that the chatbot will take in response to a particular intent. For the subscription intent, we want to provide information about subscription plans, pricing, payment options, and perhaps a link to the purchase page. For this, we'll use the stories.yml file in the data directory.

Press + to interact
version: "3.1"
stories:
- story: get subscription information
steps:
- intent: subscription
- action: utter_subscription_info
- story: happy path
steps:
- intent: greet
- action: utter_greet
- intent: mood_great
- action: utter_happy
- story: sad path 1
steps:
- intent: greet
- action: utter_greet
- intent: mood_unhappy
- action: utter_cheer_up
- action: utter_did_that_help
- intent: affirm
- action: utter_happy
- story: sad path 2
steps:
- intent: greet
- action: utter_greet
- intent: mood_unhappy
- action: utter_cheer_up
- action: utter_did_that_help
- intent: deny
- action: utter_goodbye

We have created a basic story that will play out if the intent is classified as subscription. We want the chatbot to ...