Skip to content

Commit

Permalink
fix/get_response some more
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 2, 2023
1 parent 9401f49 commit 26ec761
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,9 +1585,6 @@ def __get_response(self, session: Session):
"skill_id": self.skill_id})
srcm.context["session"] = session.serialize()

self.bus.emit(srcm.forward("skill.converse.get_response.enable",
{"skill_id": self.skill_id}))

LOG.debug(f"get_response session: {session.session_id}")
ans = []

Expand All @@ -1598,20 +1595,13 @@ def __get_response(self, session: Session):
while time.time() - start <= 15 and not ans:
ans = self.__responses[session.session_id]
time.sleep(0.1)
print(f"CURRENT GET RESPONSE: {ans}")
if ans is None:
# aborted externally (if None)
self.log.debug("get_response aborted")
break

self.bus.emit(srcm.forward("skill.converse.get_response.disable",
{"skill_id": self.skill_id}))

if ans:
print(f"GET RESPONSE RETURN: {ans}")
return ans
print(f"GET RESPONSE RETURN: None")
return None
print(f"GET RESPONSE RETURN: {ans}")
return ans

def get_response(self, dialog: str = '', data: Optional[dict] = None,
validator: Optional[Callable[[str], bool]] = None,
Expand Down Expand Up @@ -1639,6 +1629,11 @@ def get_response(self, dialog: str = '', data: Optional[dict] = None,
Message('mycroft.mic.listen', context={"skill_id": self.skill_id})
data = data or {}

session = SessionManager.get(message)
self.__responses[session.session_id] = []
self.bus.emit(message.forward("skill.converse.get_response.enable",
{"skill_id": self.skill_id}))

def on_fail_default(utterance):
fail_data = data.copy()
fail_data['utterance'] = utterance
Expand Down Expand Up @@ -1667,8 +1662,11 @@ def validator_default(utterance):
else:
msg = message.reply('mycroft.mic.listen')
self.bus.emit(msg)
return self._wait_response(is_cancel, validator, on_fail_fn,
num_retries, message)
ans = self._wait_response(is_cancel, validator, on_fail_fn,
num_retries, message)
self.bus.emit(message.forward("skill.converse.get_response.disable",
{"skill_id": self.skill_id}))
return ans

def _wait_response(self, is_cancel: callable, validator: callable,
on_fail: callable, num_retries: int,
Expand All @@ -1684,7 +1682,6 @@ def _wait_response(self, is_cancel: callable, validator: callable,
"""
session = SessionManager.get(message)

self.__responses[session.session_id] = []
# self.__responses.get(session.session_id) <- set in a killable thread
self._real_wait_response(is_cancel, validator, on_fail, num_retries, message)

Expand Down Expand Up @@ -1751,7 +1748,6 @@ def _real_wait_response(self, is_cancel, validator, on_fail, num_retries,
# if nothing said, prompt one more time
if num_fails >= num_retries:
self.__responses[sess.session_id] = None # stop trying
return

num_fails += 1

Expand Down

0 comments on commit 26ec761

Please sign in to comment.