Skip to content

Commit

Permalink
Move duckling loading to its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
OgnjenFrancuski committed Feb 2, 2024
1 parent 57fb0fd commit cb5a18a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
12 changes: 4 additions & 8 deletions actions/check_restaurant_availability.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from datetime import datetime, timedelta
from typing import List, Optional

from rasa.shared.nlu.training_data.message import Message
from rasa_sdk.interfaces import Action, Tracker
from rasa_sdk.events import EventType, SlotSet
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.interfaces import Action, Tracker
from rasa_sdk.types import DomainDict
from rasa.nlu.extractors.duckling_entity_extractor import DucklingEntityExtractor
from typing import List, Optional

duckling_config = {**DucklingEntityExtractor.get_default_config(),
"url": "https://rasa:[email protected]",
"dimensions": ["time"]}
duckling = DucklingEntityExtractor(duckling_config)
from actions.entity_extractor import duckling_entity_extractor


class CheckRestaurantAvailability(Action):
Expand Down Expand Up @@ -44,7 +40,7 @@ async def run(

def parse_datetime(text: str) -> Optional[datetime]:
msg = Message.build(text)
duckling.process([msg])
duckling_entity_extractor.process([msg])
if len(msg.data["entities"]) == 0:
return None
parsed_value = msg.data["entities"][0]["value"]
Expand Down
15 changes: 15 additions & 0 deletions actions/entity_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os

from dotenv import load_dotenv
from rasa.nlu.extractors.duckling_entity_extractor import DucklingEntityExtractor

load_dotenv()
duckling_url = os.environ.get("DUCKLING_URL")

duckling_config = {
**DucklingEntityExtractor.get_default_config(),
"url": duckling_url,
"dimensions": ["time"]
}

duckling_entity_extractor = DucklingEntityExtractor(duckling_config)
4 changes: 2 additions & 2 deletions actions/setup_recurrent_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.types import DomainDict

from actions.check_restaurant_availability import duckling
from actions.entity_extractor import duckling_entity_extractor


def parse_datetime(text: str) -> Optional[datetime]:
msg = Message.build(text)
duckling.process([msg])
duckling_entity_extractor.process([msg])
if len(msg.data["entities"]) == 0:
return None

Expand Down

0 comments on commit cb5a18a

Please sign in to comment.