-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
markers / validation #10012
markers / validation #10012
Changes from 6 commits
3404d26
2c31a5e
41a8ad4
95f4c83
a98e985
4231a41
3e3ce24
ea3b0b3
f33b8c4
9a7ef5e
32e3a4f
663d651
c3d972e
730689a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
from rasa.shared.core.domain import Domain | ||
from typing import Optional, Text, List | ||
from rasa.core.evaluation.marker_base import ( | ||
OperatorMarker, | ||
ConditionMarker, | ||
MarkerRegistry, | ||
) | ||
from rasa.shared.core.events import ActionExecuted, SlotSet, UserUttered, Event | ||
import rasa.shared.utils.io | ||
|
||
|
||
@MarkerRegistry.configurable_marker | ||
|
@@ -147,6 +149,21 @@ def negated_tag() -> Optional[Text]: | |
"""Returns the tag to be used in a config file for the negated version.""" | ||
return "action_not_executed" | ||
|
||
def validate_against_domain(self, domain: Domain) -> bool: | ||
"""Checks that this marker (and its children) refer to entries in the domain. | ||
|
||
Args: | ||
domain: The domain to check against | ||
""" | ||
valid = self.text in domain.action_names_or_texts | ||
|
||
if not valid: | ||
rasa.shared.utils.io.raise_warning( | ||
f"Referenced action '{self.text}' does not exist in the domain" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The extraction process isn't managed here - this goes over each marker and decides if they are valid, and if not emits a message, and then passes back True/False if it's valid or not. In the CLI we catch that boolean and error and exit based on it, but in these I wanted a way to collect all of the issues without stopping first, and then stop later (since reporting one at a time would be frustrating for users). The reason it's a warning is mostly because that was my first pass on it. Ideally it would go out as an error without terminating (and then get caught in the CLI to wrap it up and actually terminate) but we don't have a helper function for that so it's a little more involved - definitely something I want to fix before this merges. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CLI also terminates before the extraction process begins. It loads the marker definitions and the domain, does the validation first, and terminates if issues are found. It will only establish a connection to the tracker store (and by extension perform extraction) if there are no issues There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or in short: #10012 (comment) :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looked at how DialogueStateTracker manages this and have replicated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that it's consistent but that approach is also a bit confusing, isn't it? I would've expected a "raise..." if there's a logger error (and usually, I would not explicitly log the error but just have a decorator to pass on the error message) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... on the other hand, getting an error as a result of "only warnings" is also a bit unexpected maybe 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I figured it was consistent from the perspective of the user, but it might be worth re-evaluating how we do error management across the codebase at some point |
||
|
||
return valid | ||
|
||
def _non_negated_version_applies_at(self, event: Event) -> bool: | ||
return isinstance(event, ActionExecuted) and event.action_name == self.text | ||
|
||
|
@@ -170,6 +187,21 @@ def negated_tag() -> Optional[Text]: | |
"""Returns the tag to be used in a config file for the negated version.""" | ||
return "intent_not_detected" | ||
|
||
def validate_against_domain(self, domain: Domain) -> bool: | ||
"""Checks that this marker (and its children) refer to entries in the domain. | ||
|
||
Args: | ||
domain: The domain to check against | ||
""" | ||
valid = self.text in domain.intent_properties | ||
|
||
if not valid: | ||
rasa.shared.utils.io.raise_warning( | ||
f"Referenced intent '{self.text}' does not exist in the domain" | ||
) | ||
|
||
return valid | ||
|
||
def _non_negated_version_applies_at(self, event: Event) -> bool: | ||
return isinstance(event, UserUttered) and self.text in [ | ||
event.intent_name, | ||
|
@@ -194,6 +226,21 @@ def negated_tag() -> Optional[Text]: | |
"""Returns the tag to be used in a config file for the negated version.""" | ||
return "slot_is_not_set" | ||
|
||
def validate_against_domain(self, domain: Domain) -> bool: | ||
"""Checks that this marker (and its children) refer to entries in the domain. | ||
|
||
Args: | ||
domain: The domain to check against | ||
""" | ||
valid = any(self.text == slot.name for slot in domain.slots) | ||
|
||
if not valid: | ||
rasa.shared.utils.io.raise_warning( | ||
f"Referenced slot '{self.text}' does not exist in the domain" | ||
) | ||
|
||
return valid | ||
|
||
def _non_negated_version_applies_at(self, event: Event) -> bool: | ||
if isinstance(event, SlotSet) and event.key == self.text: | ||
# slot is set if and only if it's value is not `None` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice idea to just "bubble up" the warnings and then decide to break it here to gather all warnings first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to do it more like a compiler where you can track line number and also collect warnings a bit more elegantly, but it seemed like adding that would involve a lot of complicated stuff around adding information about where markers were parsed from to the markers and I didn't want to do too much in the time we have left