Skip to content
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

Add ovos-core 0.0.8 compat. for CommonQuery skills #508

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading