Skip to content

Commit

Permalink
1.2.0 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel authored Dec 27, 2023
2 parents 30748b2 + 0f6f198 commit fe0fba5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 74 deletions.
22 changes: 3 additions & 19 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
# Changelog

## [1.0.1a3](https://github.com/NeonGeckoCom/skill-fallback_unknown/tree/1.0.1a3) (2023-12-15)
## [1.1.1a1](https://github.com/NeonGeckoCom/skill-fallback_unknown/tree/1.1.1a1) (2023-12-20)

[Full Changelog](https://github.com/NeonGeckoCom/skill-fallback_unknown/compare/1.0.1a2...1.0.1a3)
[Full Changelog](https://github.com/NeonGeckoCom/skill-fallback_unknown/compare/1.1.0...1.1.1a1)

**Merged pull requests:**

- Testing shared resource test case [\#46](https://github.com/NeonGeckoCom/skill-fallback_unknown/pull/46) ([NeonDaniel](https://github.com/NeonDaniel))

## [1.0.1a2](https://github.com/NeonGeckoCom/skill-fallback_unknown/tree/1.0.1a2) (2023-12-13)

[Full Changelog](https://github.com/NeonGeckoCom/skill-fallback_unknown/compare/1.0.1a1...1.0.1a2)

**Merged pull requests:**

- Remove deprecated mobile request handling causing empty responses [\#44](https://github.com/NeonGeckoCom/skill-fallback_unknown/pull/44) ([NeonDaniel](https://github.com/NeonDaniel))

## [1.0.1a1](https://github.com/NeonGeckoCom/skill-fallback_unknown/tree/1.0.1a1) (2023-11-22)

[Full Changelog](https://github.com/NeonGeckoCom/skill-fallback_unknown/compare/1.0.0...1.0.1a1)

**Merged pull requests:**

- Added Ukrainian [\#43](https://github.com/NeonGeckoCom/skill-fallback_unknown/pull/43) ([NeonDmitry](https://github.com/NeonDmitry))
- Update init and Unknown response handling [\#48](https://github.com/NeonGeckoCom/skill-fallback_unknown/pull/48) ([NeonDaniel](https://github.com/NeonDaniel))



Expand Down
23 changes: 15 additions & 8 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
# 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_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"}

@classproperty
def runtime_requirements(self):
return RuntimeRequirements(network_before_load=False,
Expand All @@ -60,10 +67,6 @@ def runtime_requirements(self):
no_network_fallback=True,
no_gui_fallback=True)

# TODO: Move to `__init__` after ovos-workshop stable release
def initialize(self):
self.register_fallback(self.handle_fallback, 100)

def _read_voc_lines(self, name) -> filter:
"""
Return parsed lines for the specified voc resource
Expand All @@ -76,10 +79,13 @@ def _read_voc_lines(self, name) -> filter:
def handle_fallback(self, message: Message):
LOG.info("Unknown Fallback Checking for Neon!!!")
utterance = message.data['utterance']

client = message.context.get('client')
ww_state = self.config_core.get("listener", {}).get("wake_word_enabled",
True)
# This checks if we're pretty sure this was a request intended for Neon
if not any((self.neon_in_request(message),
self.neon_must_respond(message))):
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 @@ -90,7 +96,8 @@ def handle_fallback(self, message: Message):
'color': 'theme'}))

# Ignore likely accidental activations
if len(utterance.split()) < 2:
if len(utterance.split()) < 2 and \
client not in self._transactional_clients:
LOG.info(f"Ignoring 1-word input: {utterance}")
return True
# Show utterance that failed to match an intent
Expand Down
64 changes: 18 additions & 46 deletions test/test_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,21 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import shutil
import unittest
import os
import sys
import pytest

from os import mkdir
from os.path import dirname, join, exists
from os.path import dirname
from mock import Mock
from mycroft_bus_client import Message
from ovos_utils.messagebus import FakeBus
from neon_utils.skills import NeonFallbackSkill

from neon_minerva.tests.skill_unit_test_base import SkillTestCase

class TestSkill(unittest.TestCase):
os.environ.setdefault("TEST_SKILL_ENTRYPOINT", dirname(dirname(__file__)))

@classmethod
def setUpClass(cls) -> None:
from ovos_workshop.skill_launcher import SkillLoader

bus = FakeBus()
bus.run_in_thread()
skill_loader = SkillLoader(bus, dirname(dirname(__file__)))
skill_loader.load()
cls.skill = skill_loader.instance

# Define a directory to use for testing
cls.test_fs = join(dirname(__file__), "skill_fs")
if not exists(cls.test_fs):
mkdir(cls.test_fs)

# Override the fs paths to use the test directory
cls.skill.settings_write_path = cls.test_fs
cls.skill.file_system.path = cls.test_fs

# Override speak and speak_dialog to test passed arguments
cls.skill.speak = Mock()
cls.skill.speak_dialog = Mock()

def setUp(self):
self.skill.speak.reset_mock()
self.skill.speak_dialog.reset_mock()

def tearDown(self) -> None:
self.skill.bus.remove_all_listeners("neon.wake_words_state")

@classmethod
def tearDownClass(cls) -> None:
shutil.rmtree(cls.test_fs)

class TestSkill(SkillTestCase):
def test_00_skill_init(self):
from neon_utils.skills.neon_skill import NeonSkill
self.assertIsInstance(self.skill, NeonSkill)
Expand All @@ -89,7 +56,7 @@ def test_read_voc_lines(self):
self.assertIsNotNone(line)

def test_handle_fallback(self):
def neon_in_request(msg: Message):
def neon_in_request(msg: Message, *args, **kwargs):
if msg.data.get("neon_in_request"):
return True
return False
Expand All @@ -99,12 +66,9 @@ def neon_must_respond(msg: Message):
return True
return False

def check_for_signal(*args, **kwargs):
return False
sys.modules[self.skill.__module__].neon_must_respond = neon_must_respond
sys.modules[self.skill.__module__].request_for_neon = neon_in_request

self.skill.neon_in_request = neon_in_request
self.skill.neon_must_respond = neon_must_respond
self.skill.check_for_signal = check_for_signal
self.skill.report_metric = Mock()

message_not_for_neon = Message("test",
Expand All @@ -122,7 +86,9 @@ def check_for_signal(*args, **kwargs):
"utterance": "why is rain"})
message_unknown = Message("test", {"neon_in_request": True,
"utterance": "is it raining"})

message_transact_client = Message("test", {"neon_in_request": True,
"utterance": "short"},
{"client": "mq_api"})
self.assertTrue(self.skill.handle_fallback(message_not_for_neon))
self.skill.speak_dialog.assert_not_called()
self.assertTrue(self.skill.handle_fallback(message_too_short))
Expand Down Expand Up @@ -155,6 +121,12 @@ def check_for_signal(*args, **kwargs):
self.assertEqual(args[0][0], "unknown")
self.skill.speak_dialog.reset_mock()

self.assertTrue(self.skill.handle_fallback(message_transact_client))
self.skill.speak_dialog.assert_called_once()
args = self.skill.speak_dialog.call_args
self.assertEqual(args[0][0], "unknown")
self.skill.speak_dialog.reset_mock()


if __name__ == '__main__':
pytest.main()
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__version__ = "1.1.0"
__version__ = "1.2.0"

0 comments on commit fe0fba5

Please sign in to comment.