Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illustrate CALM slot mappings v2 improvements #70

Draft
wants to merge 3 commits into
base: release-3.12
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions actions/order_pizza.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ def run(self, dispatcher: CollectingDispatcher,
return [SlotSet("membership_points", 150)]


class ActionCorrectOrderDetails(Action):

def name(self) -> str:
return "action_ask_correct_order"

def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker, domain: Dict[str, Any]):
dispatcher.utter_message(
text="I'm sorry about that. Let's correct your order. What would you like to change?",
buttons=[
{"title": "Pizza", "payload": "/SetSlots(pizza=null)"},
{"title": "Quantity", "payload": "/SetSlots(num_pizza=null)"},
{"title": "Address", "payload": "/SetSlots(address=null)"},
]
)
return [SlotSet("confirmation_order", None), SlotSet("correct_order", True)]


class ActionShowVacancies(Action):

def name(self) -> str:
Expand All @@ -74,16 +56,3 @@ def run(self, dispatcher: CollectingDispatcher,
text="We don't have any vacancies at the moment in that department. Please check back later."
)
return []


class ActionCorrectAddress(Action):

def name(self) -> str:
return "action_correct_address"

def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker, domain: Dict[str, Any]):
dispatcher.utter_message(
text="I'm sorry about that. Let's correct your address. Please confirm your new address?"
)
return [SlotSet("address", None)]
10 changes: 10 additions & 0 deletions actions/setup_recurrent_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@


def parse_datetime(text: str) -> Optional[datetime]:
# If the text is already a date slot value extracted from Duckling,
# we can just use it
try:
result = datetime.fromisoformat(text)
return result.replace(tzinfo=None)
except ValueError:
pass

# Otherwise, we need to parse the value set by the LLM
# using Duckling
msg = Message.build(text)
duckling_entity_extractor.process([msg])
if len(msg.data.get("entities", [])) == 0:
Expand Down
35 changes: 0 additions & 35 deletions data/flows/nlu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,6 @@ nlu:
- [3](number) pizzas
- [4](number) pizzas

- intent: correct_order
examples: |
- I actually need to update my order.
- I made a mistake in my order.
- I need to change my order.
- I made a mistake in the delivery address.
- I need to update the delivery address.
- I made a mistake in the payment option.

- intent: correct_num_pizza
examples: |
- I actually want to order [2](number) pizzas.
- Need [10](number) pizzas now instead.
- I actually want to order [3](number) pizzas.
- I actually want to order [4](number) pizzas.
- I actually want to order [5](number) pizzas.
- I actually want to order [6](number) pizzas.
- I actually want to order [7](number) pizzas.
- I actually want to order [8](number) pizzas.
- I actually want to order [9](number) pizzas.
- I actually want to order [10](number) pizzas.

- intent: correct_pizza_type
examples: |
- I actually want to order a [margherita](pizza_type) pizza.
Expand All @@ -202,19 +180,6 @@ nlu:
- Actually, can i get a [diavola](pizza_type) instead.
- Actually, can i get a [quattro formaggi](pizza_type) instead.

- intent: correct_address
examples: |
- I actually want to change the delivery address to 13 Pine Road.
- actually can i get the pizza delivered to 13 Pine Road.
- I made a mistake and need to update my delivery address first to 43 Elm Street.
- Send the pizza to 25 Maple Avenue instead.
- I need to update the delivery address to 59 Oak Drive.

- intent: correct_payment_option
examples: |
- Can I pay with credit card instead?
- I actually want to pay with membership points.

- intent: affirm
examples: |
- Yes, that's correct.
Expand Down
22 changes: 0 additions & 22 deletions data/flows/order_pizza.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,6 @@ flows:
next: END
- else: END

correct_order:
name: correct_order
description: user wants to correct order details
nlu_trigger:
- intent:
name: correct_order
confidence_threshold: 0.5
steps:
- collect: correct_order
- call: fill_pizza_order

correct_address:
name: correct_address
description: user wants to correct the delivery address
nlu_trigger:
- intent:
name: correct_address
confidence_threshold: 0.7
steps:
- action: action_correct_address
- call: fill_pizza_order

job_vacancies:
name: job vacancies
description: user asks for job vacancies
Expand Down
8 changes: 8 additions & 0 deletions data/flows/setup_recurrent_payment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ flows:
- collect: recurrent_payment_frequency
description: the frequency of the payment
- collect: recurrent_payment_start_date
# we need to set the ask_before_filling flag to true to
# ensure that the bot does not mishandle corrections for this
# slot at the next step
ask_before_filling: true
description: the start date of the payment
- collect: recurrent_payment_end_date
# we need to set the ask_before_filling flag to true to
# ensure that the bot does not eagerly fill this slot
# at the collect step prior to this one
ask_before_filling: true
description: the end date of the payment
rejections:
- if: slots.recurrent_payment_end_date < slots.recurrent_payment_start_date
Expand Down
16 changes: 7 additions & 9 deletions domain/flows/order_pizza.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ intents:
- inform_pizza_type
- inform_address
- inform_num_pizza
- correct_order
- correct_num_pizza
- correct_pizza_type
- correct_address
- correct_payment_option
- affirm
- deny

