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

changed the generator to load full tracker including all sessions + added markers changelog #10170

Merged
merged 9 commits into from
Nov 11, 2021
4 changes: 4 additions & 0 deletions changelog/10170.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
A new experimental feature called `Markers` has been added.
`Markers` allow you to define points of interest in conversations as a set of conditions that need to be met.
A new command `rasa evaluate markers` allows you to apply these conditions to your existing tracker stores
and outputs the points at which the conditions were satisfied.
6 changes: 5 additions & 1 deletion rasa/core/evaluation/marker_tracker_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from rasa.core.tracker_store import TrackerStore
import rasa.shared.utils.io

STRATEGY_ALL = "all"
STRATEGY_FIRST_N = "first_n"
STRATEGY_SAMPLE = "sample"


def strategy_all(keys: List[Text], count: int) -> Iterable[Text]:
"""Selects all keys from the set of keys."""
Expand Down Expand Up @@ -96,4 +100,4 @@ def load(self) -> Iterator[Optional[DialogueStateTracker]]:

keys = self.strategy(stored_keys, self.count)
for sender in keys:
yield self.tracker_store.retrieve(sender)
yield self.tracker_store.retrieve_full_tracker(sender)
aeshky marked this conversation as resolved.
Show resolved Hide resolved
aeshky marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 28 additions & 4 deletions tests/core/evaluation/test_marker_tracker_loader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from rasa.shared.core.events import UserUttered
import pytest
import os
from rasa.shared.core.events import UserUttered, SessionStarted
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.core.domain import Domain
from rasa.shared.exceptions import RasaException
from rasa.core.evaluation.marker_tracker_loader import MarkerTrackerLoader
from rasa.core.tracker_store import InMemoryTrackerStore, TrackerStore
import pytest
from rasa.core.evaluation.marker_tracker_loader import MarkerTrackerLoader, STRATEGY_ALL
from rasa.core.tracker_store import InMemoryTrackerStore, TrackerStore, SQLTrackerStore


@pytest.fixture
Expand All @@ -20,6 +21,29 @@ def marker_trackerstore() -> TrackerStore:
return store


def test_load_sessions(tmp_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_load_sessions(tmp_path):
def test_load_sessions(tmp_path : Path):

"""Tests loading a tracker with multiple sessions."""
domain = Domain.empty()
store = SQLTrackerStore(domain, db=os.path.join(tmp_path, "temp.db"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, with paths, you can also do things like

Suggested change
store = SQLTrackerStore(domain, db=os.path.join(tmp_path, "temp.db"))
store = SQLTrackerStore(domain, db= tmp_path / "temp.db")

(https://docs.python.org/3/library/pathlib.html#basic-use)

tracker = DialogueStateTracker("test123", None)
tracker.update_with_events(
[
UserUttered("0"),
UserUttered("1"),
SessionStarted(),
UserUttered("2"),
UserUttered("3"),
],
domain,
)
store.save(tracker)

loader = MarkerTrackerLoader(store, STRATEGY_ALL)
result = list(loader.load())
assert len(result) == 1 # contains only one tracker
assert len(result[0].events) == len(tracker.events)


def test_load_sample(marker_trackerstore: TrackerStore):
"""Tests loading trackers using 'sample' strategy."""
loader = MarkerTrackerLoader(marker_trackerstore, "sample", 3)
Expand Down