Slot type List and Text

@amn41

I’ll add my example below.

nlu.yml

version: "2.0"

nlu:
- intent: bot_challenge
  examples: |
    - are you a bot?
    - are you a human?
    - am I talking to a bot?
    - am I talking to a human?

- intent: pizza
  examples: |
    - I want a [pepperoni](toppings) and [mushroom](toppings) pizza
    - I want a [pepperoni](toppings) pizza

- lookup: toppings
  examples: |
    - pepperoni
    - mushroom

domain.yml

version: "2.0"

intents:
  - pizza
  - toppings
  - bot_challenge

responses:

  utter_pizza:
  - text: "pizza! {toppings} -- {action_toppings}"

actions:
- utter_pizza
- action_pizza_action

slots:
  toppings:
    type: list
  action_toppings:
    type: text

entities:
- toppings
- action_toppings

forms:
  order_pizza_form:
    toppings:
    - entity: toppings
      type: from_entity

session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

rules.yml

version: "2.0"

rules:

- rule: Order Pizza Form
  steps:
  - intent: pizza
  - action: order_pizza_form
  - active_loop: order_pizza_form

- rule: Ordering Pizza
  condition:
  - active_loop: order_pizza_form
  steps:
    - action: order_pizza_form
    - active_loop: null
    - slot_was_set:
      - requested_slot: null
    - action: action_pizza_action
    - action: utter_pizza

and just for completeness:

actions.py

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet


import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level='DEBUG')
logger.info("LOG")

class PizzaAction(Action):


    def name(self):
        return "action_pizza_action"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain):
        print('zap', tracker.slots)
        toppings = tracker.slots.get('toppings')
        print(toppings)
        return [SlotSet('action_toppings',  toppings)]

What happens in Interactive mode is this:

 3    slot{"toppings": ["pepperoni"]}                                                   
      order_pizza_form 1.00                                                             
      active_loop{"name": "order_pizza_form"}                                           
      slot{"toppings": ["pepperoni"]}                                                   
      slot{"toppings": "pepperoni"}                                                     
      slot{"requested_slot": null}                                                      
      active_loop{"name": null}                                                         


Current slots: 
        toppings: pepperoni, action_toppings: None, requested_slot: None, session_started_metadata: None

It starts off as a list, but it turns into a string somewhere only if the list contains one item.

This does not happen if there is more than one item in the list.

1 Like