Rasa_core_sdk using multiple files including actions located in a different path then the current work_dir

(Moritz Schweppenhäuser) #1

Hey, I was just in the process of updating to rasa_core 0.11.2 and ran into a probelm using rasa_core_sdk.
So my setup looks something like this:

project_dir/
    -chatbot/
        -actions/
            -action_file_01.py
            -action_file_02.py
            -action_file_03.py

I was now trying to run the sdk server using:

python -m rasa_core_sdk.endpoint --actions chatbot/actions/action_file_01

and it looks like rasa can’t find the file:

ModuleNotFoundError: No module named 'chatbot/actions/action_file_01'

Am I doing something wrong and also is there a way to pass all three action_files to the server?


PS: I found a workaround, I don’t think is ideal. I created an actions.py-file inside the project_dir where I just import all my action_files. I then start the sdk-server using:

python -m rasa_core_sdk.endpoint --actions actions

which appears to be working

1 Like
(Akela Drissner) #2

@tmbo can you load in a folder too?

(Tom Bocklisch) #3

The --actions is not file based but module based.

You don’t necessarily need to create a module that imports all the actions, but you need to make sure that the actions are all part of one module, e.g.

project_dir/
    -chatbot/
        -__init__.py
        -actions/
            -__init__.py
            -action_file_01.py
            -action_file_02.py
            -action_file_03.py

mind the additional __init__.py's to make the folders proper modules. After that you can specify any module and the sdk will recursivly try to find all the actions:

python -m rasa_core_sdk.endpoint --actions chatbot.actions

2 Likes
(Moritz Schweppenhäuser) #4

Thanks for clearing that up! :slight_smile:

(Aman Garcha) #5

if i have multiple actions, should i make different actions file or in one actions.py i can create different Class of different actions?

(Moritz Schweppenhäuser) #6

It’s mostly up to you and if you only have a couple of actions there’s nothing wrong with keeping them in one file. For my specific use case it made sense to split my actions in different files, because I dealt with two different databases so I kept it organized that way.

(Aman Garcha) #7

It’s throwing me error , can you please help. I have written around 18 different custom actions in one actions.py file and i am returning different values but with same keyword in each class.

Its throwing me error that “UnboundLocalError: local variable ‘response’ referenced before assignment

only the first two classes at top are getting executed and even when I changed the sequence of those two classes only those two are getting executed and other classes are not getting executed.

    class AdmissionMcs(Action):
	def name(self):
		return 'admission_mcs'
	def run(self,dispatcher,tracker,domain):
		streams=tracker.get_slot('stream')
		if 'streams' == 'msc comp sci' or 'mcs':
			response=""" The admission for MCS is given on basis of 50% marks of bcs and 50% marks of entrance"""
		dispatcher.utter_message(response)
		return [SlotSet('stream',streams)]

class AdmissionBcs(Action):
	def name(self):
		return 'admission_bcs'
	def run(self,dispatcher,tracker,domain):
		streams=tracker.get_slot('stream')
		if 'streams' == 'bcs' or 'bsc comp sci':
			response=""" The admission for BCS is given on basis of entrance exam conducted by college"""
		dispatcher.utter_message(response)
		return [SlotSet('stream',streams)]

class AdmissionBba(Action):
	def name(self):
		return 'admission_bba'
	def run(self,dispatcher,tracker,domain):
		streams=tracker.get_slot('stream')
		if 'streams' == 'bba':
			response=""" The admission for BBA is given through merit list on basis of 12th Marks """
		dispatcher.utter_message(response)
		return [SlotSet('stream',streams)]

class AdmissionMba(Action):
	def name(self):
		return 'admission_mba'
	def run(self,dispatcher,tracker,domain):
		streams=tracker.get_slot('stream')
		if 'streams' == 'mba':
			response=""" The admission for MBA is given through marks scored in CAT """
		dispatcher.utter_message(response)
		return [SlotSet('stream',streams)]

The class AdmissionMcs and AdmissionBcs are executing even when i have changed the sequence of it, And when I try to access other classes its throwing me error :Local variable refereed before assignment.

Should i make separate action files or is there solution for this?

(Aman Garcha) #8

hey it is solved when i had put else statement and now its working but i dont get the logic behind putting the else statement.