Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move duckling loading to its own module #7

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading