-
Notifications
You must be signed in to change notification settings - Fork 17
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
optimize: dont load padacioso if not needed by default #629
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #629 +/- ##
==========================================
- Coverage 75.33% 72.39% -2.95%
==========================================
Files 15 15
Lines 3094 1583 -1511
==========================================
- Hits 2331 1146 -1185
+ Misses 763 437 -326
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
ovos_core/intent_services/__init__.py (3)
106-107
: Fix indentation in debug log message.The debug message indentation is inconsistent with Python's style guide (PEP 8).
- LOG.debug("Padacioso pipeline is disabled, only padatious is loaded. " - "set 'disable_padacioso': false in mycroft.conf if you want it to load alongside padatious") + LOG.debug("Padacioso pipeline is disabled, only padatious is loaded. " + "set 'disable_padacioso': false in mycroft.conf if you want it to load alongside padatious")
179-185
: Enhance warning message about performance impact.The warning about padacioso being "extremely slow" could be more specific to help users understand the performance implications.
- LOG.warning("padatious is not available! using padacioso in it's place, " - "intent matching will be extremely slow in comparison") + LOG.warning("padatious is not available! using padacioso as fallback. " + "Note: padacioso's intent matching can be significantly slower " + "due to its different matching algorithm")
202-215
: Consider simplifying the matcher dictionary updates.The current implementation has separate conditional blocks for padacioso and padatious updates. This could be simplified to reduce code duplication and improve maintainability.
- if self._padacioso_service is not None: - matchers.update({ - "padacioso_high": self._padacioso_service.match_high, - "padacioso_medium": self._padacioso_service.match_medium, - "padacioso_low": self._padacioso_service.match_low, - - }) - if self._padatious_service is not None: - matchers.update({ - "padatious_high": padatious_matcher.match_high, - "padatious_medium": padatious_matcher.match_medium, - "padatious_low": padatious_matcher.match_low, - - }) + # Add matchers for the active intent service (padatious or padacioso) + if padatious_matcher is not None: + service_name = "padatious" if self._padatious_service is not None else "padacioso" + matchers.update({ + f"{service_name}_high": padatious_matcher.match_high, + f"{service_name}_medium": padatious_matcher.match_medium, + f"{service_name}_low": padatious_matcher.match_low, + })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
ovos_core/intent_services/__init__.py
(4 hunks)
🔇 Additional comments (2)
ovos_core/intent_services/__init__.py (2)
19-21
: LGTM: Import changes are clean and follow conventions.
The imports are properly organized and the alias for PadaciosoPipeline as PadaciosoService improves code clarity.
100-104
: LGTM: Optimized padacioso loading logic.
The implementation correctly achieves the PR's goal by:
- Only loading padacioso by default when padatious is unavailable
- Allowing explicit control via the
disable_padacioso
config option
b2e1494
to
86d412f
Compare
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (5)
ovos_core/intent_services/__init__.py (5)
102-103
: Fix typos in commentsThere are typos in the comments at lines 102 and 103. Correct spelling improves code readability.
Apply this diff to correct the typos:
-# by default only load padacioso is padatious is not available +# By default, only load padacioso if padatious is not available -# save memory if padacioso isnt needed +# Save memory if padacioso isn't needed
108-109
: Update configuration file reference in log messageThe log message mentions
mycroft.conf
, which may not be the correct configuration file for this project.If the correct file is
ovos.conf
or another file, update the log message accordingly.
185-186
: Correct typo in log messageThere's a typo in the log message at line 185. "It's place" should be "its place".
Apply this diff to fix the typo:
LOG.warning("padatious is not available! using padacioso in it's place, " "intent matching will be extremely slow in comparison") +LOG.warning("padatious is not available! using padacioso in its place, " + "intent matching will be extremely slow in comparison")
204-210
: Remove unnecessary blank lines in matcher updatesThere are unnecessary blank lines at lines 209 and 210. Removing them improves code readability.
Apply this diff to clean up the code:
"padacioso_high": self._padacioso_service.match_high, "padacioso_medium": self._padacioso_service.match_medium, "padacioso_low": self._padacioso_service.match_low, - - })
211-217
: Ensure consistent matcher updates for Padatious and PadaciosoConsider aligning the structure of the matcher updates for
padatious
andpadacioso
services for consistency.This can enhance readability and maintainability. For example:
if self._padacioso_service is not None: matchers.update({ "padacioso_high": self._padacioso_service.match_high, "padacioso_medium": self._padacioso_service.match_medium, "padacioso_low": self._padacioso_service.match_low }) if self._padatious_service is not None: matchers.update({ "padatious_high": self._padatious_service.match_high, "padatious_medium": self._padatious_service.match_medium, "padatious_low": self._padatious_service.match_low })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
ovos_core/intent_services/__init__.py
(3 hunks)
🔇 Additional comments (1)
ovos_core/intent_services/__init__.py (1)
104-109
: 🛠️ Refactor suggestion
Simplify and clarify the logic for disabling Padacioso
The current logic for disabling Padacioso can be simplified for better readability and maintainability.
Consider refactoring the code as follows:
-disable_padacioso = self.config.get("disable_padacioso", self._padatious_service is not None)
+disable_padacioso = self.config.get("disable_padacioso", self._padatious_service is not None)
if not disable_padacioso:
self._padacioso_service = PadaciosoService(self.bus, self.config["padatious"])
-elif "disable_padacioso" not in self.config:
+else:
LOG.debug("Padacioso pipeline is disabled, only padatious is loaded. "
"Set 'disable_padacioso': false in the configuration if you want it to load alongside padatious")
This refactoring ensures that the default behavior is clear and the conditions are straightforward.
Likely invalid or redundant comment.
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (4)
ovos_core/intent_services/__init__.py (4)
102-103
: Correct typographical errors in commentsThe comments contain typographical errors that may lead to confusion. Please correct them for clarity.
Apply this diff to fix the comments:
-# by default only load padacioso is padatious is not available +# By default, only load padacioso if padatious is not available -# save memory if padacioso isnt needed +# Save memory if padacioso isn't needed
185-186
: Fix grammatical error in log messageThe log message contains a grammatical error. The possessive form "its" should be used instead of "it's".
Apply this diff to correct the log message:
-LOG.warning("padatious is not available! using padacioso in it's place, " +LOG.warning("padatious is not available! using padacioso in its place, "
181-187
: Improve clarity of the PadatiousMatcher substitution logicThe current logic for substituting
PadaciosoService
whenPadatiousService
is not available can be refactored for better readability.Consider restructuring the code as follows:
padatious_matcher = None if self._padatious_service is not None: padatious_matcher = self._padatious_service elif self._padacioso_service is not None: if any("padatious" in p for p in session.pipeline): LOG.warning("padatious is not available! using padacioso in its place, " "intent matching will be extremely slow in comparison") padatious_matcher = self._padacioso_serviceThis refactor makes the substitution logic more explicit and easier to follow.
498-499
: Apply consistent checks before shutting down servicesIn the
shutdown
method, you conditionally shut downself._adapt_service
andself._padacioso_service
based on their existence. For consistency and to prevent potentialAttributeError
s, apply the same checks to all services.Consider the following refactor:
-if self._padacioso_service: +if self._padacioso_service is not None: self._padacioso_service.shutdown() -if self._padatious_service: +if self._padatious_service is not None: self._padatious_service.shutdown() -if self._common_qa: +if self._common_qa is not None: self._common_qa.shutdown() -if self._converse: +if self._converse is not None: self._converse.shutdown() -if self._fallback: +if self._fallback is not None: self._fallback.shutdown() -if self._ocp: +if self._ocp is not None: self._ocp.shutdown()This ensures all services are checked for
None
before attempting to call theirshutdown
methods.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
ovos_core/intent_services/__init__.py
(4 hunks)
🔇 Additional comments (1)
ovos_core/intent_services/__init__.py (1)
104-109
: Verify the logic for disabling PadaciosoService
The condition used to set disable_padacioso
may not be immediately clear. Ensure that it aligns with the intended behavior of loading PadaciosoService
only when PadatiousService
is unavailable unless explicitly configured.
Here's the logic breakdown:
disable_padacioso
is obtained from the configuration with a default value ofself._padatious_service is not None
.- This means if
PadatiousService
is available,disable_padacioso
defaults toTrue
, disablingPadaciosoService
. - If
PadatiousService
is not available, it defaults toFalse
, enablingPadaciosoService
.
- This means if
- The subsequent check
if not disable_padacioso:
determines whether to instantiatePadaciosoService
.
Ensure this logic correctly reflects the desired default behavior and consider adding comments for clarity.
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
ovos_core/intent_services/__init__.py (2)
102-103
: Fix typos in comments for clarityThe comments in lines 102 and 103 contain typos that could cause confusion.
- Line 102: Replace "is" with "if" to read "by default only load padacioso if padatious is not available".
- Line 103: Add an apostrophe in "isn't" for correct contraction.
Apply this diff to correct the typos:
- # by default only load padacioso is padatious is not available + # by default only load padacioso if padatious is not available - # save memory if padacioso isnt needed + # save memory if padacioso isn't needed
104-109
: Enhance logging to inform users when 'PadaciosoService' is disabledCurrently, the log message about the
PadaciosoService
being disabled is only displayed if thedisable_padacioso
config option is not set. This may cause users to miss the information ifdisable_padacioso
is explicitly set toTrue
. Consider logging the message wheneverPadaciosoService
is not loaded, regardless of howdisable_padacioso
was set.Apply this diff to adjust the logging condition:
- elif "disable_padacioso" not in self.config: + else: LOG.debug("Padacioso pipeline is disabled, only padatious is loaded. " "set 'disable_padacioso': false in mycroft.conf if you want it to load alongside padatious")This change ensures that users are always informed when
PadaciosoService
is disabled, providing clearer insight into the system's configuration.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
ovos_core/intent_services/__init__.py
(4 hunks)
🔇 Additional comments (3)
ovos_core/intent_services/__init__.py (3)
181-190
: Ensure 'padatious_matcher' is properly initialized
The logic for initializing padatious_matcher
correctly handles different service availability scenarios:
- If
self._padatious_service
is available, it assigns it topadatious_matcher
. - If
self._padatious_service
is not available butself._padacioso_service
is, it assignsself._padacioso_service
topadatious_matcher
and logs a warning. - If neither service is available,
padatious_matcher
remainsNone
.
This approach prevents potential AttributeError
s when accessing matchers later in the code.
204-217
: Safely update matchers based on available services
The code appropriately checks for the existence of self._padacioso_service
and padatious_matcher
before adding their matchers to the matchers
dictionary. This prevents potential errors when the services are unavailable and ensures that only valid matchers are included.
498-499
: Conditional shutdown of 'PadaciosoService'
In the shutdown
method, the code correctly checks if self._padacioso_service
exists before calling its shutdown()
method. This prevents potential AttributeError
s if the service was never initialized.
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
ovos_core/intent_services/__init__.py (4)
102-103
: Fix typos in comments for clarityThere are minor typos in the comments that can be corrected for better readability.
Apply this diff to correct the typos:
- # by default only load padacioso is padatious is not available + # By default, only load Padacioso if Padatious is not available - # save memory if padacioso isnt needed + # Save memory if Padacioso isn't needed
104-109
: Simplify the conditional logic for better readabilityThe current conditional statements can be streamlined to improve code clarity.
Consider refactoring the logic as follows:
disable_padacioso = self.config.get("disable_padacioso", self._padatious_service is not None) if not disable_padacioso: self._padacioso_service = PadaciosoService(self.bus, self.config["padatious"]) - elif "disable_padacioso" not in self.config: + else: LOG.debug("Padacioso pipeline is disabled, only Padatious is loaded. " "Set 'disable_padacioso': false in mycroft.conf if you want it to load alongside Padatious")This change uses an
else
clause instead of checking"disable_padacioso" not in self.config
, making the logic clearer.
186-186
: Correct typo in logging messageIn the log message, "it's place" should be "its place".
Apply this diff to correct the typo:
- LOG.warning("padatious is not available! using padacioso in it's place, " + LOG.warning("Padatious is not available! Using Padacioso in its place, "
183-183
: Ensure accurate pipeline component checksThe condition
any("padatious" in p for p in session.pipeline)
might unintentionally match components that contain "padatious" as a substring.It's better to check for exact matches to avoid false positives.
- needs_pada = any("padatious" in p for p in session.pipeline) + needs_pada = any(p == "padatious_high" or p == "padatious_medium" or p == "padatious_low" for p in session.pipeline)Alternatively, if pipeline component names are standardized, consider using a more precise condition.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
ovos_core/intent_services/__init__.py
(4 hunks)
🔇 Additional comments (2)
ovos_core/intent_services/__init__.py (2)
215-220
: Verified safe addition of matchers when services are available
The code now correctly checks if padatious_matcher
is not None
before adding matchers, addressing the previous concern about potential AttributeError
.
501-502
: Safely shutting down Padacioso service
The inclusion of a check before shutting down self._padacioso_service
ensures that the shutdown method is only called if the service has been instantiated.
to account for optional padatious, padacioso and padatious are both loaded into memory to register intents
this PR makes padacioso only load if padatious is not available
side effects: if we want to use padacioso in the pipeline we need to set
"disable_padacioso": false
explicitly in config to have it load side by side with padatiousSummary by CodeRabbit
New Features
Bug Fixes