Along with public skills, we now have private skills as web bots! Users can create their own private skills which can be used only by them and in the chatbots deployed by them. The SUSI Server accepts parameters to identify a valid private skill and applies that private skill for a particular chat. It then executes the query and sends the response to the client. This blog explains how private skill is applied in the SUSI Chat.
Understanding the API
The API to receive response from SUSI is /susi/chat.json. For applying only the public skills, we can send a request like /susi/chat.json?q=hello. Here only one parameter “q” is involved in which we send the query. However, for a private skill, the following parameters are involved:
- privateskill – when the client sends this parameter, it indicates to use a private skill.
- userid – the userid of the user who has created the private skill
- group – the group name of the private skill
- language – the language of the private skill
- skill – the skill name of the private skill
Thus, the four parameters userid, group, language, skill serves to uniquely identify a private skill.
Fetching the private skill
After the client sends the appropriate parameters to apply a private skill, the server must actually apply the private skill. This is done in a similar manner how persona and dream skills are applied. The First step is the fetch the private skill from the susi_private_skill_data folder.
Applying the private skill
After we have fetched the private skill, the next step is to apply it. To do this, we create a SusiMind object and add it to the general minds variable. Thus the skill will be applied to the particular chat with the highest priority, since it will be the first skill to be added to the minds variable. Later, the public skills can be added to the minds variable, thus their priority will be lower than the private skill.
Example API: http://localhost:4000/susi/chat.json?q=hi&privateskill=1&userid=17a70987d09c33e6f56fe05dca6e3d27&group=Knowledge&language=en&skill=knowprides
The skill exists in the correct location:
The skill file content is:
Thus, on sending the query “tell me” with the other parameters, we get the correct reply i.e “yes sure” from the server:
- JSON Object in java: https://docs.oracle.com/javaee/7/api/javax/json/JsonObject.html
- Byte array input stream: https://www.javatpoint.com/java-bytearrayinputstream-class
- Work with Files in java: https://docs.oracle.com/javase/7/docs/api/java/io/File.html