Skip to content

Commit

Permalink
feat:intents (#7)
Browse files Browse the repository at this point in the history
* feat:intents

* feat:intents

* fix:improve active persona handling
  • Loading branch information
JarbasAl authored Nov 13, 2024
1 parent 950fd85 commit 50851e0
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions ovos_persona/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 50851e0

Please sign in to comment.