Skip to content

Commit

Permalink
ensure lang in session
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Jan 29, 2025
1 parent 23e562e commit 1f05583
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ovos_core/intent_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _handle_deactivate(self, message):
skill_id = message.data.get("skill_id")
self._deactivations[sess.session_id].append(skill_id)

def _emit_match_message(self, match: Union[IntentHandlerMatch, PipelineMatch], message: Message):
def _emit_match_message(self, match: Union[IntentHandlerMatch, PipelineMatch], message: Message, lang: str):
"""
Emit a reply message for a matched intent, updating session and skill activation.
Expand All @@ -278,6 +278,7 @@ def _emit_match_message(self, match: Union[IntentHandlerMatch, PipelineMatch], m
match (Union[IntentHandlerMatch, PipelineMatch]): The matched intent object containing
utterance and matching information.
message (Message): The original messagebus message that triggered the intent match.
lang (str): The language of the pipeline plugin match
Details:
- Handles two types of matches: PipelineMatch and IntentHandlerMatch
Expand All @@ -296,6 +297,7 @@ def _emit_match_message(self, match: Union[IntentHandlerMatch, PipelineMatch], m
"""
reply = None
sess = match.updated_session or SessionManager.get(message)
sess.lang = lang # ensure it is updated

# utterance fully handled by pipeline matcher
if isinstance(match, PipelineMatch):
Expand All @@ -310,6 +312,7 @@ def _emit_match_message(self, match: Union[IntentHandlerMatch, PipelineMatch], m

if reply is not None:
reply.data["utterance"] = match.utterance
reply.data["lang"] = lang

# update active skill list
if match.skill_id:
Expand Down Expand Up @@ -414,10 +417,10 @@ def handle_utterance(self, message: Message):
if self.config.get("multilingual_matching"):
# if multilingual matching is enabled, attempt to match all user languages if main fails
langs += [l for l in get_valid_languages() if l != lang]
for l in langs:
match = match_func(utterances, l, message)
for intent_lang in langs:
match = match_func(utterances, intent_lang, message)
if match:
LOG.info(f"{pipeline} match ({l}): {match}")
LOG.info(f"{pipeline} match ({intent_lang}): {match}")
if match.skill_id and match.skill_id in sess.blacklisted_skills:
LOG.debug(
f"ignoring match, skill_id '{match.skill_id}' blacklisted by Session '{sess.session_id}'")
Expand All @@ -427,7 +430,7 @@ def handle_utterance(self, message: Message):
f"ignoring match, intent '{match.match_type}' blacklisted by Session '{sess.session_id}'")
continue
try:
self._emit_match_message(match, message)
self._emit_match_message(match, message, intent_lang)
break
except:
LOG.exception(f"{match_func} returned an invalid match")
Expand Down

0 comments on commit 1f05583

Please sign in to comment.