Skip to content

Commit

Permalink
fix/get_response_not_ponging (#372)
Browse files Browse the repository at this point in the history
* fix/get_response_not_conversing

we only converse with skills that pong "can_handle": True and therefore dont handle UtteranceState.RESPONSE

* use threading.Event

* comments + readability

* pin older ovos utils until unittests updated
  • Loading branch information
JarbasAl authored Oct 12, 2023
1 parent 61f361c commit ba7f008
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
46 changes: 31 additions & 15 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 ovos_config.config import Configuration
from ovos_config.locale import setup_locale

import ovos_core.intent_services
from threading import Event
from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, UtteranceState
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_utils.messagebus 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 @@ -209,25 +209,41 @@ def _converse_allowed(self, skill_id):
def _collect_converse_skills(self, message):
"""use the messagebus api to determine which skills want to converse
This includes all skills and external applications"""
session = SessionManager.get(message)

skill_ids = []
want_converse = []
# 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)

active_skills = self.get_active_skills()

event = Event()

def handle_ack(msg):
nonlocal event
skill_id = msg.data["skill_id"]
if msg.data.get("can_handle", True):
if skill_id in active_skills:
want_converse.append(skill_id)
skill_ids.append(skill_id)

# validate the converse pong
if all((skill_id not in want_converse,
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
skill_ids.append(skill_id)

if all(s in skill_ids for s in active_skills):
# all skills answered the ping!
event.set()

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

# wait for all skills to acknowledge they want to converse
self.bus.emit(message.forward("skill.converse.ping"))
start = time.time()
while not all(s in skill_ids for s in active_skills) \
and time.time() - start <= 0.5:
time.sleep(0.02)

# wait for all skills to acknowledge they want to converse
event.wait(timeout=0.5)

self.bus.remove("skill.converse.pong", handle_ack)
return want_converse
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ padacioso~=0.2, >=0.2.1a8
adapt-parser>=1.0.0, <2.0.0

ovos-bus-client<0.1.0, >=0.0.6a10
ovos-utils<0.1.0, >=0.0.36a8
ovos-utils<0.1.0, ==0.0.36a8
ovos-plugin-manager<0.1.0, >=0.0.24a9
ovos-config~=0.0,>=0.0.11a13
ovos-lingua-franca>=0.4.7
Expand Down

0 comments on commit ba7f008

Please sign in to comment.