Skip to content

Commit

Permalink
engine from config
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Dec 12, 2024
1 parent b53a92c commit 582e12d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ovos_padatious.match_data import MatchData


class DomainIntentEngine:
class DomainIntentContainer:
"""
A domain-aware intent recognition engine that organizes intents and entities
into specific domains, providing flexible and hierarchical intent matching.
Expand Down
29 changes: 21 additions & 8 deletions ovos_padatious/opm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# limitations under the License.
#
"""Intent service wrapping padatious."""
from collections import defaultdict
from functools import lru_cache
from os.path import expanduser, isfile
from threading import Event, RLock
from typing import Optional, Dict, List, Union
from collections import defaultdict
from typing import Optional, Dict, List, Union, Type

from langcodes import closest_match
from ovos_bus_client.client import MessageBusClient
from ovos_bus_client.message import Message
Expand All @@ -31,10 +32,16 @@
from ovos_utils.log import LOG, deprecated, log_deprecation
from ovos_utils.xdg_utils import xdg_data_home

from ovos_padatious import IntentContainer as PadatiousIntentContainer
from ovos_padatious.domain_engine import DomainIntentEngine
from ovos_padatious import IntentContainer
from ovos_padatious.domain_engine import DomainIntentContainer
from ovos_padatious.match_data import MatchData as PadatiousIntent

PadatiousIntentContainer = IntentContainer # backwards compat

# for easy typing
PadatiousEngine = Union[Type[IntentContainer],
Type[DomainIntentContainer]]


class PadatiousMatcher:
"""Matcher class to avoid redundancy in padatious intent matching."""
Expand Down Expand Up @@ -88,7 +95,8 @@ class PadatiousPipeline(ConfidenceMatcherPipeline):
"""Service class for padatious intent matching."""

def __init__(self, bus: Optional[Union[MessageBusClient, FakeBus]] = None,
config: Optional[Dict] = None):
config: Optional[Dict] = None,
engine_class: Optional[PadatiousEngine] = IntentContainer):

super().__init__(bus, config)
self.lock = RLock()
Expand All @@ -103,10 +111,15 @@ def __init__(self, bus: Optional[Union[MessageBusClient, FakeBus]] = None,
self.conf_med = self.config.get("conf_med") or 0.8
self.conf_low = self.config.get("conf_low") or 0.5

if engine_class is None:
if self.config.get("domain_engine"):
engine_class = DomainIntentContainer
else:
engine_class = IntentContainer

intent_cache = expanduser(self.config.get('intent_cache') or
f"{xdg_data_home()}/{get_xdg_base()}/intent_cache")
self.containers = {lang: DomainIntentEngine(f"{intent_cache}/{lang}")
for lang in langs}
self.containers = {lang: engine_class(cache_dir=f"{intent_cache}/{lang}") for lang in langs}

self.finished_training_event = Event() # DEPRECATED
self.finished_initial_train = False
Expand Down Expand Up @@ -397,7 +410,7 @@ def handle_entity_manifest(self, message):

@lru_cache(maxsize=3) # repeat calls under different conf levels wont re-run code
def _calc_padatious_intent(utt: str,
intent_container: PadatiousIntentContainer,
intent_container: Union[IntentContainer, DomainIntentContainer],
sess: Session) -> Optional[PadatiousIntent]:
"""
Try to match an utterance to an intent in an intent_container
Expand Down

0 comments on commit 582e12d

Please sign in to comment.