Skip to content

Commit

Permalink
Merge pull request #2 from OpenVoiceOS/release-0.1.1a1
Browse files Browse the repository at this point in the history
Release 0.1.1a1
  • Loading branch information
JarbasAl authored Oct 14, 2024
2 parents 09f8971 + d0503a5 commit cecd4ca
Show file tree
Hide file tree
Showing 26 changed files with 367 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
- name: Install test dependencies
run: |
pip install -r tests/requirements.txt
pip install tests/ovos_tskill_fakewiki
- name: Run unittests
run: |
pytest --cov=ovos_commonqa --cov-report=xml ./tests
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

## [0.1.1a1](https://github.com/OpenVoiceOS/ovos-common-query-pipeline-plugin/tree/0.1.1a1) (2024-10-14)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-common-query-pipeline-plugin/compare/0.1.0...0.1.1a1)

**Merged pull requests:**

- unittests [\#1](https://github.com/OpenVoiceOS/ovos-common-query-pipeline-plugin/pull/1) ([JarbasAl](https://github.com/JarbasAl))



\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
6 changes: 6 additions & 0 deletions ovos_commonqa/locale/ca-es/Play.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cerca
busca
inicia
comença
llegeix
reprodueix
4 changes: 4 additions & 0 deletions ovos_commonqa/locale/de-de/Play.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lese
spiele
starte
suche
4 changes: 4 additions & 0 deletions ovos_commonqa/locale/en-us/Play.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
play
read
search
start
4 changes: 4 additions & 0 deletions ovos_commonqa/locale/fr-fr/Play.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cherche
démarre
joue
lis
4 changes: 4 additions & 0 deletions ovos_commonqa/locale/it-it/Play.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cerca
inizia
leggi
suona
4 changes: 4 additions & 0 deletions ovos_commonqa/locale/nl-nl/Play.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(speel | play)
lees
start
zoek
4 changes: 4 additions & 0 deletions ovos_commonqa/locale/pt-br/Play.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inicie
leia
procure
toque
4 changes: 4 additions & 0 deletions ovos_commonqa/locale/pt-pt/Play.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(lê|ler)
(procura|procurar)
(reproduz|reproduzir)
(toca|tocar)
4 changes: 2 additions & 2 deletions ovos_commonqa/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# START_VERSION_BLOCK
VERSION_MAJOR = 0
VERSION_MINOR = 1
VERSION_BUILD = 0
VERSION_ALPHA = 0
VERSION_BUILD = 1
VERSION_ALPHA = 1
# END_VERSION_BLOCK
Empty file added tests/__init__.py
Empty file.
66 changes: 66 additions & 0 deletions tests/ovos_tskill_fakewiki/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from ovos_workshop.intents import IntentBuilder

from ovos_workshop.skills.common_query_skill import CommonQuerySkill, CQSMatchLevel
from ovos_workshop.decorators import intent_handler


class FakeWikiSkill(CommonQuerySkill):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.displayed = False
self.idx = 0
self.results = []

# explicit intents
@intent_handler("search_fakewiki.intent")
def handle_search(self, message):
query = message.data["query"]
self.ask_the_wiki(query)
if self.results:
self.speak_result()
else:
self.speak_dialog("no_answer")

@intent_handler(IntentBuilder("FakeWikiMore").require("More").
require("FakeWikiKnows"))
def handle_tell_more(self, message):
""" Follow up query handler, "tell me more"."""
self.speak_result()

def speak_result(self):
if self.idx + 1 > len(self.results):
self.speak_dialog("thats all")
self.remove_context("FakeWikiKnows")
self.idx = 0
else:
self.display_fakewiki()
ans = self.results[self.idx]
self.speak(ans)
self.idx += 1

# common query integration
def CQS_match_query_phrase(self, utt):
self.log.debug("FakeWiki query: " + utt)
response = self.ask_the_wiki(utt)[0]
self.idx += 1 # spoken by common query framework
return (utt, CQSMatchLevel.GENERAL, response,
{'query': utt, 'answer': response})

def CQS_action(self, phrase, data):
""" If selected show gui """
self.display_fakewiki()

# fakewiki integration
def ask_the_wiki(self, query):
# context for follow up questions
self.set_context("FakeWikiKnows", query)
self.idx = 0
self.results = ["answer 1", "answer 2"]
return self.results

def display_fakewiki(self):
self.displayed = True


def create_skill():
return FakeWikiSkill()
4 changes: 4 additions & 0 deletions tests/ovos_tskill_fakewiki/locale/en-US/More.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
know more
tell me more
tell more
continue
1 change: 1 addition & 0 deletions tests/ovos_tskill_fakewiki/locale/en-US/no_answer.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
the archives are incomplete
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
search wiki for {query}
search wiki for {query}
ask the wiki about {query}
ask the wiki about {query}
what does wiki say about {query}
what does wiki say about {query}
ask the wiki {query}
search the wiki for {query}
what does the wiki say about {query}
23 changes: 23 additions & 0 deletions tests/ovos_tskill_fakewiki/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
from setuptools import setup

# skill_id=package_name:SkillClass
PLUGIN_ENTRY_POINT = 'ovos-tskill-fakewiki.openvoiceos=ovos_tskill_fakewiki:FakeWikiSkill'

setup(
# this is the package name that goes on pip
name='ovos-tskill-fakewiki',
version='0.0.1',
description='this is a OVOS test skill for the common query framework',
url='https://github.com/OpenVoiceOS/ovos-core',
author='JarbasAi',
author_email='[email protected]',
license='Apache-2.0',
package_dir={"ovos_tskill_fakewiki": ""},
package_data={'ovos_tskill_fakewiki': ['locale/*']},
packages=['ovos_tskill_fakewiki'],
include_package_data=True,
install_requires=["ovos-workshop"],
keywords='ovos skill plugin',
entry_points={'ovos.plugin.skill': PLUGIN_ENTRY_POINT}
)
4 changes: 4 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coveralls>=1.8.2
flake8>=3.7.9
pytest>=5.2.4
pytest-cov>=2.8.1
159 changes: 159 additions & 0 deletions tests/test_common_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import json
import unittest

from ovos_commonqa.opm import CommonQAService
from ovos_tskill_fakewiki import FakeWikiSkill
from ovos_utils.messagebus import FakeBus, Message


class TestCommonQuery(unittest.TestCase):
def setUp(self):
self.bus = FakeBus()
self.bus.emitted_msgs = []

def get_msg(msg):
self.bus.emitted_msgs.append(json.loads(msg))

self.skill = FakeWikiSkill()
self.skill._startup(self.bus, "wiki.test")

self.cc = CommonQAService(self.bus)

self.bus.on("message", get_msg)

def test_init(self):
self.assertEqual(self.cc.bus, self.bus)
self.assertIsInstance(self.cc.skill_id, str)
self.assertIsInstance(self.cc.active_queries, dict)
self.assertEqual(self.cc.enclosure.bus, self.bus)
self.assertEqual(self.cc.enclosure.skill_id, self.cc.skill_id)
self.assertEqual(len(self.bus.ee.listeners("question:query.response")),
1)
self.assertEqual(len(self.bus.ee.listeners("common_query.question")), 1)

def test_is_question_like(self):
lang = "en-us"
self.assertTrue(self.cc.is_question_like("what is a computer", lang))
self.assertTrue(self.cc.is_question_like("tell me about computers",
lang))
self.assertFalse(self.cc.is_question_like("what computer", lang))
self.assertFalse(self.cc.is_question_like("play something", lang))
self.assertFalse(self.cc.is_question_like("play some music", lang))

def test_match(self):
# TODO
pass

def test_handle_question(self):
# TODO
pass

def test_handle_query_response(self):
# TODO
pass

def test_query_timeout(self):
# TODO
pass

def test_common_query_events(self):
self.bus.emitted_msgs = []
self.assertEqual(self.cc.skill_id, "common_query.openvoiceos")

qq_ctxt = {"source": "audio",
"destination": "skills",
'skill_id': self.cc.skill_id}
qq_ans_ctxt = {"source": "skills",
"destination": "audio",
'skill_id': self.cc.skill_id}
original_ctxt = dict(qq_ctxt)
self.bus.emit(Message("common_query.question",
{"utterance": "what is the speed of light"},
dict(qq_ctxt)))
self.assertEqual(qq_ctxt, original_ctxt, qq_ctxt)
skill_ctxt = {"source": "audio", "destination": "skills", 'skill_id': 'wiki.test'}
skill_ans_ctxt = {"source": "skills", "destination": "audio", 'skill_id': 'wiki.test'}

expected = [
# original query
{'context': qq_ctxt,
'data': {'utterance': 'what is the speed of light'},
'type': 'common_query.question'},
# thinking animation
{'type': 'enclosure.mouth.think',
'data': {},
'context': qq_ctxt},
# send query
{'type': 'question:query',
'data': {'phrase': 'what is the speed of light'},
'context': qq_ans_ctxt},
# skill announces its searching
{'type': 'question:query.response',
'data': {'phrase': 'what is the speed of light',
'skill_id': 'wiki.test',
'searching': True},
'context': skill_ctxt},
# skill context set by skill for continuous dialog
{'type': 'add_context',
'data': {'context': 'wiki_testFakeWikiKnows',
'word': 'what is the speed of light',
'origin': ''},
'context': skill_ans_ctxt},
# final response
{'type': 'question:query.response',
'data': {'phrase': 'what is the speed of light',
'skill_id': 'wiki.test',
'answer': "answer 1",
'handles_speech': True,
'callback_data': {'query': 'what is the speed of light',
'answer': "answer 1"},
'conf': 0.74},
'context': skill_ctxt},
# stop thinking animation
{'type': 'enclosure.mouth.reset',
'data': {},
'context': qq_ctxt},
# skill callback event
# the destination here is `skills` and skill_id context is
# CommonQuery since this event is not dictated by the selected skill
{'type': 'question:action',
'data': {'skill_id': 'wiki.test',
'answer': 'answer 1',
'conf': 0.74,
'handles_speech': True,
'phrase': 'what is the speed of light',
'callback_data': {'query': 'what is the speed of light',
'answer': 'answer 1'}},
'context': qq_ans_ctxt}, # destination: audio from this message forward
# skill was select, make it an active skill
{'context': qq_ans_ctxt,
'data': {'skill_id': 'wiki.test', 'timeout': 5.0},
'type': 'intent.service.skills.activate'},
# tell enclosure about active skill (speak method). This is the
# skill that provided the response and may follow-up with actions
# in a callback method
{'type': 'enclosure.active_skill',
'data': {'skill_id': 'wiki.test'},
'context': qq_ans_ctxt},
# execution of speak method. This is called from CommonQuery, but
# should report the skill which provided the response to match the
# enclosure active_skill and any follow-up actions in the callback
{'type': 'speak',
'data': {'utterance': 'answer 1',
'expect_response': False,
'meta': {'skill': 'wiki.test'},
'lang': 'en-us'},
'context': skill_ans_ctxt},
# handler complete event
{'type': 'mycroft.skill.handler.complete',
'data': {'handler': 'common_query'},
'context': skill_ans_ctxt},
]

for ctr, msg in enumerate(expected):
m: dict = self.bus.emitted_msgs[ctr]
if "session" in m.get("context", {}):
m["context"].pop("session") # simplify test comparisons
if "session" in msg.get("context", {}):
msg["context"].pop("session") # simplify test comparisons
self.assertEqual(msg, m, f"idx={ctr}|emitted={m}")
10 changes: 9 additions & 1 deletion translations/ca-es/vocabs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
"explica'm sobre",
"quin",
"de qui"
],
"Play.voc": [
"cerca",
"busca",
"inicia",
"comença",
"llegeix",
"reprodueix"
]
}
}
8 changes: 7 additions & 1 deletion translations/de-de/vocabs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
"Erzähl mir von",
"welche",
"wessen"
],
"Play.voc": [
"lese",
"spiele",
"starte",
"suche"
]
}
}
Loading

0 comments on commit cecd4ca

Please sign in to comment.