How to achieve dialogue scoring

I wanted to implement a feature where users could rate a conversation at the end of the conversation;How can I store the dialogue and the corresponding score in the database? Can I use the table Events?

Make a custom action “action_rate_store” which extracts score entity from user input and put it at the end of all your stories. Write mySQL connection code in the custom action which stores the score input in a column of the table.


class ActionRateScore(Action):
    def name(self) -> Text:
        return "action_rate_score"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        
        db = mysql.connect(
            host="localhost",
            user="user",
            password="password",
            database="database"
        )
        sender_id = tracker.current_state()['sender_id']
        cursor = db.cursor()
        val=tracker.get_slot("score")
        cursor.execute("UPDATE table SET score = '%s' where id='%s'" %(val,sender_id))
        db.commit()
        return []

create a mysql database (“database” in this snippet) with a table inside (“table” in this snippet). Replace username and password with valid credentials.

2 Likes

@holdrain you can even see this repo with the example: https://github.com/cedextech/rasa-chatbot-templates/tree/master/04_feedback_bot and use the tracker store to save the rating in the database (Postgres or SQL). OR What Sandeep suggested that can be possible. Good Luck!

2 Likes

You have been very helpful, I have solved the problem and I have made some changes in the code:

class ActionSaveRate(Action):

    def name(self) -> Text:

            return "action_save_rate"
    def run(
    self,
    dispatcher: "CollectingDispatcher",
    tracker: Tracker,
    domain: Dict[Text, Any]):
    db = mysql.connector.connect(
        host="localhost",
        user="root",
        password="root",
        database="rasa"
    )
    sender_id = tracker.current_state()['sender_id']
    cursor = db.cursor()

    val = tracker.get_slot("score")

    cursor.execute("UPDATE events SET score = '%s' where sender_id = '%s'" % (val, sender_id))

    db.commit()

    return []

ok! useful

no worries.