Giter Club home page Giter Club logo

forms_bot's People

Contributors

joeyfaulkner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

forms_bot's Issues

Encountered an exception while running the form

Following is my code:

Actions.py:

-- coding: utf-8 --

from typing import Dict, Text, Any, List, Union, Optional

from rasa_sdk import Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormAction

class RestaurantForm(FormAction):
"""Example of a custom form action"""

def name(self) -> Text:
    """Unique identifier of the form"""

    return "restaurant_form"

@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
    """A list of required slots that the form has to fill"""

    return ["cuisine", "num_people", "outdoor_seating", "preferences", "feedback"]

def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
    """A dictionary to map required slots to
        - an extracted entity
        - intent: value pairs
        - a whole message
        or a list of them, where a first match will be picked"""

    return {
        "cuisine": self.from_entity(entity="cuisine", not_intent="chitchat"),
        "num_people": [
            self.from_entity(
                entity="num_people", intent=["inform", "request_restaurant"]
            ),
            self.from_entity(entity="number"),
        ],
        "outdoor_seating": [
            self.from_entity(entity="seating"),
            self.from_intent(intent="affirm", value=True),
            self.from_intent(intent="deny", value=False),
        ],
        "preferences": [
            self.from_intent(intent="deny", value="no additional preferences"),
            self.from_text(not_intent="affirm"),
        ],
        "feedback": [self.from_entity(entity="feedback"), self.from_text()],
    }

# USED FOR DOCS: do not rename without updating in docs
@staticmethod
def cuisine_db() -> List[Text]:
    """Database of supported cuisines"""

    return [
        "caribbean",
        "chinese",
        "french",
        "greek",
        "indian",
        "italian",
        "mexican",
    ]

@staticmethod
def is_int(string: Text) -> bool:
    """Check if a string is an integer"""

    try:
        int(string)
        return True
    except ValueError:
        return False

# USED FOR DOCS: do not rename without updating in docs
def validate_cuisine(
    self,
    value: Text,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
) -> Optional[Text]:
    """Validate cuisine value."""

    if value.lower() in self.cuisine_db():
        # validation succeeded, set the value of the "cuisine" slot to value
        return {"cuisine": value}
    else:
        dispatcher.utter_template("utter_wrong_cuisine", tracker)
        # validation failed, set this slot to None, meaning the
        # user will be asked for the slot again
        return {"cuisine": None}

def validate_num_people(
    self,
    value: Text,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
) -> Optional[Text]:
    """Validate num_people value."""

    if self.is_int(value) and int(value) > 0:
        return {"num_people": value}
    else:
        dispatcher.utter_template("utter_wrong_num_people", tracker)
        # validation failed, set slot to None
        return {"num_people": None}

def validate_outdoor_seating(
    self,
    value: Text,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
) -> Any:
    """Validate outdoor_seating value."""

    if isinstance(value, str):
        if "out" in value:
            # convert "out..." to True
            return {"outdoor_seating": True}
        elif "in" in value:
            # convert "in..." to False
            return {"outdoor_seating": False}
        else:
            dispatcher.utter_template("utter_wrong_outdoor_seating", tracker)
            # validation failed, set slot to None
            return {"outdoor_seating": None}

    else:
        # affirm/deny was picked up as T/F
        return {"outdoor_seating": value}

def submit(
    self,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
) -> List[Dict]:
    """Define what the form has to do
        after all required slots are filled"""

    # utter submit template
    dispatcher.utter_template("utter_submit", tracker)
    return []

But when I load the bot in the terminal it shows the error:

Encountered an exception while running action 'restaurant_form'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.

Can anyone please tell what is wrong here?

missing of training file

In order to train the bot we need to have training data. Could i know where have you provided it?

forms_bot not working with latest rasa_core release

I am getting the following error when i am trying to run the forms_bot code

