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

Extend FallbackSkill from ovos-workshop #50

Merged
merged 5 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
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: 14 additions & 17 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from neon_utils.skills.neon_fallback_skill import NeonFallbackSkill
from neon_utils.message_utils import neon_must_respond, request_for_neon
from ovos_workshop.decorators import fallback_handler
from ovos_workshop.skills.fallback import FallbackSkill
from neon_utils.message_utils import request_for_neon
from ovos_bus_client import Message
from ovos_utils import classproperty
from ovos_utils.log import LOG
from ovos_utils.process_utils import RuntimeRequirements


class UnknownSkill(NeonFallbackSkill):
def __init__(self, *args, **kwargs):
NeonFallbackSkill.__init__(self, *args, **kwargs)
self.register_fallback(self.handle_fallback, 100)
# Set of clients that always expect a response
self._transactional_clients = {"mq_api"}
class UnknownSkill(FallbackSkill):
# Set of clients that always expect a response
_transactional_clients = {"mq_api", "klat", "mobile"}

@classproperty
def runtime_requirements(self):
Expand All @@ -76,6 +74,7 @@ def _read_voc_lines(self, name) -> filter:
with open(self.find_resource(name + '.voc', 'vocab')) as f:
return filter(bool, map(str.strip, f.read().split('\n')))

@fallback_handler(priority=100)
def handle_fallback(self, message: Message):
LOG.info("Unknown Fallback Checking for Neon!!!")
utterance = message.data['utterance']
Expand All @@ -84,7 +83,6 @@ def handle_fallback(self, message: Message):
True)
# This checks if we're pretty sure this was a request intended for Neon
if not any((request_for_neon(message, "neon", self.voc_match, ww_state),
neon_must_respond(message),
client in self._transactional_clients)):
LOG.info("Ignoring streaming STT or public conversation input")
return True
Expand All @@ -103,15 +101,14 @@ def handle_fallback(self, message: Message):
# Show utterance that failed to match an intent
if self.settings.get('show_utterances'):
self.gui['utterance'] = utterance
self.gui.show_page("UnknownIntent.qml")
self.gui.show_page("UnknownIntent")

# Report an intent failure
self.bus.emit(Message("neon.metric", {"name": "failed-intent",
'utterance': utterance,
'client': client
}))

try:
# Report an intent failure
self.report_metric('failed-intent',
{'utterance': utterance,
'device': self.config_core.get("dev_type")})
except Exception as e:
LOG.exception(e)
LOG.debug(f"Checking if neon must respond: {message.data}")

# Determine what kind of question this is to reply appropriately
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
neon-utils~=1.5
ovos_utils~=0.0.28
ovos_utils~=0.0.28
ovos-workshop~=0.0.15
1 change: 1 addition & 0 deletions skill.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"requirements": {
"python": [
"neon-utils~=1.5",
"ovos-workshop~=0.0.15",
"ovos_utils~=0.0.28"
],
"system": {},
Expand Down
5 changes: 0 additions & 5 deletions test/test_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@


class TestSkill(SkillTestCase):
def test_00_skill_init(self):
from neon_utils.skills.neon_skill import NeonSkill
self.assertIsInstance(self.skill, NeonSkill)
self.assertIsInstance(self.skill, NeonFallbackSkill)

def test_read_voc_lines(self):
valid_vocab = ('question', 'who.is', 'why.is')
for v in valid_vocab:
Expand Down
Loading