Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"It's sunny in Berlin",
"What's the weather",
0.65432,
),
ResponseSelectionEvaluationResult(
"chitchat",
"My name is Mr.bot",
"My name is Mr.bot",
"What's your name?",
0.98765,
),
]
result = evaluate_response_selections(response_results, report_folder)
report = json.loads(rasa.utils.io.read_file(report_filename))
name_query_results = {
"precision": 1.0,
"recall": 1.0,
"f1-score": 1.0,
"support": 1,
}
prediction = {
"text": "What's your name?",
"intent_target": "chitchat",
"response_target": "My name is Mr.bot",
"response_predicted": "My name is Mr.bot",
"confidence": 0.98765,
}
def test_all_events_before_user_msg():
tracker_dump = "data/test_trackers/tracker_moodbot.json"
tracker_json = json.loads(rasa.utils.io.read_file(tracker_dump))
evts = tracker_json.get("events")
m = interactive.all_events_before_latest_user_msg(evts)
assert m is not None
assert m == evts[:4]
def test_read_json_dump(default_agent):
tracker_dump = "data/test_trackers/tracker_moodbot.json"
tracker_json = json.loads(rasa.utils.io.read_file(tracker_dump))
restored_tracker = restore.load_tracker_from_json(
tracker_dump, default_agent.domain
)
assert len(restored_tracker.events) == 7
assert restored_tracker.latest_action_name == "action_listen"
assert not restored_tracker.is_paused()
assert restored_tracker.sender_id == "mysender"
assert restored_tracker.events[-1].timestamp == 1517821726.211042
restored_state = restored_tracker.current_state(EventVerbosity.AFTER_RESTART)
assert restored_state == tracker_json
def test_all_events_before_user_msg():
tracker_dump = "data/test_trackers/tracker_moodbot.json"
tracker_json = json.loads(rasa.utils.io.read_file(tracker_dump))
evts = tracker_json.get("events")
m = interactive.all_events_before_latest_user_msg(evts)
assert m is not None
assert m == evts[:4]
def test_entity_evaluation_report(tmpdir_factory):
path = tmpdir_factory.mktemp("evaluation").strpath
report_folder = os.path.join(path, "reports")
mock_extractors = ["A", "B"]
report_filename_a = os.path.join(report_folder, "A_report.json")
report_filename_b = os.path.join(report_folder, "B_report.json")
utils.create_dir(report_folder)
result = evaluate_entities(
[EN_targets], [EN_predicted], [EN_tokens], mock_extractors, report_folder
)
report_a = json.loads(rasa.utils.io.read_file(report_filename_a))
report_b = json.loads(rasa.utils.io.read_file(report_filename_b))
assert len(report_a) == 8
assert report_a["datetime"]["support"] == 1.0
assert report_b["macro avg"]["recall"] == 0.2
assert result["A"]["accuracy"] == 0.75
@classmethod
def from_file(cls, path: Text) -> "Domain":
return cls.from_yaml(rasa.utils.io.read_file(path))
@classmethod
def load(cls, path: Text) -> "FallbackPolicy":
meta = {}
if os.path.exists(path):
meta_path = os.path.join(path, "fallback_policy.json")
if os.path.isfile(meta_path):
meta = json.loads(rasa.utils.io.read_file(meta_path))
return cls(**meta)
def from_file(cls, path: Text) -> "Domain":
return cls.from_yaml(rasa.utils.io.read_file(path))
def load_specification(cls, path: Text) -> Dict[Text, Any]:
"""Load a domains specification from a dumped model directory."""
metadata_path = os.path.join(path, "domain.json")
specification = json.loads(rasa.utils.io.read_file(metadata_path))
return specification
@classmethod
def load(cls, path: Text) -> "MappingPolicy":
"""Returns the class with the configured priority."""
meta = {}
if os.path.exists(path):
meta_path = os.path.join(path, "mapping_policy.json")
if os.path.isfile(meta_path):
meta = json.loads(rasa.utils.io.read_file(meta_path))
return cls(**meta)