Skip to content

Commit

Permalink
feat:pipeline plugin factory (#11)
Browse files Browse the repository at this point in the history
* feat:pipeline plugin factory

* feat:pipeline plugin factory

* feat:pipeline plugin factory
  • Loading branch information
JarbasAl authored Oct 16, 2024
1 parent 149d413 commit 73a3aae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
28 changes: 15 additions & 13 deletions ovos_commonqa/opm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
from dataclasses import dataclass
from os.path import dirname
from threading import Event
from typing import Dict, Optional
from typing import Dict, Optional, List, Union

from ovos_bus_client.client import MessageBusClient
from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager
from ovos_config.config import Configuration
from ovos_plugin_manager.solvers import find_multiple_choice_solver_plugins
from ovos_plugin_manager.templates.pipeline import IntentMatch, PipelinePlugin
from ovos_plugin_manager.templates.pipeline import PipelineMatch, PipelineStageMatcher
from ovos_utils import flatten_list
from ovos_utils.log import LOG
from ovos_utils.fakebus import FakeBus
from ovos_utils.lang import standardize_lang_tag
from ovos_utils.log import LOG
from ovos_workshop.app import OVOSAbstractApplication


Expand All @@ -31,12 +33,13 @@ class Query:
selected_skill: str = ""


class CommonQAService(PipelinePlugin, OVOSAbstractApplication):
def __init__(self, bus, config=None):
class CommonQAService(PipelineStageMatcher, OVOSAbstractApplication):
def __init__(self, bus: Optional[Union[MessageBusClient, FakeBus]] = None,
config: Optional[Dict] = None):
OVOSAbstractApplication.__init__(
self, bus=bus, skill_id="common_query.openvoiceos",
resources_dir=f"{dirname(__file__)}")
PipelinePlugin.__init__(self, config)
PipelineStageMatcher.__init__(self, bus, config)
self.active_queries: Dict[str, Query] = dict()

self.common_query_skills = []
Expand Down Expand Up @@ -88,7 +91,7 @@ def is_question_like(self, utterance: str, lang: str):
# require a "question word"
return self.voc_match(utterance, "QuestionWord", lang)

def match(self, utterances: str, lang: str, message: Message) -> Optional[IntentMatch]:
def match(self, utterances: List[str], lang: str, message: Message) -> Optional[PipelineMatch]:
"""
Send common query request and select best response
Expand All @@ -98,7 +101,7 @@ def match(self, utterances: str, lang: str, message: Message) -> Optional[Intent
lang (str): Language code
message: Message for session context
Returns:
IntentMatch or None
PipelineMatch or None
"""
lang = standardize_lang_tag(lang)
# we call flatten in case someone is sending the old style list of tuples
Expand All @@ -118,11 +121,10 @@ def match(self, utterances: str, lang: str, message: Message) -> Optional[Intent
message.data["utterance"] = utterance
answered, skill_id = self.handle_question(message)
if answered:
match = IntentMatch(intent_service='CommonQuery',
intent_type=True,
intent_data={},
skill_id=skill_id,
utterance=utterance)
match = PipelineMatch(handled=True,
match_data={},
skill_id=skill_id,
utterance=utterance)
break
return match

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ovos-workshop>=0.1.7,<2.0.0
ovos-plugin-manager
ovos-plugin-manager>=0.5.0,<1.0.0
ovos-bus-client
ovos-config
ovos-utils>=0.3.4,<1.0.0
4 changes: 2 additions & 2 deletions tests/test_common_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_init(self):
self.assertEqual(len(self.bus.ee.listeners("common_query.question")), 1)

def test_is_question_like(self):
lang = "en-us"
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))
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_common_query_events(self):
'data': {'utterance': 'answer 1',
'expect_response': False,
'meta': {'skill': 'wiki.test'},
'lang': 'en-us'},
'lang': 'en-US'},
'context': skill_ans_ctxt},
# handler complete event
{'type': 'mycroft.skill.handler.complete',
Expand Down

0 comments on commit 73a3aae

Please sign in to comment.