How to make a Snips skill – Part 6 – Put everything together - Publish the App and Actions

20. January 2019 18:35
4 min reading
This post thumbnail

In the last 5 parts we were looking at many different subjects not only specifically related to Snips. We made some excursions towards Python specifics and towards Multilanguage issues. Now is the time to put all the pieces together inside our Raspberry Pi and try out our App.

Table of Content

  1. Overview
  2. Intents – how to get data for slots and intents
  3. All about API – get the needed public transport data
  4. Data to spoken text – what about Multilanguage
  5. Develop the actions – tell Snips what to do
  6. Put everything together – publish and debug the App and Actions

Publish the App to GitHub

Before you publish your Snips App for the general public, you have to push your App code onto GitHub or another publicly accessible code repository (should also work with GitLab). Before we do that, there are a couple of requirements we have to fulfill so that SAM, the Snips Command Line Interface is able to pick up our actions and install them accordingly into our Raspberry Pi.

Prepare requirements.txt for our actions

If we use anything more than standard Python libraries who are installed together with the Python distribution, we need to tell SAM what other libraries our actions code is expecting. This is done with the requirements.txt file. This file is provided in the Snips Template (see Part 5 of the Blog Series). We just have to add the additional libraries. In our case this is requests and python-dateutil. This leaves us with the following requirements.txt:

# Bindings for the hermes protocol 
hermes-python>=0.1

# More dependency goes here..
requests
python-dateutil

Line endings in our code files

We have to make sure the line endings in our code are just LF instead of CRLF. If we develop on a Windows System chances are, that our line endings are CRLF by default. You can do this very easily if you are using Microsoft Visual Studio Code as your code editor. Just make sure you click on the line ending icon in the toolbar and choose LF.

Visual Studio Code Line Endings

Make sure all the .py and .sh files are executable

Here again something we have to consider developing on a Windows box and publishing to a Linux system like the Raspberry Pi. We need to make sure that GitHub is marking our file permissions according to the Linux System. There we need to flag our Python files and setup.sh (which is generating a virtual environment and installing our actions) as executable.

After some searching around I found the following line of bash command who does exactly this:

The best way to use this command is in Git Bash downloadable from Git for Windows.

find . -name '*.sh' | xargs git update-index --chmod=+x
find . -name '*.py' | xargs git update-index --chmod=+x

Install the App

Now everything is ready to deploy our new App to Snips on our Raspberry Pi. I will not go into details how this is done since there are good examples in the Snips documentation. Just a short remainder:

  • open your Snips console
  • create a new assistant (I usually create a new assistant with just the App I’m about to develop)
  • add your App to the assistant
  • let Snips train your assistant and then click on deploy assistant
  • copy the command into your terminal where you installed SAM and let it run

SNIPS Deploy Assistant

This will install the whole assistant. Which means all the necessary components like NLU and ASR and of course our action code. A screenshot of my deployment looks like the picture above.

Notice that you get asked to enter a value for the parameters who are in the secrets section of your config.ini file!

Another way to just install the actions on your Raspberry Pi and skip the NLU und ASR training is with the following SAM command:

sam install skills --git https://github.com/cellerich/snips-app-swiss-publictransport.git

This way you can make changes while debugging your actions and just install those changes.

A third way to make changes during debugging is to change the files directly on your Raspberry Pi. The location of the actions is in:

/var/lib/snips/skills

Be aware that your code is under source control on your Raspberry Pi as well. So either commit the changes from your Raspi or clear the whole directory and install the actions later again with SAM.

Test and Debug the App

The easiest way (I found) to debug an action is when you add Debug Logging code in your actions. Then set the log_level variable in your config.ini file to DEBUG and check the output from snips-skill-server. Before you can see anything, you have to stop snips-skill-server and start it again from the command line inside your Raspberry Pi command line:

sudo systemctl stop snips-skill-server.service
snips-skill-server -vvv

Depending on how many v you enter as a parameter the more verbose is the logging output of your snips-skill-server. Try it out with -vvv, -vv and -v.

remember to stop snips-skill-server again after installing the actions trough SAM. The install routine will start the snips-skill-server at the end.

Conclusions

It was interesting to create this first SNIPS App and I learned a lot in the process. I also found out during the journey that I could not use the Slot Type PUBLICTRANSPORT_TYPE since my API does not let me filter my results for a specific “Transport Type”, that is something I have to adjust in my App later on. Another learning was, that the intent TRAIN_SCHEDULE_TO hardly ever gets called. The training sentences are to close to the TRAIN_SCHEDULE_FROM_TO intent and usually SNIPS understands the later and just leaves the Slot FROM_STATION empty. Something I had to deal with in the action code. So this intent can be left out in the next version of the App.

Here are some recommendations I like to give to you when you are beginning with the creation of SNIPS App’s:

  • make yourself familiar with some LINUX Bash commands for file handling, copying, renaming and changing of permissions
  • get yourself a decent SSH client to log into your Raspberry Pi. Nowadays I would go with Microsoft Terminal
  • learn more about Python (in my opinion a language which will become handy in many other areas in the future)
  • read the relevant topics about intents, SNIPS console, SAM and Apps in the official SNIPS Documentation
  • join the SNIPS Forum and read the different topics and ask questions. People there seem to be very friendly with “Noobs” like I’m one and help out with knowledge pretty fast.

Hopefully I could inspire you somehow with my “criss cross – how to”. As I mentioned in the first post, I did write this blog series along while I was developing the App. Therefore it may not be that straight forward all the time, but it projects the twists and turns I had to do to get the App working. If you have any comments about the App, my Python coding style (I would love to improve that) or other things, please let me know in the comments below or in the SNIPS Forums.