Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make action metadata available in tracker in 2.8.x #10458

Merged
merged 6 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/10458.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make `action_metadata` json serializable and make it available on the tracker. This is a backport of a fix in 3.0.0.
1 change: 1 addition & 0 deletions rasa/core/policies/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ def _pick_best_policy(
is_no_user_prediction=best_prediction.is_no_user_prediction,
diagnostic_data=best_prediction.diagnostic_data,
hide_rule_turn=best_prediction.hide_rule_turn,
action_metadata=best_prediction.action_metadata
)

def _best_policy_prediction(
Expand Down
6 changes: 3 additions & 3 deletions rasa/core/policies/unexpected_intent_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,11 @@ def _collect_action_metadata(
def _compile_metadata_for_label(
label_name: Text, similarity_score: float, threshold: Optional[float],
) -> "RankingCandidateMetadata":
severity = threshold - similarity_score if threshold else None
severity = float(threshold - similarity_score) if threshold else None
return {
NAME: label_name,
SCORE_KEY: similarity_score,
THRESHOLD_KEY: threshold,
SCORE_KEY: float(similarity_score),
THRESHOLD_KEY: float(threshold) if threshold else None,
SEVERITY_KEY: severity,
}

Expand Down
9 changes: 6 additions & 3 deletions tests/core/policies/test_unexpected_intent_policy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from pathlib import Path
from typing import Optional, List, Dict, Text, Type
import tensorflow as tf
Expand Down Expand Up @@ -489,9 +490,9 @@ def test_action_unlikely_intent_prediction(
self,
trained_policy: UnexpecTEDIntentPolicy,
default_domain: Domain,
predicted_similarity,
threshold_value,
is_unlikely,
predicted_similarity: float,
threshold_value: float,
is_unlikely: bool,
monkeypatch: MonkeyPatch,
tmp_path: Path,
):
Expand Down Expand Up @@ -538,6 +539,8 @@ def test_action_unlikely_intent_prediction(
# of the metadata is tested separately and
# not as part of this test.
assert prediction.action_metadata is not None
# Assert metadata is serializable
assert json.dumps(prediction.action_metadata)

@pytest.mark.parametrize(
"tracker_events, should_skip",
Expand Down