Bot loaded. Type a message and press enter (use '/stop' to exit):
hi
2018-10-01 17:56:09 DEBUG requests.packages.urllib3.connectionpool - Starting new HTTP connection (1): localhost
2018-10-01 17:56:09 DEBUG rasa_core.tracker_store - Creating a new tracker for id 'default'.
2018-10-01 17:56:09 DEBUG rasa_core.processor - Received user message 'hi' with intent '{'name': 'hi', 'confidence': 1.0}' and entities '[]'
2018-10-01 17:56:09 DEBUG rasa_core.processor - Logged UserUtterance - tracker now has 2 events
2018-10-01 17:56:09 DEBUG rasa_core.processor - Current slot values:
people: None
has_gym: None
breakfast: None
requested_slot: None
location: None
info: None
outdoor_seating: None
hotel: None
enddate: None
restaurant: None
cuisine: None
plan_complete: None
price: None
reservations: None
startdate: None
date_suitable: None
has_spa: None
2018-10-01 17:56:09 DEBUG rasa_core.policies.memoization - Current tracker state [None, {}, {'prev_action_listen': 1.0, 'intent_hi': 1.0}]
2018-10-01 17:56:09 DEBUG rasa_core.policies.memoization - There is no memorised next action
2018-10-01 17:56:09 DEBUG rasa_core.featurizers - Feature 'intent_hi' (value: '1.0') could not be found in feature map. Make sure you added all intents and entities to the domain
2018-10-01 17:56:09 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_2_KerasPolicy
2018-10-01 17:56:09 DEBUG rasa_core.processor - Predicted next action 'activate_restaurant' with prob 0.80.
2018-10-01 17:56:09 ERROR rasa_core.processor - Encountered an exception while running action 'activate_restaurant'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
2018-10-01 17:56:09 ERROR rasa_core.processor - The model predicted the custom action 'activate_restaurant' but you didn't configure an endpoint to run this custom action. Please take a look at the docs and set an endpoint configuration. https://rasa.com/docs/core/customactions/
Traceback (most recent call last):
File "/home/sfrplindia1/Work/SantaFe/Raghuram/chatbots/venv3/lib/python3.5/site-packages/rasa_core/processor.py", line 324, in _run_action
events = action.run(dispatcher, tracker, self.domain)
File "/home/sfrplindia1/Work/SantaFe/Raghuram/chatbots/venv3/lib/python3.5/site-packages/rasa_core/actions/action.py", line 305, in run
"".format(self.name(), DOCS_BASE_URL))
Exception: The model predicted the custom action 'activate_restaurant' but you didn't configure an endpoint to run this custom action. Please take a look at the docs and set an endpoint configuration. https://rasa.com/docs/core/customactions/
2018-10-01 17:56:09 DEBUG rasa_core.processor - Action 'activate_restaurant' ended with events '[]'
2018-10-01 17:56:09 DEBUG rasa_core.policies.memoization - Current tracker state [{}, {'prev_action_listen': 1.0, 'intent_hi': 1.0}, {'prev_activate_restaurant': 1.0, 'intent_hi': 1.0}]
2018-10-01 17:56:09 DEBUG rasa_core.policies.memoization - There is no memorised next action
2018-10-01 17:56:09 DEBUG rasa_core.featurizers - Feature 'intent_hi' (value: '1.0') could not be found in feature map. Make sure you added all intents and entities to the domain
2018-10-01 17:56:09 DEBUG rasa_core.featurizers - Feature 'intent_hi' (value: '1.0') could not be found in feature map. Make sure you added all intents and entities to the domain
2018-10-01 17:56:09 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_2_KerasPolicy
2018-10-01 17:56:09 DEBUG rasa_core.processor - Predicted next action 'deactivate_plan' with prob 0.66.
2018-10-01 17:56:09 ERROR rasa_core.processor - Encountered an exception while running action 'deactivate_plan'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
2018-10-01 17:56:09 ERROR rasa_core.processor - The model predicted the custom action 'deactivate_plan' but you didn't configure an endpoint t

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.