Skip to content

Commit

Permalink
fix:standardize_lang
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 16, 2024
1 parent ed6f2e4 commit 0f1b010
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
26 changes: 15 additions & 11 deletions ovos_core/intent_services/fallback_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 4 additions & 3 deletions ovos_core/intent_services/stop_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0f1b010

Please sign in to comment.