From 50851e09f53a2f40c01a1d0209304a4f1ef96856 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:32:30 +0000 Subject: [PATCH] feat:intents (#7) * feat:intents * feat:intents * fix:improve active persona handling --- ovos_persona/__init__.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/ovos_persona/__init__.py b/ovos_persona/__init__.py index 19a41b8..78280fd 100644 --- a/ovos_persona/__init__.py +++ b/ovos_persona/__init__.py @@ -158,10 +158,16 @@ def match_high(self, utterances: List[str], lang: Optional[str] = None, Returns: IntentMatch if handled otherwise None. """ + if self.active_persona and self.voc_match(utterances[0], "Release", lang): + return IntentHandlerMatch(match_type='persona:release', + match_data={"persona": self.active_persona}, + skill_id="persona.openvoiceos", + utterance=utterances[0]) + match = self.intent_matchers[lang].calc_intent(utterances[0].lower()) if match["name"]: - LOG.info(f"Persona exact match: {match}") + LOG.info(f"Persona intent exact match: {match}") persona = match["entities"].pop("persona") if match["name"] == "summon": return IntentHandlerMatch(match_type='persona:summon', @@ -180,11 +186,18 @@ def match_high(self, utterances: List[str], lang: Optional[str] = None, skill_id="persona.openvoiceos", utterance=utterances[0]) - if self.active_persona and self.voc_match(utterances[0], "Release", lang): - return IntentHandlerMatch(match_type='persona:release', - match_data={"persona": self.active_persona}, - skill_id="persona.openvoiceos", - utterance=utterances[0]) + # override regular intent parsing, handle utterance until persona release + if self.active_persona: + LOG.debug(f"Persona is active: {self.active_persona}") + ans = self.chatbox_ask(utterances[0], + lang=lang, + persona=self.active_persona) + if ans: + return IntentHandlerMatch(match_type='persona:answer', + match_data={"answer": ans, + "persona": self.active_persona}, + skill_id="persona.openvoiceos", + utterance=utterances[0]) def match_medium(self, utterances: List[str], lang: str, message: Message) -> None: return self.match_high(utterances, lang, message) @@ -219,8 +232,10 @@ def handle_persona_summon(self, message): self.speak_dialog("unknown_persona") else: self.active_persona = persona + LOG.info(f"Summoned Persona: {self.active_persona}") def handle_persona_release(self, message): + LOG.info(f"Releasing Persona: {self.active_persona}") self.active_persona = None