diff --git a/actions/check_restaurant_availability.py b/actions/check_restaurant_availability.py index e5bd0ce..948a508 100644 --- a/actions/check_restaurant_availability.py +++ b/actions/check_restaurant_availability.py @@ -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:xCTBjGqjTqDqE6X72FXLiBWVXYaQDZ@duckling.rasa-dev.io", - "dimensions": ["time"]} -duckling = DucklingEntityExtractor(duckling_config) +from actions.entity_extractor import duckling_entity_extractor class CheckRestaurantAvailability(Action): @@ -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"] diff --git a/actions/entity_extractor.py b/actions/entity_extractor.py new file mode 100644 index 0000000..18ff9d0 --- /dev/null +++ b/actions/entity_extractor.py @@ -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) diff --git a/actions/setup_recurrent_payment.py b/actions/setup_recurrent_payment.py index 60a2744..a70628a 100644 --- a/actions/setup_recurrent_payment.py +++ b/actions/setup_recurrent_payment.py @@ -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