Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/converse messages #144

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ jobs:
run: |
sudo apt install libssl-dev libfann-dev portaudio19-dev libpulse-dev
pip install -r requirements/test.txt
pip install ./test/end2end/session/skill-ovos-hello-world
pip install ./test/end2end/session/skill-ovos-fallback-unknown
pip install ./test/end2end/session/skill-ovos-fallback-unknownv1
pip install ./test/end2end/session/skill-converse_test
- name: Run unittests
run: |
pytest --cov=ovos_workshop --cov-report xml test/unittests
pytest --cov-append --cov=ovos_workshop --cov-report xml test/end2end
# NOTE: additional pytest invocations should also add the --cov-append flag
# or they will overwrite previous invocations' coverage reports
# (for an example, see OVOS Skill Manager's workflow)
Expand Down
72 changes: 46 additions & 26 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,9 +915,15 @@ def _register_system_event_handlers(self):
if self.stop_is_implemented:
self.add_event('mycroft.stop', self.__handle_stop,
speak_errors=False)
self.add_event('skill.converse.ping', self._handle_converse_ack,
# TODO: deprectate 0.0.9
self.add_event("skill.converse.ping", self._handle_converse_ack,
speak_errors=False)
self.add_event('skill.converse.request', self._handle_converse_request,
self.add_event(f"{self.skill_id}.converse.ping", self._handle_converse_ack,
emphasize marked this conversation as resolved.
Show resolved Hide resolved
speak_errors=False)
# TODO: deprecate 0.0.9
self.add_event("skill.converse.request", self._handle_converse_request,
speak_errors=False)
self.add_event(f"{self.skill_id}.converse.request", self._handle_converse_request,
speak_errors=False)
self.add_event(f"{self.skill_id}.activate", self.handle_activate,
speak_errors=False)
Expand All @@ -938,7 +944,9 @@ def _register_system_event_handlers(self):
self.add_event('mycroft.skills.settings.changed',
self.handle_settings_change, speak_errors=False)

# TODO: deprecate 0.0.9
self.add_event("skill.converse.get_response", self.__handle_get_response, speak_errors=False)
self.add_event(f"{self.skill_id}.converse.get_response", self.__handle_get_response, speak_errors=False)

def _send_public_api(self, message: Message):
"""
Expand Down Expand Up @@ -1017,8 +1025,13 @@ def _handle_converse_ack(self, message: Message):
may override the property self.converse_is_implemented to enable or
disable converse support. Note that this does not affect a skill's
`active` status.
@param message: `skill.converse.ping` Message
@param message: `{self.skill_id}.converse.ping` Message
"""
if message.msg_type == "skill.converse.ping":
log_deprecation("Support for message type `skill.converse.ping` is deprecated, use `{skill_id}.converse.ping`", "0.0.9")
if message.data.get("skill_id") != self.skill_id:
return # not for us!

self.bus.emit(message.reply(
"skill.converse.pong",
data={"skill_id": self.skill_id,
Expand All @@ -1029,26 +1042,29 @@ def _handle_converse_request(self, message: Message):
"""
If this skill is requested and supports converse, handle the user input
with `converse`.
@param message: `skill.converse.request` Message
@param message: `{self.skill_id}.converse.request` Message
"""
skill_id = message.data['skill_id']
if skill_id == self.skill_id:
try:
# converse can have multiple signatures
params = signature(self.converse).parameters
kwargs = {"message": message,
"utterances": message.data['utterances'],
"lang": message.data['lang']}
kwargs = {k: v for k, v in kwargs.items() if k in params}
result = self.converse(**kwargs)
self.bus.emit(message.reply('skill.converse.response',
{"skill_id": self.skill_id,
"result": result}))
except Exception as e:
LOG.error(e)
self.bus.emit(message.reply('skill.converse.response',
{"skill_id": self.skill_id,
"result": False}))
if message.msg_type == "skill.converse.request":
log_deprecation("Support for message type `skill.converse.request` is deprecated, use `{skill_id}.converse.request`", "0.0.9")
if message.data.get("skill_id") != self.skill_id:
return # not for us!

try:
# converse can have multiple signatures
params = signature(self.converse).parameters
kwargs = {"message": message,
"utterances": message.data['utterances'],
"lang": message.data['lang']}
kwargs = {k: v for k, v in kwargs.items() if k in params}
result = self.converse(**kwargs)
self.bus.emit(message.reply('skill.converse.response',
{"skill_id": self.skill_id,
"result": result}))
except Exception as e:
LOG.error(e)
self.bus.emit(message.reply('skill.converse.response',
{"skill_id": self.skill_id,
"result": False}))

def _handle_collect_resting(self, message: Optional[Message] = None):
"""
Expand Down Expand Up @@ -1545,10 +1561,14 @@ def converse(utterances, lang=None):
return ans

def __handle_get_response(self, message):

skill_id = message.data["skill_id"]
if skill_id != self.skill_id:
return # not for us!
emphasize marked this conversation as resolved.
Show resolved Hide resolved
"""
Handle the response message to a previous get_response / speak call
sent from the intent service
"""
if message.msg_type == "skill.converse.get_response":
log_deprecation("Support for message type `skill.converse.get_response` is deprecated, use `{skill_id}.converse.get_response`", "0.0.9")
if message.data.get("skill_id") != self.skill_id:
return # not for us!

# validate session_id to ensure this isnt another
# user querying the skill at same time
Expand Down
Empty file removed test/end2end/__init__.py
Empty file.
Empty file removed test/end2end/session/__init__.py
Empty file.
69 changes: 0 additions & 69 deletions test/end2end/session/minicroft.py

This file was deleted.

82 changes: 0 additions & 82 deletions test/end2end/session/skill-converse_test/__init__.py

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

39 changes: 0 additions & 39 deletions test/end2end/session/skill-converse_test/setup.py

This file was deleted.

10 changes: 0 additions & 10 deletions test/end2end/session/skill-ovos-fallback-unknown/__init__.py

This file was deleted.

This file was deleted.

Loading
Loading