From 9a8588762c90f35906961f0433a351a8e1cf809f Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:16:09 +0000 Subject: [PATCH 1/3] fix:legacy cps session (#22) keep message.context to ensure session --- ocp_pipeline/legacy.py | 12 ++++++------ ocp_pipeline/opm.py | 29 ++++++++++++++--------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/ocp_pipeline/legacy.py b/ocp_pipeline/legacy.py index 6fb0709..f17cb12 100644 --- a/ocp_pipeline/legacy.py +++ b/ocp_pipeline/legacy.py @@ -1,7 +1,7 @@ import time from typing import Tuple, Optional -from ovos_bus_client.message import Message +from ovos_bus_client.message import Message, dig_for_message from ovos_bus_client.util import wait_for_reply from ovos_utils.ocp import MediaType, PlaybackType, MediaEntry @@ -67,19 +67,19 @@ def handle_cps_response(self, message): # Collect all replies until the timeout self.query_replies[message.data["phrase"]].append(message.data) - def send_query(self, phrase): + def send_query(self, phrase, message: Optional[Message] = None): self.query_replies[phrase] = [] self.query_extensions[phrase] = [] - self.bus.emit(Message('play:query', - {"phrase": phrase})) + message = message or dig_for_message() or Message("") + self.bus.emit(message.forward('play:query',{"phrase": phrase})) def get_results(self, phrase): if self.query_replies.get(phrase): return [self.cps2media(r) for r in self.query_replies[phrase]] return [] - def search(self, phrase, timeout=5): - self.send_query(phrase) + def search(self, phrase, timeout=5, message: Optional[Message] = None): + self.send_query(phrase, message) self.waiting = True start_ts = time.time() while self.waiting and time.time() - start_ts <= timeout: diff --git a/ocp_pipeline/opm.py b/ocp_pipeline/opm.py index 42ad536..4dbdb63 100644 --- a/ocp_pipeline/opm.py +++ b/ocp_pipeline/opm.py @@ -14,8 +14,7 @@ from ovos_bus_client.session import SessionManager from ovos_config import Configuration from ovos_plugin_manager.ocp import available_extractors -from ovos_plugin_manager.templates.pipeline import IntentHandlerMatch, ConfidenceMatcherPipeline, PipelineStageMatcher, \ - PipelineMatch +from ovos_plugin_manager.templates.pipeline import IntentHandlerMatch, ConfidenceMatcherPipeline from ovos_utils.lang import standardize_lang_tag, get_language_dir from ovos_utils.log import LOG, deprecated, log_deprecation from ovos_utils.messagebus import FakeBus @@ -1062,7 +1061,7 @@ def match_fallback(self, utterances: List[str], lang: str, message: Message = No return self.match_low(utterances, lang, message) @deprecated("match_legacy is deprecated! use MycroftCPSLegacyPipeline class directly instead", "2.0.0") - def match_legacy(self, utterances: List[str], lang: str, message: Message = None) -> Optional[PipelineMatch]: + def match_legacy(self, utterances: List[str], lang: str, message: Message = None) -> Optional[IntentHandlerMatch]: """ match legacy mycroft common play skills (must import from deprecated mycroft module) not recommended, legacy support only @@ -1071,17 +1070,19 @@ def match_legacy(self, utterances: List[str], lang: str, message: Message = None return MycroftCPSLegacyPipeline(self.bus, self.config).match(utterances, lang, message) -class MycroftCPSLegacyPipeline(PipelineStageMatcher): +class MycroftCPSLegacyPipeline(ConfidenceMatcherPipeline, OVOSAbstractApplication): def __init__(self, bus: Optional[Union[MessageBusClient, FakeBus]] = None, config: Optional[Dict] = None): - super().__init__(bus, config) + OVOSAbstractApplication.__init__(self, bus=bus or FakeBus(), + skill_id=OCP_ID, resources_dir=f"{dirname(__file__)}") + ConfidenceMatcherPipeline.__init__(self, bus, config) self.mycroft_cps = LegacyCommonPlay(self.bus) OCPPipelineMatcher.load_intent_files() - self.bus.on("ocp:legacy_cps", self.handle_legacy_cps) + self.add_event("ocp:legacy_cps", self.handle_legacy_cps, is_intent=True) ############ # Legacy Mycroft CommonPlay skills - def match(self, utterances: List[str], lang: str, message: Message = None) -> Optional[PipelineMatch]: + def match(self, utterances: List[str], lang: str, message: Message = None) -> Optional[IntentHandlerMatch]: """ match legacy mycroft common play skills (must import from deprecated mycroft module) not recommended, legacy support only @@ -1104,13 +1105,11 @@ def match(self, utterances: List[str], lang: str, message: Message = None) -> Op if match["name"] == "play": LOG.info(f"Legacy Mycroft CommonPlay match: {match}") utterance = match["entities"].pop("query") - self.bus.emit(Message("ocp:legacy_cps", - {"query": utterance, "conf": 0.7})) - return PipelineMatch(handled=True, - match_data={"query": utterance, - "conf": 0.7}, - skill_id=OCP_ID, - utterance=utterance) + return IntentHandlerMatch(match_type="ocp:legacy_cps", + match_data={"query": utterance, + "conf": 0.7}, + skill_id=OCP_ID, + utterance=utterance) def match_medium(self, utterances: List[str], lang: str, message: Message = None) -> Optional[IntentHandlerMatch]: return None @@ -1121,7 +1120,7 @@ def match_low(self, utterances: List[str], lang: str, message: Message = None) - def handle_legacy_cps(self, message: Message): """intent handler for legacy CPS matches""" utt = message.data["query"] - res = self.mycroft_cps.search(utt) + res = self.mycroft_cps.search(utt, message=message) if res: best = OCPPipelineMatcher.select_best([r[0] for r in res], message) if best: From cbb392478e19b7a05d8628a8bc02c72897dc1a8d Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Thu, 31 Oct 2024 16:16:26 +0000 Subject: [PATCH 2/3] Increment Version to 1.0.3a1 --- ocp_pipeline/version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocp_pipeline/version.py b/ocp_pipeline/version.py index fd1e64f..cf2e7fd 100644 --- a/ocp_pipeline/version.py +++ b/ocp_pipeline/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_BUILD = 2 -VERSION_ALPHA = 0 +VERSION_BUILD = 3 +VERSION_ALPHA = 1 # END_VERSION_BLOCK From 93b3cbc47ee133de79d80237cc4f50f2875279bb Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Thu, 31 Oct 2024 16:16:46 +0000 Subject: [PATCH 3/3] Update Changelog --- CHANGELOG.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfb39f2..27db853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,22 +1,12 @@ # Changelog -## [1.0.2a1](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/tree/1.0.2a1) (2024-10-31) +## [1.0.3a1](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/tree/1.0.3a1) (2024-10-31) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/compare/1.0.2a1...1.0.2a1) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/compare/1.0.2...1.0.3a1) **Merged pull requests:** -- fix:legacy\_cps [\#21](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/pull/21) ([JarbasAl](https://github.com/JarbasAl)) -- de-de/translate [\#20](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/pull/20) ([gitlocalize-app[bot]](https://github.com/apps/gitlocalize-app)) - -## [1.0.2a1](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/tree/1.0.2a1) (2024-10-19) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/compare/1.0.1...1.0.2a1) - -**Merged pull requests:** - -- fixed italian translation [\#19](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/pull/19) ([gitlocalize-app[bot]](https://github.com/apps/gitlocalize-app)) -- fixed italian translation [\#18](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/pull/18) ([gitlocalize-app[bot]](https://github.com/apps/gitlocalize-app)) +- fix:legacy cps session [\#22](https://github.com/OpenVoiceOS/ovos-ocp-pipeline-plugin/pull/22) ([JarbasAl](https://github.com/JarbasAl))