I do most of my development in IntelliJ. It allows you to run python code in it’s debugger which is very useful because you can insert breakpoints and look at variables at that point in the code.
Since I have to use Rasa’s entry point from the command line: ($rasa shell) and run custom actions as a server ($rasa run actions). I do not see any obvious way in which I can make use of my debugger, either to debug the actions.py file or to observe the inner workings of Rasa itself.
You can configure your IDE debugger by running rasa as a module rather than script. Create a new debug configuration and supply the module you want to run in interpreter options. For example, to run the debugger on rasa init, you’d have to put
It runs and hits breakpoints within rasa’s code but I cannot navigate any buttons in the Two Stage Fallback for example. Furthermore, I cannot stop at breakpoints within the actions.py custom actions file. Obviously that is because it is run as a web hosted service via:
rasa run actions
So how could one accomplish that as well? Can “rasa run actions” be run as a module? When I run -help for that command I don’t see an argument to specify where the actions.py file is located. In any case, it seems like since that command runs actions.py as a web hosted service (even locally) and that would not allow me to stop at breakpoints within IntelliJ for the actions.py file.
I find it easiest to use this little startup script. I tested it with the Wing IDE, but it should work for any python debugger.
file: run_action_server_with_IDE.py
"""This script allows use of an IDE (Wing, Pycharm, ...) to debug custom actions:
(-) Place this script in same location as your actions.py
(-) Open & run it from within your IDE
(-) Now you can put breakpoints in your actions.py, but also explore the internals of the
rasa_sdk action server itself.
"""
import os
import sys
# insert path of this script in syspath so actions.py will be found
sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)))
#
# This is exactly like issuing the command:
# $ rasa run actions
#
sys.argv.append('run')
sys.argv.append('actions')
from rasa.__main__ import main
main()
These responses are very useful if you want to run the rasa action server in an IDE such as IntelliJ or Pycharm. Just to add on to this, if you want to run the rasa shell, you have to create another (similar) custom Run/Debug configuration where you:
provide the rasa executable as the “Script path”
provide corresponding model/endpoints/etc arguments in “Parameters”.
check the box which says “Emulate terminal in output console” under “Execution”
The first two steps are similar to what’s required for running the action server. The last step is important, otherwise you’ll get
Warning: Output is not to a terminal (fd=1).
Warning: Input is not to a terminal (fd=0).