Skip to content

Commit

Permalink
Refactor/converse messages (#371)
Browse files Browse the repository at this point in the history
Co-authored-by: JarbasAi <[email protected]>
  • Loading branch information
emphasize and JarbasAl authored Oct 13, 2023
1 parent e88ff4f commit 2408fd5
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 858 deletions.
18 changes: 11 additions & 7 deletions ovos_core/intent_services/converse_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ def _collect_converse_skills(self, message):

active_skills = self.get_active_skills()

if not active_skills:
return want_converse

event = Event()

def handle_ack(msg):
Expand All @@ -240,7 +243,10 @@ def handle_ack(msg):

self.bus.on("skill.converse.pong", handle_ack)

self.bus.emit(message.forward("skill.converse.ping"))
# ask skills if they want to converse
for skill_id in active_skills:
self.bus.emit(message.forward(f"{skill_id}.converse.ping",
{"skill_id": skill_id}))

# wait for all skills to acknowledge they want to converse
event.wait(timeout=0.5)
Expand Down Expand Up @@ -275,17 +281,15 @@ def converse(self, utterances, skill_id, lang, message):

state = session.utterance_states.get(skill_id, UtteranceState.INTENT)
if state == UtteranceState.RESPONSE:
converse_msg = message.reply("skill.converse.get_response",
{"skill_id": skill_id,
"utterances": utterances,
converse_msg = message.reply(f"{skill_id}.converse.get_response",
{"utterances": utterances,
"lang": lang})
self.bus.emit(converse_msg)
return True

if self._converse_allowed(skill_id):
converse_msg = message.reply("skill.converse.request",
{"skill_id": skill_id,
"utterances": utterances,
converse_msg = message.reply(f"{skill_id}.converse.request",
{"utterances": utterances,
"lang": lang})
result = self.bus.wait_for_response(converse_msg,
'skill.converse.response')
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ovos-plugin-manager<0.1.0, >=0.0.24a9
ovos-config~=0.0,>=0.0.11a13
ovos-lingua-franca>=0.4.7
ovos-backend-client>=0.1.0a12
ovos-workshop<0.1.0, >=0.0.13a10
ovos-workshop<0.1.0, >=0.0.13a16

# provides plugins and classic machine learning framework
ovos-classifiers<0.1.0, >=0.0.0a37
10 changes: 6 additions & 4 deletions test/end2end/session/test_complete_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def test_complete_failure(self):
SessionManager.sessions = {}
SessionManager.default_session = SessionManager.sessions["default"] = Session("default")
SessionManager.default_session.lang = "en-us"
SessionManager.default_session.active_skills = [(self.skill_id, time.time())]
messages = []

def new_msg(msg):
Expand Down Expand Up @@ -46,7 +47,7 @@ def wait_for_n_messages(n):
expected_messages = [
"recognizer_loop:utterance",
# Converse
"skill.converse.ping",
f"{self.skill_id}.converse.ping",
"skill.converse.pong",
# FallbackV1
"mycroft.skills.fallback",
Expand Down Expand Up @@ -81,7 +82,7 @@ def wait_for_n_messages(n):
self.assertEqual(m.context["session"]["session_id"], "default")

# verify ping/pong answer from hello world skill
self.assertEqual(messages[1].msg_type, "skill.converse.ping")
self.assertEqual(messages[1].msg_type, f"{self.skill_id}.converse.ping")
self.assertEqual(messages[2].msg_type, "skill.converse.pong")
self.assertEqual(messages[2].data["skill_id"], self.skill_id)
self.assertEqual(messages[2].context["skill_id"], self.skill_id)
Expand Down Expand Up @@ -131,6 +132,7 @@ def test_complete_failure_lang_detect(self):
SessionManager.sessions = {}
SessionManager.default_session = SessionManager.sessions["default"] = Session("default")
SessionManager.default_session.lang = "en-us"
SessionManager.default_session.active_skills = [(self.skill_id, time.time())]

stt_lang_detect = "pt-pt"

Expand Down Expand Up @@ -167,7 +169,7 @@ def wait_for_n_messages(n):
expected_messages = [
"recognizer_loop:utterance",
"ovos.session.update_default", # language changed
"skill.converse.ping",
f"{self.skill_id}.converse.ping",
"skill.converse.pong",
"mycroft.skills.fallback",
"mycroft.skill.handler.start",
Expand Down Expand Up @@ -205,7 +207,7 @@ def wait_for_n_messages(n):
self.assertEqual(messages[1].data["session_data"]["lang"], stt_lang_detect)

# verify ping/pong answer from hello world skill
self.assertEqual(messages[2].msg_type, "skill.converse.ping")
self.assertEqual(messages[2].msg_type, f"{self.skill_id}.converse.ping")
self.assertEqual(messages[3].msg_type, "skill.converse.pong")
self.assertEqual(messages[3].data["skill_id"], self.skill_id)
self.assertEqual(messages[3].context["skill_id"], self.skill_id)
Expand Down
Loading

0 comments on commit 2408fd5

Please sign in to comment.