Expand All @@ -24,6 +20,7 @@ slots:
mappings:
- type: from_entity
entity: pizza_type
- type: from_llm
num_pizza:
type: float
mappings:
Expand All @@ -32,19 +29,20 @@ slots:
intent: inform_num_pizza
conditions:
- active_flow: fill_pizza_order
- type: from_entity
entity: number
intent: correct_num_pizza
- type: from_llm
allow_nlu_correction: true
conditions:
- active_flow: fill_pizza_order
- active_flow: order_pizza
- active_flow: fill_pizza_order
- active_flow: order_pizza
address:
type: text
mappings:
- type: from_text
intent: inform_address
conditions:
- active_flow: fill_pizza_order
- type: from_llm
allow_nlu_correction: true
confirmation_order:
type: bool
mappings:
Expand Down
4 changes: 4 additions & 0 deletions domain/flows/setup_recurrent_payment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ slots:
type: any
mappings:
- type: from_llm
- type: from_entity
entity: time # shared entity defined in restaurant.yml domain file
recurrent_payment_end_date:
type: any
mappings:
- type: from_llm
- type: from_entity
entity: time
recurrent_payment_confirmation:
type: bool
mappings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ test_cases:
- user: /SetSlots(confirmation_order=True)
- utter: utter_ask_payment_option
- user: wait, i meant to say the pizza should be delivered to 13 Pine Road.
- bot: "I'm sorry about that. Let's correct your address. Please confirm your new address?"
- utter: utter_ask_address
- user: 13 Pine Road
- bot: Would you like to change the address?
- user: /SetSlots(confirm_slot_correction=true)
- utter: utter_corrected_previous_input
- utter: utter_confirm
- user: /SetSlots(confirmation_order=True)
- utter: utter_flow_continue_interrupted
- utter: utter_ask_payment_option

- test_case: user_orders_pizza_stating_which_type_and_corrects_payment_option_later
Expand All @@ -72,7 +71,7 @@ test_cases:
- utter: utter_corrected_previous_input
- utter: utter_ask_card_details

- test_case: user_orders_pizza_stating_which_type_and_corrects_order_details_later
- test_case: user_orders_pizza_stating_which_type_and_corrects_address_mistake_later
steps:
- user: I would like to order a diavola pizza.
- utter: utter_ask_num_pizza
Expand All @@ -83,12 +82,11 @@ test_cases:
- user: /SetSlots(confirmation_order=True)
- utter: utter_ask_payment_option
- user: actually, i made a mistake and need to update my delivery address first.
- bot: "I'm sorry about that. Let's correct your order. What would you like to change?"
# TODO: ideal place to assert planned buttons feature in e2e testing
- user: /SetSlots(address=null)
- bot: Would you like to change the address?
- user: /SetSlots(confirm_slot_correction=true)
- utter: utter_corrected_previous_input
- utter: utter_ask_address
- user: 3 Pine Road
- user: 31 Pine Road
- utter: utter_confirm
- user: /SetSlots(confirmation_order=True)
- utter: utter_flow_continue_interrupted
- utter: utter_ask_payment_option
9 changes: 4 additions & 5 deletions e2e_tests/passing/corrections/user_corrects_string_slot.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
test_cases:
- test_case: user corrects string slot
steps:
# NLUCommandAdapter should start the flow, so "Peter" is not detected as an entity
# NLUCommandAdapter should start the flow, and the SingleStepLLMCommandGenerator should
# set detect the value for the slot "add_contact_name"
- user: I want to add Peter to my contacts
- slot_was_set:
- route_session_to_calm: True
- slot_was_set:
- add_contact_name: "Peter"
- utter: utter_ask_add_contact_handle
- user: It's @PeterPark
- slot_was_set:
- add_contact_handle: "@PeterPark"
- utter: utter_ask_add_contact_name
- user: Peter
- slot_was_set:
- add_contact_name: "Peter"
- utter: utter_ask_add_contact_confirmation
- user: Ah, please use Spidey as the name
- utter: utter_ask_confirm_slot_correction
Expand Down
9 changes: 4 additions & 5 deletions e2e_tests/passing/digressions/user_asks_what_info_is.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
test_cases:
- test_case: user asks what requested information is
steps:
# NLUCommandAdapter should start the flow, so "Peter" is not detected as an entity
# NLUCommandAdapter should start the flow, and the SingleStepLLMCommandGenerator should
# set detect the value for the slot "add_contact_name"
- user: I want to add Kate to my contacts
- slot_was_set:
- route_session_to_calm: True
- slot_was_set:
- add_contact_name: "Kate"
- utter: utter_ask_add_contact_handle
- user: What's a contact handle?
# not able to test the response of enterprise search
# - utter: utter_contact_handle_info
- utter: utter_ask_add_contact_handle
- user: Ah okay she sent it to me, it's @KatePurry
- utter: utter_ask_add_contact_name
- user: Kate
- slot_was_set:
- add_contact_name: "Kate"
- utter: utter_ask_add_contact_confirmation
- user: "yes"
- utter: utter_contact_added
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ test_cases:
- user: Please show my contacts
- utter: utter_list_contacts
- utter: utter_can_do_something_else
# The NLUCommandAdapter predicts the StartFlow(remove_contact) so the contact handle is not yet detected
# The NLUCommandAdapter predicts the StartFlow(remove_contact) and the SingleStepLLMCommandGenerator should
# set detect the value for the slot "add_contact_name"
- user: Remove contact @MaryLu
# we use action_ask_remove_contact_handle for the collect step
- user: "@MaryLu"
- slot_was_set:
- remove_contact_handle: "@MaryLu"
- utter: utter_ask_remove_contact_confirmation
Expand Down
Loading
Loading