PrestonDocks
PrestonDocks

Reputation: 5418

Rasa how to get a value (slot) from a user

I want rasa to respond to a user when they ask for a forecast for a part number.

From what I have read, I understand I need to use a slot, but I can't find a clear example that I can understand on how to get the part number from the user.

It would give me a head start if I could see an example nlu, story and domain where

  1. the user is asked for a part number
  2. The user enters the part number
  3. Rasa responds with the part number.

here is what I have so far.

domain.yml

intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
- get_supplier_forecast
entities:
- partnumber
slots:
  partnumber:
    type: text
templates:
  utter_greet:
  - text: Hey! How are you?
  utter_cheer_up:
  - text: 'Here is something to cheer you up:'
    image: https://i.imgur.com/nGF1K8f.jpg
  utter_did_that_help:
  - text: Did that help you?
  utter_happy:
  - text: Great, carry on!
  utter_goodbye:
  - text: Bye
  utter_iamabot:
  - text: I am a bot, powered by Rasa.
  utter_get_part_number:
  - text: can you give me the part number please
  utter_give_me_a_minute_while_i_check:
  - text: Give me a minute while I see if I can find a forecast for {partnumber}
  utter_confirm_part_number:
  - text: Thanks you asked for forecast for {partnumber} did this help?
actions:
- utter_greet
- utter_cheer_up
- utter_did_that_help
- utter_happy
- utter_goodbye
- utter_iamabot
- utter_get_part_number
- utter_give_me_a_minute_while_i_check
- utter_confirm_part_number

nlu.md

## intent:greet
- hey
- hello
- hi
- good morning
- good evening
- hey there

## intent:goodbye
- bye
- goodbye
- see you around
- see you later

## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct

## intent:deny
- no
- never
- I don't think so
- don't like that
- no way
- not really

## intent:mood_great
- perfect
- very good
- great
- amazing
- wonderful
- I am feeling very good
- I am great
- I'm good

## intent:mood_unhappy
- sad
- very sad
- unhappy
- bad
- very bad
- awful
- terrible
- not very good
- extremely sad
- so sad

## intent:bot_challenge
- are you a bot?
- are you a human?
- am I talking to a bot?
- am I talking to a human?

## intent:get_supplier_forecast
- Give me a forecast
- Give me a part number forecast
- I want a forecast
- I want a part number forecast
- I want a forecast for a part
- I want a supplier forecast
- Forecast delivery date
- I need a part number delivery date
- I need an item delivery date
- When will i get a part delivered

stories.md

## happy path
* greet
  - utter_greet
* mood_great
  - utter_happy

## sad path 1
* greet
  - utter_greet
* mood_unhappy
  - utter_cheer_up
  - utter_did_that_help
* affirm
  - utter_happy

## sad path 2
* greet
  - utter_greet
* mood_unhappy
  - utter_cheer_up
  - utter_did_that_help
* deny
  - utter_goodbye

## say goodbye
* goodbye
  - utter_goodbye

## bot challenge
* bot_challenge
  - utter_iamabot

## give me a forecast
* get_supplier_forecast{"partnumber":"J12345-001"}
  - slot {"partnumber":"J12345-001"}
  - utter_get_part_number
  - utter_confirm_part_number

Upvotes: 2

Views: 2548

Answers (1)

V. Dhananjaya
V. Dhananjaya

Reputation: 101

Domain file remain as the same. Try below things.

Story file:

## give me a forecast path1
* get_supplier_forecast{"partnumber":null}
  - slot {"partnumber":null}
  - utter_get_part_number
## give me a forecast path2
* get_supplier_forecast{"partnumber":"J12345-001"}
  - slot {"partnumber":"J12345-001"}
  - utter_confirm_part_number

Include this NLU file:

## intent:get_supplier_forecast
#this is how to mention slots in nlu file
- ['J12345-001'](partnumber)

Note: I don't know what is "partnumber" in your case. If there is so many of them you might wanna use "lookup tables".

From above changes first if the slot is null utter_get_part_number will trigger and if the slot is filled with a value utter_confirm_part_number will trigger

If this doesn't fulfill your need or doesn't work as expected, you can try rasa interactive training. Just run rasa interactive on CMD or try rasa x interactive talk. From this you can choose what you expect from the bot

Upvotes: 2

Related Questions