From 3c1e4bea79b7a529944ac73b0cff727d2600e548 Mon Sep 17 00:00:00 2001 From: miro Date: Wed, 26 Jun 2024 16:24:59 +0100 Subject: [PATCH 1/5] fix/no_media_skills do not search OCP when no OCP skills are installed --- .../intent_services/locale/en-us/no.media.skills.dialog | 3 +++ ovos_core/intent_services/ocp_service.py | 4 ++++ translations/en-us/dialogs.json | 5 +++++ 3 files changed, 12 insertions(+) create mode 100644 ovos_core/intent_services/locale/en-us/no.media.skills.dialog diff --git a/ovos_core/intent_services/locale/en-us/no.media.skills.dialog b/ovos_core/intent_services/locale/en-us/no.media.skills.dialog new file mode 100644 index 000000000000..ceab698e9145 --- /dev/null +++ b/ovos_core/intent_services/locale/en-us/no.media.skills.dialog @@ -0,0 +1,3 @@ +I'm sorry, I don't have any media skills installed +I need to install some media skills before I can play media +I can't play media until some media skills are installed \ No newline at end of file diff --git a/ovos_core/intent_services/ocp_service.py b/ovos_core/intent_services/ocp_service.py index 3d5eb25465b6..b870be9212ec 100644 --- a/ovos_core/intent_services/ocp_service.py +++ b/ovos_core/intent_services/ocp_service.py @@ -527,6 +527,10 @@ def handle_play_favorites_intent(self, message: Message): # intent handlers def handle_play_intent(self, message: Message): + if not len(self.skill_aliases): # skill_id registered when skills load + self.speak_dialog("no.media.skills") + return + self.speak_dialog("just.one.moment") lang = message.data["lang"] diff --git a/translations/en-us/dialogs.json b/translations/en-us/dialogs.json index b35f6e8ead27..63bd6ddbdbbc 100644 --- a/translations/en-us/dialogs.json +++ b/translations/en-us/dialogs.json @@ -6,6 +6,11 @@ "play.what.dialog": [ "What should i play next?" ], + "no.media.skills.dialog": [ + "I'm sorry, I don't have any media skills installed", + "I need to install some media skills before I can play media", + "I can't play media until some media skills are installed" + ], "just.one.moment.dialog": [ "Give me a moment", "Just a second", From c31f59d38a47a0926fa5a2c81aeb356eb67bfe51 Mon Sep 17 00:00:00 2001 From: miro Date: Thu, 27 Jun 2024 02:10:45 +0100 Subject: [PATCH 2/5] further optimize search speed when no skills available for requested media type --- ovos_core/intent_services/ocp_service.py | 39 +++++++++++++++++++----- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/ovos_core/intent_services/ocp_service.py b/ovos_core/intent_services/ocp_service.py index b870be9212ec..89acb70a91a9 100644 --- a/ovos_core/intent_services/ocp_service.py +++ b/ovos_core/intent_services/ocp_service.py @@ -133,6 +133,9 @@ def __init__(self, bus=None, config=None): self.skill_aliases = { # "skill_id": ["names"] } + self.media2skill = { + m: [] for m in MediaType + } self.entity_csvs = self.config.get("entity_csvs", []) # user defined keyword csv files self.load_classifiers() @@ -242,6 +245,14 @@ def handle_skill_register(self, message: Message): LOG.info(f"Registering OCP Keyword for {skill_id} : {aliases}") self.skill_aliases[skill_id] = aliases + for idx, m in enumerate(media): + try: + m = self._normalize_media_enum(m) + self.media2skill[m].append(skill_id) + media[idx] = m + except: + LOG.error(f"{skill_id} reported an invalid media_type: {m}") + # TODO - review below and add missing # set bias in classifier # aliases -> {type}_streaming_service bias @@ -525,6 +536,16 @@ def handle_play_favorites_intent(self, message: Message): self.bus.emit(message.forward("ovos.common_play.liked_tracks.play")) # intent handlers + @staticmethod + def _normalize_media_enum(m: Union[int, MediaType]): + if isinstance(m, MediaType): + return m + # convert int to enum + for e in MediaType: + if e == m: + return e + raise ValueError(f"{m} is not a valid media type") + def handle_play_intent(self, message: Message): if not len(self.skill_aliases): # skill_id registered when skills load @@ -539,12 +560,6 @@ def handle_play_intent(self, message: Message): skills = message.data.get("skills", []) # search common play skills - # convert int to enum - for e in MediaType: - if e == media_type: - media_type = e - break - results = self._search(query, media_type, lang, skills=skills, message=message) @@ -906,9 +921,11 @@ def _search(self, phrase: str, media_type: MediaType, lang: str, return results def _execute_query(self, phrase: str, - media_type: MediaType = MediaType.GENERIC, + media_type: MediaType = Union[int, MediaType.GENERIC], skills: Optional[List[str]] = None) -> list: """ actually send the search to OCP skills""" + media_type = self._normalize_media_enum(media_type) + with self.search_lock: # stop any search still happening self.bus.emit(Message("ovos.common_play.search.stop")) @@ -919,11 +936,19 @@ def _execute_query(self, phrase: str, results = [] if skills: for skill_id in skills: + if skill_id not in self.media2skill[media_type]: + LOG.debug(f"{skill_id} can't handle {media_type} queries") + continue LOG.debug(f"Searching OCP Skill: {skill_id}") query.send(skill_id) query.wait() results += query.results + if not len(self.media2skill[media_type]): + LOG.info(f"No skills available to handle {media_type} queries, " + f"forcing MediaType.GENERIC") + media_type = MediaType.GENERIC + # search all skills if not results: if skills: From b39429a55b1de8a441565234c635e8be21224e9c Mon Sep 17 00:00:00 2001 From: miro Date: Sun, 30 Jun 2024 20:45:58 +0100 Subject: [PATCH 3/5] fix tests --- test/end2end/session/test_ocp.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/end2end/session/test_ocp.py b/test/end2end/session/test_ocp.py index f8fc65dfe96e..5eeba7659f9c 100644 --- a/test/end2end/session/test_ocp.py +++ b/test/end2end/session/test_ocp.py @@ -347,17 +347,11 @@ def wait_for_n_messages(n): "speak", "ovos.common_play.search.start", "enclosure.mouth.think", - "ovos.common_play.search.stop", # any ongoing previous search - "ovos.common_play.query", # movie media type search - # no skills want to search - "ovos.common_play.query", # generic media type fallback + "ovos.common_play.search.stop", # stop any ongoing previous search + "ovos.common_play.query", # generic media type, no movie skills available # skill searching (generic) "ovos.common_play.skill.search_start", "ovos.common_play.query.response", - "ovos.common_play.query.response", - "ovos.common_play.query.response", - "ovos.common_play.query.response", - "ovos.common_play.query.response", "ovos.common_play.skill.search_end", "ovos.common_play.search.end", # no good results From 61c66a9d6c6c6c538d308c0ead8c146a8e14c480 Mon Sep 17 00:00:00 2001 From: miro Date: Sun, 30 Jun 2024 20:46:52 +0100 Subject: [PATCH 4/5] min requirements.txt --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 2c2e45150489..ab13ad642882 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -12,7 +12,7 @@ ovos-plugin-manager<0.1.0, >=0.0.25 ovos-config~=0.0,>=0.0.13a8 ovos-lingua-franca>=0.4.7 ovos-backend-client~=0.1.0 -ovos-workshop>=0.0.16a40 +ovos-workshop>=0.0.16a42 # provides plugins and classic machine learning framework ovos-classifiers<0.1.0, >=0.0.0a53 From e019156370f70ea3ef059a0d0ba9f6155b1d8d04 Mon Sep 17 00:00:00 2001 From: miro Date: Sun, 30 Jun 2024 20:50:00 +0100 Subject: [PATCH 5/5] typo --- ovos_core/intent_services/ocp_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ovos_core/intent_services/ocp_service.py b/ovos_core/intent_services/ocp_service.py index 89acb70a91a9..5753b7e5a62a 100644 --- a/ovos_core/intent_services/ocp_service.py +++ b/ovos_core/intent_services/ocp_service.py @@ -921,7 +921,7 @@ def _search(self, phrase: str, media_type: MediaType, lang: str, return results def _execute_query(self, phrase: str, - media_type: MediaType = Union[int, MediaType.GENERIC], + media_type: MediaType = Union[int, MediaType], skills: Optional[List[str]] = None) -> list: """ actually send the search to OCP skills""" media_type = self._normalize_media_enum(media_type)