-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
warn for invalid keys for components #7134
Changes from 4 commits
238bfd4
ba56f66
30da34a
9719f0f
18e8778
7d9eba3
949bd8d
f0a1c00
8bd0973
e47bc1b
7f94c3e
9792ce2
1e92f01
44a6093
52d2864
741bae2
abea5aa
3c0db65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added warning for when an option is provided for a component that is not listed as a key in the defaults for that component. | ||
indam23 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,34 @@ def validate_requirements(component_names: List[Optional[Text]]) -> None: | |
) | ||
|
||
|
||
def validate_component_keys(pipeline: List["Component"]) -> None: | ||
indam23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Validates that all keys for a component are valid. | ||
|
||
Raises: | ||
InvalidConfigError: If any component has a key specified that is not used | ||
by the component class, it is likely a mistake in the pipeline | ||
|
||
Args: | ||
pipeline: The list of components in the piopeline | ||
""" | ||
from rasa.nlu import registry | ||
|
||
for component in pipeline: | ||
component_name = component.get("name") | ||
component_class = registry.get_component_class(component_name) | ||
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. Note that this may raise an exception. Maybe it would be better to run the validation within 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 even better within 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. that would also avoid having to do the check in two locations? 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. mm I tried moving it into Re. putting it in 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. it would have the advantage that you don't have to load the components yourself in 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 moved it - does that work? |
||
allowed_keys = set(component_class.defaults.keys()) | ||
provided_keys = set(component.keys()) | ||
provided_keys.remove("name") | ||
listseperator = "\n- " | ||
indam23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for key in provided_keys: | ||
if key not in allowed_keys: | ||
rasa.shared.utils.io.raise_warning( | ||
f"You have provided an invalid key `{key}` for component `{component_name}` in your pipeline. " | ||
f"Valid options for `{component_name}` are:\n- " | ||
f"{listseperator.join(allowed_keys)}" | ||
indam23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
|
||
def validate_empty_pipeline(pipeline: List["Component"]) -> None: | ||
"""Ensures the pipeline is not empty. | ||
|
||
|
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.
can we add the link to the documentation for
Component
s please?