i am trying to create a custom policy “MyPolicy” in botfront, which would just return a value.My main intention is to see whether the custom policy is getting registered in rasa or not.
below is my policy code and i have placed that in my botfront/rasa folder:
from rasa_sdk import Action, Tracker
#from rasa_sdk.events import SlotSet
from rasa_sdk.events import SessionStarted, ActionExecuted
import logging
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import UserUtteranceReverted, ActionReverted
from rasa_sdk.events import SlotSet
from rasa_sdk.events import AllSlotsReset
from rasa_sdk.events import UserUtteranceReverted, ActionReverted, FollowupAction
from typing import List, Dict, Text, Optional, Any, Union, Tuple
import rasa.shared.utils.common
import rasa.shared.utils.io
from rasa.core.policies.policy import Policy, PolicyPrediction
class MyPolicy(Policy):
def __init__(
self,
lookup: Optional[Dict] = None,
**kwargs: Any,
) -> None:
# max history is set to 2 in order to capture
# previous meaningful action before action listen
super().__init__(
lookup=lookup,
**kwargs,
)
print("in policy*****************************************************************")
def predict_action_probabilities(self, tracker, domain):
if tracker.get_slot("version") == "15.9.0":
return confidence_scores_for("action_hi", 1.0, domain)
else:
return "hiiiiii"
def _metadata(self) -> Dict[Text, Any]:
return {"lookup": self.lookup}
In my policies pipeline i have the below code:
policies:
- name: TEDPolicy
epochs: 50
max_history: 5
batch_size:
- name: RulePolicy
- name: AugmentedMemoizationPolicy
- name: MyPolicy
But it is throwing the below error:
2021-03-12 04:46:23 WARNING rasa.utils.common - Failed to write global config. Error: [Errno 13] Permission denied: '/.config'. Skipping.
2021-03-12 04:46:23 ERROR rasa.server - Traceback (most recent call last):
File "/opt/venv/lib/python3.7/site-packages/rasa/core/policies/ensemble.py", line 430, in from_dict
constr_func = registry.policy_from_module_path(policy_name)
File "/opt/venv/lib/python3.7/site-packages/rasa/core/registry.py", line 28, in policy_from_module_path
module_path, lookup_path="rasa.core.policies.registry"
File "/opt/venv/lib/python3.7/site-packages/rasa/shared/utils/common.py", line 31, in class_from_module_path
return getattr(m, module_path)
AttributeError: module 'rasa.core.policies.registry' has no attribute 'MyPolicy'
``
During handling of the above exception, another exception occurred:
``
Traceback (most recent call last):
File "/opt/venv/lib/python3.7/site-packages/rasa/server.py", line 1021, in train
training_result = await train_async(**training_payload)
File "/opt/venv/lib/python3.7/site-packages/rasa/train.py", line 178, in train_async
finetuning_epoch_fraction=finetuning_epoch_fraction,
File "/opt/venv/lib/python3.7/site-packages/rasa/train.py", line 368, in _train_async_internal
finetuning_epoch_fraction=finetuning_epoch_fraction,
File "/opt/venv/lib/python3.7/site-packages/rasa/train.py", line 431, in _do_training
finetuning_epoch_fraction=finetuning_epoch_fraction,
File "/opt/venv/lib/python3.7/site-packages/rasa/train.py", line 626, in _train_core_with_validated_data
model_to_finetune=model_to_finetune,
File "/opt/venv/lib/python3.7/site-packages/rasa/core/train.py", line 45, in train
policies = config.load(policy_config)
File "/opt/venv/lib/python3.7/site-packages/rasa/core/config.py", line 56, in load
return PolicyEnsemble.from_dict(config_data)
File "/opt/venv/lib/python3.7/site-packages/rasa/core/policies/ensemble.py", line 438, in from_dict
f"Module for policy '{policy_name}' could not "
rasa.core.policies.ensemble.InvalidPolicyConfig: Module for policy 'MyPolicy' could not be loaded. Please make sure the name is a valid policy.
``
2021-03-12 04:46:23 ERROR rasa.server - An unexpected error occurred during training. Error: Module for policy 'MyPolicy' could not be loaded. Please make sure the name is a valid policy.
@akelad Any help in this regard would be welcomed