-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fixes a bug where slot values vanish when using the augmented memoization policy. If in the past, the slot is set to a specific value, and then later the slot being set to the same value, no new SlotSet event is emitted. However, this leads to the augmented memoiziation policy wrongly assuming this slot to be unset, as the older, original SlotSet event was pruned already.
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import textwrap | ||
from unittest.mock import Mock | ||
|
||
from rasa.core.actions.action import ActionExtractSlots | ||
from rasa.core.channels import CollectingOutputChannel | ||
from rasa.shared.core.domain import Domain | ||
from rasa.shared.core.events import UserUttered, SlotSet | ||
from rasa.shared.core.trackers import DialogueStateTracker | ||
|
||
|
||
async def test_action_extract_slots_returns_slot_set_even_if_slot_value_is_unchanged(): | ||
event_with_slot_entity = UserUttered( | ||
text="I am a text", | ||
intent={"name": "intent_with_entity"}, | ||
entities=[{"entity": "entity", "value": "value"}], | ||
) | ||
|
||
domain = textwrap.dedent( | ||
""" | ||
intents: | ||
- intent_with_entity | ||
entities: | ||
- entity | ||
slots: | ||
entity: | ||
type: text | ||
mappings: | ||
- type: from_entity | ||
entity: entity | ||
""" | ||
) | ||
|
||
domain = Domain.from_yaml(domain) | ||
|
||
tracker = DialogueStateTracker.from_events( | ||
"some-sender", | ||
evts=[ | ||
event_with_slot_entity, | ||
], | ||
) | ||
|
||
tracker._set_slot("entity", "value") | ||
|
||
action = ActionExtractSlots(None) | ||
|
||
events = await action.run( | ||
output_channel=CollectingOutputChannel(), | ||
nlg=Mock(), | ||
tracker=tracker, | ||
domain=domain, | ||
) | ||
|
||
assert len(events) == 1 | ||
assert type(events[0]) == SlotSet | ||
assert events[0].key == "entity" | ||
assert events[0].value == "value" |