Skip to content

Commit

Permalink
Move duckling loading to its own module (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
OgnjenFrancuski authored Feb 6, 2024
1 parent 57fb0fd commit 62221f9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
OPENAI_API_KEY: ${{secrets.OPENAI_API_KEY}}
RASA_PRO_LICENSE: ${{secrets.RASA_PRO_LICENSE}}
RASA_PRO_BETA_INTENTLESS: true
DUCKLING_URL: ${{secrets.DUCKLING_URL}}
run: |
make train
Expand Down
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 62221f9

Please sign in to comment.