Skip to content

Commit

Permalink
cleanup/explicit_utterance_handled_message (#510)
Browse files Browse the repository at this point in the history
dont emit "ovos.utterance.handled" by pretending to be a intent_type, be explicit about handling this message
  • Loading branch information
JarbasAl authored Jun 20, 2024
1 parent 1f1a371 commit af12cf6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
7 changes: 6 additions & 1 deletion ovos_core/intent_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,13 @@ def _emit_match_message(self, match: IntentMatch, message: Message):
# ensure skill_id is present in message.context
message.context["skill_id"] = match.skill_id

if match.intent_type is True:
# utterance fully handled
reply = message.reply("ovos.utterance.handled",
{"skill_id": match.skill_id})
self.bus.emit(reply)
# Launch skill if not handled by the match function
if match.intent_type:
elif match.intent_type:
# keep all original message.data and update with intent match
data = dict(message.data)
data.update(match.intent_data)
Expand Down
3 changes: 1 addition & 2 deletions ovos_core/intent_services/commonqa_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ def match(self, utterances: str, lang: str, message: Message):
answered, skill_id = self.handle_question(message)
if answered:
match = ovos_core.intent_services.IntentMatch(intent_service='CommonQuery',
intent_type="ovos.utterance.handled",
# emit instead of intent message
intent_type=True,
intent_data={},
skill_id=skill_id,
utterance=utterance)
Expand Down
17 changes: 9 additions & 8 deletions ovos_core/intent_services/converse_service.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import time
from threading import Event

import ovos_core.intent_services
from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, UtteranceState
from ovos_bus_client.util import get_message_lang
from ovos_config.config import Configuration
from ovos_config.locale import setup_locale
from ovos_utils import flatten_list
from ovos_utils.log import LOG
from ovos_bus_client.util import get_message_lang
from ovos_workshop.permissions import ConverseMode, ConverseActivationMode

import ovos_core.intent_services


class ConverseService:
"""Intent Service handling conversational skills."""
Expand Down Expand Up @@ -215,7 +215,7 @@ def _collect_converse_skills(self, message):
# include all skills in get_response state
want_converse = [skill_id for skill_id, state in session.utterance_states.items()
if state == UtteranceState.RESPONSE]
skill_ids += want_converse # dont wait for these pong answers (optimization)
skill_ids += want_converse # dont wait for these pong answers (optimization)

active_skills = self.get_active_skills()

Expand All @@ -230,11 +230,11 @@ def handle_ack(msg):

# validate the converse pong
if all((skill_id not in want_converse,
msg.data.get("can_handle", True),
skill_id in active_skills)):
msg.data.get("can_handle", True),
skill_id in active_skills)):
want_converse.append(skill_id)

if skill_id not in skill_ids: # track which answer we got
if skill_id not in skill_ids: # track which answer we got
skill_ids.append(skill_id)

if all(s in skill_ids for s in active_skills):
Expand Down Expand Up @@ -326,7 +326,8 @@ def converse_with_skills(self, utterances, lang, message):
if self.converse(utterances, skill_id, lang, message):
state = session.utterance_states.get(skill_id, UtteranceState.INTENT)
return ovos_core.intent_services.IntentMatch(intent_service='Converse',
intent_type="ovos.utterance.handled" if state != UtteranceState.RESPONSE else None, # emit instead of intent message
intent_type=state != UtteranceState.RESPONSE,
# intent_type == True -> emit "ovos.utterance.handled"
intent_data={},
skill_id=skill_id,
utterance=utterances[0])
Expand Down
8 changes: 4 additions & 4 deletions ovos_core/intent_services/stop_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def match_stop_high(self, utterances, lang, message):
# emit a global stop, full stop anything OVOS is doing
self.bus.emit(message.reply("mycroft.stop", {}))
return ovos_core.intent_services.IntentMatch(intent_service='Stop',
intent_type="ovos.utterance.handled",
intent_type=True,
intent_data={"conf": conf},
skill_id=None,
utterance=utterance)
Expand All @@ -159,7 +159,7 @@ def match_stop_high(self, utterances, lang, message):

if self.stop_skill(skill_id, message):
return ovos_core.intent_services.IntentMatch(intent_service='Stop',
intent_type="ovos.utterance.handled",
intent_type=True,
intent_data={"conf": conf},
skill_id=skill_id,
utterance=utterance)
Expand Down Expand Up @@ -227,15 +227,15 @@ def match_stop_low(self, utterances, lang, message):

if self.stop_skill(skill_id, message):
return ovos_core.intent_services.IntentMatch(intent_service='Stop',
intent_type="ovos.utterance.handled",
intent_type=True,
# emit instead of intent message
intent_data={"conf": conf},
skill_id=skill_id, utterance=utterance)

# emit a global stop, full stop anything OVOS is doing
self.bus.emit(message.reply("mycroft.stop", {}))
return ovos_core.intent_services.IntentMatch(intent_service='Stop',
intent_type="ovos.utterance.handled",
intent_type=True,
# emit instead of intent message {"conf": conf},
intent_data={},
skill_id=None,
Expand Down

0 comments on commit af12cf6

Please sign in to comment.