Deploy actions server with multiple custom actions file

I am going to deploy my actions server according to this document.

It states that “The rasa/rasa-sdk image will automatically look for the actions in actions/actions.py .” However, I have multiple actions python scripts which are put in the same folder named “actions” and no one named “actions.py”. What can I do for this situation?

Thank you.

Make the actions folder a package. Just put an empty python file of the name __init__.py inside the actions folder.

I just did this, thank you for posting how :slight_smile:

An IMPORTANT thing to note is that you have to include all of your import, and from statements in all of your .py files in the directory.

as an example, I had to edit all 16 of my action files and add this to the top of each one

import logging
from typing import Any, Text, Dict, List, Union, Optional
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormAction
from rasa_sdk.events import SlotSet, AllSlotsReset, Restarted, UserUtteranceReverted, ConversationPaused

logger = logging.getLogger(__name__)

Works like a charm now!

2 Likes

Hi @jonathanpwheat,

Can you please post a sample on how to did use multiple actions file

thank you

EDIT: I just published an article on how to do this

Sure thing.

Couple of basic instructions first so it all makes sense. The first thing to do is create an actions folder off of your project root

Then create a file in that actions folder with the name __init.py__ (that’s 2 underscores before and after) This tells the system this directory is a “package” and everything in here gets loaded.

Then move your actions.py file into your new actions folder

Now you can split up your actions.py file up.
To do this

  • Create a new file - say action_file_1.py (the filename is arbitrary, name it whatever makes sense to you).
  • Copy all of your import and from statements from the main actions.py file and paste them into your new file.
  • Cut / paste however many classes you want to move from your main actions.py file to your new one.
  • Save the file
  • repeat as necessary

I’m working on an in-depth article explaining this and how I organized mine, etc, but that’s the general idea.

Here’s a screenshot of my actions folder:

image

And here’s an example of the top of one of these new action files with my import and from statements and the beginning of the Class I moved here.

The great thing is that you don’t need to change anything related to launching your action server, it’s the same rasa run actions as before.

3 Likes

thank you

Hey @jonathanpwheat!

I have defined global variables, functions, and classes in actions.py. Will I need to define them in all files if I split actions?

Or can I dump them all in a file, and then import that file from each file?

Update: Tried it, it works. I need to import the file with the global stuff.

1 Like

Sorry, I’ve been traveling and haven’t looked at the forum recently - I’m glad you were able to get it working!!

1 Like

No prob! Thank you for the awesome articles :slight_smile:

1 Like