Error while getting latest user message(self.from_text()) in a slot from console

i want the complete input from user to be stored in the slot named ‘doc_desc’ but i am getting an error :Received request to run 'form_2' DEBUG:rasa_core_sdk.forms:There is no active form DEBUG:rasa_core_sdk.forms:Activated the form 'form_2' DEBUG:rasa_core_sdk.forms:Skipping validation **ERROR:flask.app:Exception on /webhook [POST]** Traceback (most recent call last): File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\_compat.py", line 35, in reraise raise value File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_cors\decorator.py", line 128, in wrapped_function resp = make_response(f(*args, **kwargs)) File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\rasa_core_sdk\endpoint.py", line 83, in webhook response = executor.run(action_call) File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\rasa_core_sdk\executor.py", line 177, in run events = action(dispatcher, tracker, domain) File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\rasa_core_sdk\forms.py", line 392, in run domain) File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36\lib\site-packages\rasa_core_sdk\forms.py", line 279, in request_next_slot **for slot in self.required_slots(tracker):** **TypeError: required_slots() takes 1 positional argument but 2 were given** 127.0.0.1 - - [2019-02-12 14:15:10] "POST /webhook HTTP/1.1" 500 412 0.046816

My action_form.py contains: `# -- coding: utf-8 -- from typing import Dict, Text, Any, List, Union

from rasa_core_sdk import ActionExecutionRejection from rasa_core_sdk import Action, Tracker from rasa_core_sdk.events import SlotSet from rasa_core_sdk.executor import CollectingDispatcher from rasa_core_sdk.forms import FormAction, REQUESTED_SLOT

class form_1(FormAction): “”“Example of a custom form action”""

def name(self): # type: () -> Text “”“Unique identifier of the form”""

   return "form_1"

@staticmethod def required_slots(tracker) -> List[Text]: # type: () -> List[Text]

   return ["region", "rel"]

def slot_mapping(self, tracker):

   return {"region": self.from_entity(entity="region"), "rel": self.from_entity(entity="rel")}

def submit(self, dispatcher, tracker, domain): # type: (CollectingDispatcher, Tracker, 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 []

class form_2(FormAction): def name(self): return “form_2”

def required_slots(tracker): # type: () -> List[Text]

   return ["doc_desc"]

def slot_mapping(self):

   return {"doc_desc": self.from_text()}

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

   # utter submit template
   dispatcher.utter_message(tracker.get_slot('doc_desc'))
   dispatcher.utter_template('utter_submit', tracker)
   return []

where is the error, and how do i store the latest text from user into slot name 'doc_desc'. Is there any error in my endpoints.yml? the code there is: action_endpoint: url: “http://localhost:5055/webhook”`

The error appears to be in your actions file in the required slots

TypeError: required_slots() takes 1 positional argument but 2 were given According to the code you posted, there is a syntax error. Colon is in the wrong place.

@staticmethod 
def required_slots(tracker): # -> List[Text] # type: () -> List[Text]
    return ["region", "rel"]

Thank you for replying. I changed and made the correction but still getting the same error. Just to make sure, the error is actually occurring in form_2. The form_1 is extracting entities in the usual manner. Is there a different command to get latest user text as input into a slot from the console vs from an api? I am really confused.

The way you’re accessing the latest slot is right, even the action endpoint seems fine, not sure why the error.

It is this way even on windows terminal, right(to get latest user input)? I am breaking my head but cannot find why this is happening.

I don’t think the whole text is going into the slot. Looking at the docs, the from_text() is to extract slots from the latest text message, similar to from_intent() and from_entities(). It will extract slots from the message, not the message itself.

1 Like

Thanks a lot for the concern. After exploring, i coded the form_action.py as:

class form_2(FormAction):
   def name(self):
       return "form_2"

   def run(self, dispatcher, tracker, domain):
 
       message = tracker.latest_message.get('text')
       SlotSet('doc_desc', message)
       dispatcher.utter_message(tracker.get_slot('doc_desc'))
       return ['doc_desc']

However i am still getting an error on the console where the bot is active as:

Enter the document description 2019-02-12 20:11:31 ERROR rasa_core.processor - Encountered an exception while running action ‘form_2’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code. 127.0.0.1 - - [2019-02-12 20:11:31] “POST /webhooks/rest/webhook?stream=true&token= HTTP/1.1” 200 249 2.205089

But the console where the action point is running says:

127.0.0.1 - - [2019-02-12 20:11:29] “POST /webhook HTTP/1.1” 200 441 0.000000 DEBUG:rasa_core_sdk.executor:Received request to run ‘form_2’ DEBUG:rasa_core_sdk.executor:Successfully ran ‘form_2’ 127.0.0.1 - - [2019-02-12 20:11:31] “POST /webhook HTTP/1.1” 200 192 0.000000

Why is this happening?

Okay, since you have only one slot and you want to capture the whole message don’t use form actions, just create a custom action and store the message. Form actions are just like filling a form which has a series of questions which the user needs to provide.

The error you’re getting might be due to the Slot not being set. You can do it this way using a normal action.

class Actionform_2(Action):
   def name(self):
       return "form_2"

   def run(self, dispatcher, tracker, domain):
 
       message = tracker.latest_message.get('text')
       dispatcher.utter_message(message)
       return [SlotSet('doc_desc', message)] #slot value can only be set by returning it
3 Likes

Thank you so much!