Skip to content

Commit

Permalink
feat:pipeline plugin factory
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 16, 2024
1 parent bd9741e commit 0cc2081
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 20 additions & 18 deletions padacioso/opm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

from functools import lru_cache
from os.path import isfile
from typing import List, Optional
from typing import Optional, Dict, List, Union

from langcodes import closest_match
from ovos_bus_client.client import MessageBusClient
from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from ovos_config.config import Configuration
from ovos_plugin_manager.templates.pipeline import PipelinePlugin, IntentMatch
from ovos_plugin_manager.templates.pipeline import ConfidenceMatcherPipeline, IntentMatch
from ovos_utils import flatten_list
from ovos_utils.fakebus import FakeBus
from ovos_utils.lang import standardize_lang_tag
from ovos_utils.log import LOG

Expand Down Expand Up @@ -46,27 +48,26 @@ def __repr__(self):
return repr(self.__dict__)


class PadaciosoPipeline(PipelinePlugin):
class PadaciosoPipeline(ConfidenceMatcherPipeline):
"""Service class for padacioso intent matching."""

def __init__(self, bus, config):
super().__init__(config)
self.padacioso_config = config
self.bus = bus
def __init__(self, bus: Optional[Union[MessageBusClient, FakeBus]] = None,
config: Optional[Dict] = None):
super().__init__(config=config or {}, bus=bus)

core_config = Configuration()
self.lang = standardize_lang_tag(core_config.get("lang", "en-US"))
langs = core_config.get('secondary_langs') or []
if self.lang not in langs:
langs.append(self.lang)
langs = [standardize_lang_tag(l) for l in langs]
self.conf_high = self.padacioso_config.get("conf_high") or 0.95
self.conf_med = self.padacioso_config.get("conf_med") or 0.8
self.conf_low = self.padacioso_config.get("conf_low") or 0.5
self.workers = self.padacioso_config.get("workers") or 4
self.conf_high = self.config.get("conf_high") or 0.95
self.conf_med = self.config.get("conf_med") or 0.8
self.conf_low = self.config.get("conf_low") or 0.5
self.workers = self.config.get("workers") or 4

self.containers = {lang: FallbackIntentContainer(
self.padacioso_config.get("fuzz"), n_workers=self.workers)
self.config.get("fuzz"), n_workers=self.workers)
for lang in langs}

self.bus.on('padatious:register_intent', self.register_intent)
Expand Down Expand Up @@ -95,11 +96,12 @@ def _match_level(self, utterances, limit, lang=None,
padacioso_intent = self.calc_intent(utterances, lang, message)
if padacioso_intent is not None and padacioso_intent.conf > limit:
skill_id = padacioso_intent.name.split(':')[0]
return IntentMatch(
'Padacioso', padacioso_intent.name,
padacioso_intent.matches, skill_id, padacioso_intent.sent)
return IntentMatch(match_type=padacioso_intent.name,
match_data=padacioso_intent.matches,
skill_id=skill_id,
utterance=padacioso_intent.sent)

def match_high(self, utterances, lang=None, message=None) -> Optional[IntentMatch]:
def match_high(self, utterances: List[str], lang: str, message: Message) -> Optional[IntentMatch]:
"""Intent matcher for high confidence.
Args:
Expand All @@ -108,7 +110,7 @@ def match_high(self, utterances, lang=None, message=None) -> Optional[IntentMatc
"""
return self._match_level(utterances, self.conf_high, lang, message)

def match_medium(self, utterances, lang=None, message=None) -> Optional[IntentMatch]:
def match_medium(self, utterances: List[str], lang: str, message: Message) -> Optional[IntentMatch]:
"""Intent matcher for medium confidence.
Args:
Expand All @@ -117,7 +119,7 @@ def match_medium(self, utterances, lang=None, message=None) -> Optional[IntentMa
"""
return self._match_level(utterances, self.conf_med, lang, message)

def match_low(self, utterances, lang=None, message=None) -> Optional[IntentMatch]:
def match_low(self, utterances: List[str], lang: str, message: Message) -> Optional[IntentMatch]:
"""Intent matcher for low confidence.
Args:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def required(requirements_file):
if pkg.strip() and not pkg.startswith("#")]


PLUGIN_ENTRY_POINT = 'ovos-padacioso-pipeline-plugin=ovos_padacioso.opm:PadaciosoPipeline'
PLUGIN_ENTRY_POINT = 'ovos-padacioso-pipeline-plugin=padacioso.opm:PadaciosoPipeline'


setup(
Expand Down

0 comments on commit 0cc2081

Please sign in to comment.