Skip to content

Commit

Permalink
Add ovos-core 0.0.8 compat. for CommonQuery skills (#508)
Browse files Browse the repository at this point in the history
* Add forwards-compat with ovos-core 0.0.8 CommonQuery
Mark CommonQuerySkill as deprecated

* Add logging to troubleshoot missing responses

* Cleanup logging

---------

Co-authored-by: Daniel McKnight <[email protected]>
  • Loading branch information
NeonDaniel and NeonDaniel authored Apr 4, 2024
1 parent 4003b27 commit c5a6764
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions neon_utils/skills/common_query_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
from ovos_workshop.decorators.layers import IntentLayers
from ovos_workshop.skills.common_query_skill import CQSMatchLevel, CQSVisualMatchLevel
from ovos_workshop.skills.common_query_skill import CommonQuerySkill as _CQS
from ovos_workshop.decorators.compat import backwards_compat
from ovos_utils.file_utils import resolve_resource_file
from ovos_utils.log import log_deprecation
from ovos_utils.log import log_deprecation, LOG
from neon_utils.skills.neon_skill import NeonSkill


Expand Down Expand Up @@ -76,6 +77,9 @@ class CommonQuerySkill(NeonSkill, _CQS):
answers from several skills presenting the best one available.
"""
def __init__(self, *args, **kwargs):
log_deprecation("This base class is deprecated. Implement "
"`ovos_workshop.skills.common_query_skill."
"CommonQuerySkill`", "2.0.0")
# these should probably be configurable
self.level_confidence = {
CQSMatchLevel.EXACT: 0.9,
Expand Down Expand Up @@ -130,7 +134,7 @@ def __calc_confidence(self, match, phrase, level):
else:
return 0.0 # should never happen

def __handle_query_action(self, message):
def __handle_query_classic(self, message):
"""Message handler for question:action.
Extracts phrase and data from message forward this to the skills
Expand All @@ -139,13 +143,36 @@ def __handle_query_action(self, message):
if message.data["skill_id"] != self.skill_id:
# Not for this skill!
return
LOG.debug(f"handling for ovos-core 0.0.7")
phrase = message.data["phrase"]
data = message.data.get("callback_data")
# Invoke derived class to provide playback data
self.CQS_action(phrase, data)
self.bus.emit(message.forward("mycroft.skill.handler.complete",
{"handler": "common_query"}))

@backwards_compat(classic_core=__handle_query_classic,
pre_008=__handle_query_classic)
def __handle_query_action(self, message):
"""
If this skill's response was spoken to the user, this method is called.
Phrase and callback data from `CQS_match_query_phrase` will be passed
to the `CQS_action` method.
@param message: `question:action` message
"""
if message.data["skill_id"] != self.skill_id:
# Not for this skill!
return
LOG.debug(f"handling for ovos-core 0.0.8")
phrase = message.data["phrase"]
data = message.data.get("callback_data") or {}
if data.get("answer"):
self.speak(data["answer"])
# Invoke derived class to provide playback data
self.CQS_action(phrase, data)
self.bus.emit(message.forward("mycroft.skill.handler.complete",
{"handler": "common_query"}))

def __handle_question_query(self, message):
# Override ovos-workshop implementation that doesn't pass `message`
search_phrase = message.data["phrase"]
Expand Down

0 comments on commit c5a6764

Please sign in to comment.