I am attempting to write a custom Policy to emulate some old legacy business logic. I have spent hours reading the docs and examining the source, but I cannot get my policy to emit an utterance or any event. PolicyPrediction docs are very unclear about how to create Events, and the usage in TEDPolicy and MemoizationPolicy is pretty complicated.
Any help appreciated.
Here is my code. I would like it to say “Hello Purple Elephants!”. Instead it seems to add the utterance to the tracker history but never actually emits it to the user.
@DefaultV1Recipe.register(
[DefaultV1Recipe.ComponentType.POLICY_WITHOUT_END_TO_END_SUPPORT], is_trainable=False
)
class WhistlePolicy(Policy):
@staticmethod
def get_default_config() -> Dict[Text, Any]:
"""Returns the default config (see parent class for full docstring)."""
# please make sure to update the docs when changing a default parameter
return {
POLICY_PRIORITY: 10.0,
POLICY_MAX_HISTORY: 10,
}
def train(
self,
training_trackers: List[TrackerWithCachedStates],
domain: Domain,
**kwargs: Any,
) -> Resource:
# output_fingerprint must be unique to this instance.
return Resource(
'WhistlePolicy',
output_fingerprint='WhistlePolicyFingerprint',
)
def predict_action_probabilities(
self,
tracker: DialogueStateTracker,
domain: Domain,
rule_only_data: Optional[Dict[Text, Any]] = None,
**kwargs: Any,
) -> PolicyPrediction:
event = Event.from_parameters(BotUttered('Hello Purple Elephants!'))
return PolicyPrediction(
probabilities=[1.0],
policy_name=self.__class__.__name__,
policy_priority=self.priority,
events=[],
optional_events=[event],
is_end_to_end_prediction=False,
is_no_user_prediction=False,
diagnostic_data={},
action_metadata=None,
)