For making a system more reliable and robust, continuous evaluation is quite important. So is in case of SUSI AI. User feedback is important to improve SUSI skills and create new ones. Previously we had only thumbs up / thumbs down as a feedback method, from the susi chat client. But now a 5 star rating system has been added to the SUSI Skill CMS so that users can rate a skill there. Before the implementation of API let’s look how data is stored in SUSI AI Susi_server uses DAO in which skill rating is stored as JSONTray.
The server side implementation
A new java class has been created for the API, FiveStarRateSkillService.java.
public class FiveStarRateSkillService extends AbstractAPIHandler implements APIHandler { private static final long serialVersionUID =7947060716231250102L; @Override public BaseUserRole getMinimalBaseUserRole() { return BaseUserRole.USER; } @Override public JSONObject getDefaultPermissions(BaseUserRole baseUserRole) { return null; } @Override public String getAPIPath() { return "/cms/rateSkill.json"; } ... }
The getMinimalBaseRole method tells the minimum User role required to access this servlet it can also be ADMIN, USER or ANONYMOUS. In our case it is USER. A user needs to be logged in to rate a skill on a scale of 1-5 stars. The API runs at “/cms/fiveStarRateSkill.json” endpoint.
Next, create serviceImpl method in the above class to handle the request from the client and respond to it.
1. Fetch the required query parameters and store them in variables. They include skill model, group, language, skill name and starts that the user has given in the rating.
String skill_name = call.get("skill", null); String skill_stars = call.get("stars", null);
2. Then check if the skill exists. If not them throw an exception. Otherwise, increment the count of the corresponding rating. The rating object has keys as one_star, two_star, three_star, four_star and five_star that has the count of that star rating.
if (skill_stars.equals("1")) { skillName.put("one_star", skillName.getInt("one_star") + 1 + ""); } else if (skill_stars.equals("2")) { skillName.put("two_star", skillName.getInt("two_star") + 1 + ""); } else if (skill_stars.equals("3")) { skillName.put("three_star", skillName.getInt("three_star") + 1 + ""); } else if (skill_stars.equals("4")) { skillName.put("four_star", skillName.getInt("four_star") + 1 + ""); } else if (skill_stars.equals("5")) { skillName.put("five_star", skillName.getInt("five_star") + 1 + ""); }
3. Re-calculate the total rating done on that skill and its average rating and update the object. If the skill has not been already rated then create a new rating object and initialize it with the 0 star counts.
public JSONObject createRatingObject(String skill_stars) { JSONObject skillName = new JSONObject(); JSONObject skillStars = new JSONObject(); skillStars.put("one_star", 0); skillStars.put("two_star", 0); skillStars.put("three_star", 0); skillStars.put("four_star", 0); skillStars.put("five_star", 0); skillStars.put("avg_star", 0); skillStars.put("total_star", 0); skillName.put("stars", skillStars); }
The complete FiveStarRateSkillService.java is available here : –
Rating a skill
Sample endpoint
This gives 3 star rating to the “aboutsusi” skill.
Parameters
- Model
- Group
- Language
- Skill
- Stars
Response
{ "ratings": { "one_star": 0, "four_star": 0, "five_star": 1, "total_star": 1, "three_star": 0, "avg_star": 5, "two_star": 0 }, "session": {"identity": { "type": "email", "name": "1anuppanwar@gmail.com", "anonymous": false }}, "accepted": true, "message": "Skill ratings updated" }
Getting the stats of Skill Ratings
Sample endpoint
This fetches the current ratings of the “aboutsusi” skill.
Parameters
- Model
- Group
- Language
- Skill
Response
{ "session": { "identity": { "type": "host", "name": "172.68.144.159_81c88a10", "anonymous": true } }, "skill_name": "aboutsusi", "accepted": true, "message": "Skill ratings fetched", "skill_rating": { "negative": "0", "positive": "0", "stars": { "one_star": 0, "four_star": 2, "five_star": 1, "total_star": 4, "three_star": 1, "avg_star": 4, "two_star": 0 }, "feedback_count": 3 } }
Conclusion
So this 5 star rating system will help in improving the SUSI skills. Also, it will help in making better decisions when we have multiple similar skills and we have to choose one to respond to the user query.
References
- Using SUSI AI Server to Store User Feedback for a Skill https://blog.fossasia.org/using-susi-ai-server-to-store-user-feedback-for-a-skill/