From 0f1b010707a1b639d857ac69f659bfc7cc8ff299 Mon Sep 17 00:00:00 2001 From: miro Date: Wed, 16 Oct 2024 04:07:25 +0100 Subject: [PATCH] fix:standardize_lang --- ovos_core/intent_services/fallback_service.py | 26 +++++++++++-------- ovos_core/intent_services/stop_service.py | 7 ++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/ovos_core/intent_services/fallback_service.py b/ovos_core/intent_services/fallback_service.py index 5d1c7e8b3d6..ce567ada341 100644 --- a/ovos_core/intent_services/fallback_service.py +++ b/ovos_core/intent_services/fallback_service.py @@ -16,15 +16,17 @@ import operator import time from collections import namedtuple -from typing import Optional +from typing import Optional, List +from ovos_bus_client.message import Message from ovos_bus_client.session import SessionManager +from ovos_workshop.permissions import FallbackMode + from ovos_config import Configuration from ovos_plugin_manager.templates.pipeline import IntentMatch, PipelinePlugin from ovos_utils import flatten_list from ovos_utils.lang import standardize_lang_tag from ovos_utils.log import LOG -from ovos_workshop.permissions import FallbackMode FallbackRange = namedtuple('FallbackRange', ['start', 'stop']) @@ -40,7 +42,7 @@ def __init__(self, bus): self.bus.on("ovos.skills.fallback.deregister", self.handle_deregister_fallback) super().__init__(self.fallback_config) - def handle_register_fallback(self, message): + def handle_register_fallback(self, message: Message): skill_id = message.data.get("skill_id") priority = message.data.get("priority") or 101 @@ -53,12 +55,12 @@ def handle_register_fallback(self, message): else: self.registered_fallbacks[skill_id] = priority - def handle_deregister_fallback(self, message): + def handle_deregister_fallback(self, message: Message): skill_id = message.data.get("skill_id") if skill_id in self.registered_fallbacks: self.registered_fallbacks.pop(skill_id) - def _fallback_allowed(self, skill_id): + def _fallback_allowed(self, skill_id: str) -> bool: """Checks if a skill_id is allowed to fallback - is the skill blacklisted from fallback @@ -79,7 +81,8 @@ def _fallback_allowed(self, skill_id): return False return True - def _collect_fallback_skills(self, message, fb_range=FallbackRange(0, 100)): + def _collect_fallback_skills(self, message: Message, + fb_range: FallbackRange = FallbackRange(0, 100)) -> List[str]: """use the messagebus api to determine which skills have registered fallback handlers This includes all skills and external applications""" skill_ids = [] # skill_ids that already answered to ping @@ -117,7 +120,7 @@ def handle_ack(msg): self.bus.remove("ovos.skills.fallback.pong", handle_ack) return fallback_skills - def attempt_fallback(self, utterances, skill_id, lang, message): + def attempt_fallback(self, utterances: List[str], skill_id: str, lang: str, message: Message) -> bool: """Call skill and ask if they want to process the utterance. Args: @@ -159,7 +162,8 @@ def attempt_fallback(self, utterances, skill_id, lang, message): f'increasing "max_skill_runtime" in mycroft.conf might help alleviate this issue') return False - def _fallback_range(self, utterances, lang, message, fb_range) -> Optional[IntentMatch]: + def _fallback_range(self, utterances: List[str], lang: str, + message: Message, fb_range: FallbackRange) -> Optional[IntentMatch]: """Send fallback request for a specified priority range. Args: @@ -197,17 +201,17 @@ def _fallback_range(self, utterances, lang, message, fb_range) -> Optional[Inten utterance=utterances[0]) return None - def high_prio(self, utterances, lang, message) -> Optional[IntentMatch]: + def high_prio(self, utterances: List[str], lang: str, message: Message) -> Optional[IntentMatch]: """Pre-padatious fallbacks.""" return self._fallback_range(utterances, lang, message, FallbackRange(0, 5)) - def medium_prio(self, utterances, lang, message) -> Optional[IntentMatch]: + def medium_prio(self, utterances: List[str], lang: str, message: Message) -> Optional[IntentMatch]: """General fallbacks.""" return self._fallback_range(utterances, lang, message, FallbackRange(5, 90)) - def low_prio(self, utterances, lang, message) -> Optional[IntentMatch]: + def low_prio(self, utterances: List[str], lang: str, message: Message) -> Optional[IntentMatch]: """Low prio fallbacks with general matching such as chat-bot.""" return self._fallback_range(utterances, lang, message, FallbackRange(90, 101)) diff --git a/ovos_core/intent_services/stop_service.py b/ovos_core/intent_services/stop_service.py index 54492d0d57c..bdb1137a75f 100644 --- a/ovos_core/intent_services/stop_service.py +++ b/ovos_core/intent_services/stop_service.py @@ -38,7 +38,8 @@ def load_resource_files(self): n = f.split(".", 1)[0] self._voc_cache[lang2][n] = flatten_list(lines) - def get_active_skills(self, message: Optional[Message] = None): + @staticmethod + def get_active_skills(message: Optional[Message] = None) -> List[str]: """Active skill ids ordered by converse priority this represents the order in which stop will be called @@ -48,7 +49,7 @@ def get_active_skills(self, message: Optional[Message] = None): session = SessionManager.get(message) return [skill[0] for skill in session.active_skills] - def _collect_stop_skills(self, message: Message): + def _collect_stop_skills(self, message: Message) -> List[str]: """use the messagebus api to determine which skills can stop This includes all skills and external applications""" @@ -92,7 +93,7 @@ def handle_ack(msg): self.bus.remove("skill.stop.pong", handle_ack) return want_stop or active_skills - def stop_skill(self, skill_id: str, message: Message): + def stop_skill(self, skill_id: str, message: Message) -> bool: """Tell a skill to stop anything it's doing, taking into account the message Session