Skip to content

Commit

Permalink
Overhauled feedback system and generalized it to be cleaner with a cu…
Browse files Browse the repository at this point in the history
…stom action on the actions server (#10)
  • Loading branch information
aadiraju authored Mar 24, 2021
1 parent 73f42e5 commit 7320024
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If the above doesn't work, refer to the documentation linked above.
Once Rasa X has been installed, navigate to the root folder of the project, and do the following:
- run `rasa x` and wait for it to launch. **Note:** This may take a while depending on your system.
- _**VERY IMPORTANT**_ : In a **separate** terminal window/tab, run the command `rasa run actions`, to run a custom actions server for the bot to be able to work properly.
- If there is an error about `spaCy` model not being able to lead, run the following command, and it should work: `python -m spacy download en_core_web_md`
- If there is an error about `spaCy` model not being able to loaded, run the following command, and it should work: `python -m spacy download en_core_web_md`

Once the commands finish running, they should open up a browser window that goes directly to Rasa X like so:

Expand Down
30 changes: 27 additions & 3 deletions actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# https://rasa.com/docs/rasa/custom-actions


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
Expand All @@ -22,6 +20,32 @@ def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
jokeCat = ["good", "bad", "ok"]
dispatcher.utter_message(template="utter_" + secrets.choice(jokeCat) + "_joke")

# Tell a random joke and ask for feedback
dispatcher.utter_message(response="utter_" + secrets.choice(jokeCat) + "_joke")
dispatcher.utter_message(response="utter_ask_for_feedback")

return []


class ActionHandleFeedback(Action):

def name(self) -> Text:
return "action_handle_feedback"

def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
recentSentiment = next(tracker.get_latest_entity_values("sentiment"),
None) # Extracts the most recent sentiment
if recentSentiment == "pos":
dispatcher.utter_message(response="utter_feedback_good") # Utter good feedback response, only if feedback
# is good
elif recentSentiment is None:
dispatcher.utter_message(response="utter_default") # Handle case where there is no intent/sentiment
# extracted
else:
dispatcher.utter_message(response="utter_feedback_bad") # If feedback is neutral or negative utter bad
# feedback

return []
4 changes: 1 addition & 3 deletions data/nlu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ nlu:
- run a [joke]{"entity": "jokeformat"} by me
- run a [hiarious thing]{"entity": "jokeformat"} by me
- Tell me Another
- intent: feedback_good
- intent: feedback
examples: |
- That was funny
- Ahahah
Expand Down Expand Up @@ -145,8 +145,6 @@ nlu:
- Good one!
- that was a funny [joke]{"entity": "jokeformat"}
- I liked that one
- intent: feedback_bad
examples: |
- Meh
- Not funny
- You could do better
Expand Down
21 changes: 4 additions & 17 deletions data/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ rules:
- intent: agreetojokes
- action: utter_agreetojokes
- action: action_tell_joke
wait_for_user_input: false
- rule: userconsent handling deny
steps:
- intent: denyjokes
Expand All @@ -36,24 +35,12 @@ rules:
- intent: ask_joke
- action: utter_agreetojokes
- action: action_tell_joke
wait_for_user_input: false
- rule: always follow up joke with feedback
- rule: handle feedback
steps:
- intent: feedback
- action: action_handle_feedback
- action: action_tell_joke
- action: utter_ask_for_feedback
- rule: handle good feedback
steps:
- intent: feedback_good
- action: utter_feedback_good
- action: action_tell_joke
wait_for_user_input: false
- rule: handle bad feedback
steps:
- intent: feedback_bad
- action: utter_feedback_bad
- action: action_tell_joke
wait_for_user_input: false
- rule: Stope telling jokes when the user says they are finished
- rule: Stop telling jokes when the user says they are finished
steps:
- intent: finished
- action: utter_finished
Expand Down
34 changes: 10 additions & 24 deletions data/stories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ stories:
- gives_consent: True
- action: utter_agreetojokes #bot says yay
- action: action_tell_joke #bot gives bad one liner
- action: utter_ask_for_feedback #bot asks for feedback

- story: endconvo
steps:
Expand All @@ -51,27 +50,21 @@ stories:
- gives_consent: True
- action: utter_agreetojokes
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_bad
- intent: feedback
- action: utter_feedback_bad
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_good
- intent: feedback
- action: utter_feedback_good
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_good
- intent: feedback
- action: utter_feedback_good
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_good
- intent: feedback
- action: utter_feedback_good
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_bad
- intent: feedback
- action: utter_feedback_bad
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: finished
- action: utter_finished
- intent: goodbye
Expand All @@ -91,27 +84,21 @@ stories:
- gives_consent: True
- action: utter_agreetojokes
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_bad
- intent: feedback
- action: utter_feedback_bad
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_good
- intent: feedback
- action: utter_feedback_good
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_good
- intent: feedback
- action: utter_feedback_good
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_good
- intent: feedback
- action: utter_feedback_good
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: feedback_bad
- intent: feedback
- action: utter_feedback_bad
- action: action_tell_joke
- action: utter_ask_for_feedback
- intent: finished
- action: utter_finished
- intent: goodbye
Expand All @@ -133,4 +120,3 @@ stories:
- action: utter_finished
- intent: goodbye
- action: utter_goodbye

5 changes: 2 additions & 3 deletions domain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
intents:
- feedback_bad:
- feedback:
use_entities: true
- goodbye:
use_entities: true
Expand All @@ -17,8 +17,6 @@ intents:
use_entities: true
- finished:
use_entities: true
- feedback_good:
use_entities: true
- denyjokes:
use_entities: true
- ask_joke:
Expand Down Expand Up @@ -510,5 +508,6 @@ actions:
- utter_default
- utter_ask_rephrase
- action_tell_joke
- action_handle_feedback
forms: {}
e2e_actions: []
Binary file not shown.

0 comments on commit 7320024

Please sign in to comment.