Multi-turn story example: Apply filter

Beyond single-turn command-and-control stories, Diatheke can model complex dialogues with multiple interactions between the user and the system. Diatheke can prompt the user for more information (“slot filling”) and can respond to multiple different intents in the context of the same story.

Required slots

All entities are by default optional. That means it is okay if they are not specified by the user. A story can also define some slots as required for a given intent. If the user doesn’t include a required entity in the initial utterance, Diatheke will prompt the user. This is called “slot filling” and is the most common form of multi-turn dialogue.

For example, in the apply_filter_story, the image_filter slot is required. If the user says “Apply vintage filter”, Diatheke immediately returns the apply_filter_command, but if they just say “apply filter”, Diatheke will prompt “What filter do you want to apply?” The user can then answer just “vintage” to fill in the slot.

Modeling this interaction flow involves multiple files:

  • Identiying image_filter as a required slot for the apply_filter_intent occurs in the story in which apply_filter_intent is called. In this case, it is in main.yaml. (In the example code below, everything in main.yaml as the same as earlier in the tutorial except for the addition of required_slots.)
  • The wording for prompting a user to fill a slot is in prompt_for_image_filter.yaml in the replies directory.
  • Designating prompt_for_image_filter as the prompt for the image_filter slot can be either in apply_filter_intent.yaml or in the specific stories from which the intent is called. Since we’d probably want the same wording whenever we’re prompting for a filter, we’ll configure it in the intent file.
  • There is a special intent defined in slot_fill_intent.yaml that matches an entity value uttered without other context.
  • The image_filter entity, apply_filter reply and command are defined in their respective files and apply_filter_story.yaml ties them all together.

Slot Filling Example


init_actions:
  - type: reply
    id: welcome_message
  - type: input
    id: main_input

start_actions:
  - type: input
    id: main_input
    
input_actions:
  - name: main_input
    intents:
    # In this example, required_slots has been added to the apply_filter_intent
      - intent_id: apply_filter_intent
        required_slots:
        - image_filter
        actions:
          - type: story
            id: apply_filter_story
      - intent_id: zoom_intent
        actions:
          - type: story
            id: zoom_story

defaults:
  no_intent_actions:
    - type: reply
      id: no_intent_reply

language_data:
  en_US:
    example_utterances:
      - Apply ${image_filter} filter
      - Apply ${image_filter}
      - Make the picture look ${image_filter}
      - Apply a ${image_filter} filter
      - Apply the ${image_filter} filter
      - ${image_filter} filter
slot_prompts:
  - slot: image_filter
    reply_id: prompt_for_image_filter

language_data:
  en_US:
    - Which filter would you like to apply?

language_data:
  en_US:
    example_utterances:
      - ${image_filter}

format: value_list

language_data:
  en_US:
    values:
      - vintage
      - lomo
      - clarity
      - sin city
      - sunrise
      - cross process
      - orange peel
      - love
      - grungy
      - jarques
      - pinhole
      - old boot
      - glowing sun
      - hazy days
      - her majesty
      - nostalgia
      - hemingway
      - concentrate
      - black and white
      - bright
      - greyscale
      - grayscale

start_actions:
    - type: command
      id: apply_filter_command
    - type: reply
      id: apply_filter_reply  

# This command applies the requested filter to the photograph.
inputs:
  - image_filter 

outputs: # This command returns nothing.


language_data:
  en_US:
    - Applying ${image_filter} filter.

Next we’ll extend the Apply Filters story to include multiple intents by allowing the users to ask what filters are available.