@EPedrotti I am not sure how it is going wrong in the custom actions, because the custom actions seem to be working perfectly fine while I run them on the cmd line. That is leaving me confused, or may be I am missing something rudimentary here. I am posting all the details below, I also have this as an open issue on github.
Actions SDK just returns a 404 error whenever the APIs need to be called, the thing I do not get is that works perfectly fine on the cmd line.
INFO:__main__:Starting action endpoint server...
INFO:rasa_core_sdk.executor:Registered function for 'action_weather'.
INFO:rasa_core_sdk.executor:Registered function for 'wolfram_alpha'.
INFO:__main__:Action endpoint is up and running. on ('0.0.0.0', 5055)
127.0.0.1 - - [2019-01-01 12:00:27] "POST /webhook/ HTTP/1.1" 404 342 0.009915
127.0.0.1 - - [2019-01-01 12:00:53] "POST /webhook/ HTTP/1.1" 404 342 0.001687
Here are my localhost logs
2019-01-01 12:00:27 ERROR rasa_core.actions.action - Failed to run custom action 'action_weather'. Action server responded with a non 200 status code of 404. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/
2019-01-01 12:00:27 ERROR rasa_core.processor - Encountered an exception while running action 'action_weather'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
127.0.0.1 - - [2019-01-01 12:00:27] "POST /webhooks/rest/webhook HTTP/1.1" 200 142 0.077290
2019-01-01 12:00:53 WARNING py.warnings - /anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
2019-01-01 12:00:53 ERROR rasa_core.actions.action - Failed to run custom action 'wolfram_alpha'. Action server responded with a non 200 status code of 404. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/
2019-01-01 12:00:53 ERROR rasa_core.processor - Encountered an exception while running action 'wolfram_alpha'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
127.0.0.1 - - [2019-01-01 12:00:53] "POST /webhooks/rest/webhook HTTP/1.1" 200 142 0.073290
You can see I tried calling both the APIs and get the same error. Also if I didn’t mention before, everything other than API calls is returning a response on postman as it should.
Here are more detailed logs. My first input is: “Hello my name is Mark”. I get a response back, my next input is: “Who is the president of US?” where it should call the Wolfram API. The same thing happens with weather API if I change my input to: “What is the weather in London?”
2019-01-01 12:18:44 INFO root - Rasa Core server is up and running on http://localhost:5005
Bot loaded. Type a message and press enter (use '/stop' to exit):
2019-01-01 12:18:57 DEBUG rasa_core.tracker_store - Creating a new tracker for id 'Rasa'.
2019-01-01 12:18:57 WARNING py.warnings - /anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
2019-01-01 12:18:57 DEBUG rasa_core.processor - Received user message 'Hello my name is Mark' with intent '{'name': 'greet', 'confidence': 0.5992243649211548}' and entities '[{'start': 17, 'end': 21, 'value': 'mark', 'entity': 'PERSON', 'confidence': 0.6440988744205052, 'extractor': 'ner_crf'}]'
2019-01-01 12:18:57 DEBUG rasa_core.processor - Logged UserUtterance - tracker now has 3 events
2019-01-01 12:18:57 DEBUG rasa_core.processor - Current slot values:
PERSON: mark
location: None
2019-01-01 12:18:57 DEBUG rasa_core.policies.memoization - Current tracker state [None, None, None, {}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:18:57 DEBUG rasa_core.policies.memoization - There is no memorised next action
2019-01-01 12:18:57 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:18:57 DEBUG rasa_core.processor - Predicted next action 'utter_greet' with prob 0.30.
2019-01-01 12:18:57 DEBUG rasa_core.processor - Action 'utter_greet' ended with events '[]'
2019-01-01 12:18:57 DEBUG rasa_core.processor - Bot utterance 'BotUttered(text: Hello mark! How can I help?, data: {
"elements": null,
"buttons": null,
"attachment": null
})'
2019-01-01 12:18:57 DEBUG rasa_core.policies.memoization - Current tracker state [None, None, {}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'prev_utter_greet': 1.0, 'entity_PERSON': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:18:57 DEBUG rasa_core.policies.memoization - There is no memorised next action
2019-01-01 12:18:57 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:18:57 DEBUG rasa_core.processor - Predicted next action 'action_listen' with prob 0.87.
2019-01-01 12:18:57 DEBUG rasa_core.processor - Action 'action_listen' ended with events '[]'
127.0.0.1 - - [2019-01-01 12:18:57] "POST /webhooks/rest/webhook HTTP/1.1" 200 203 0.257879
2019-01-01 12:19:51 DEBUG rasa_core.tracker_store - Recreating tracker for id 'Rasa'
2019-01-01 12:19:52 WARNING py.warnings - /anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
2019-01-01 12:19:52 DEBUG rasa_core.processor - Received user message 'Who is the president of US' with intent '{'name': 'information', 'confidence': 0.6909834200535575}' and entities '[]'
2019-01-01 12:19:52 DEBUG rasa_core.processor - Logged UserUtterance - tracker now has 7 events
2019-01-01 12:19:52 DEBUG rasa_core.processor - Current slot values:
PERSON: mark
location: None
2019-01-01 12:19:52 DEBUG rasa_core.policies.memoization - Current tracker state [None, {}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'prev_utter_greet': 1.0, 'entity_PERSON': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'intent_information': 1.0, 'prev_action_listen': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:19:52 DEBUG rasa_core.policies.memoization - There is no memorised next action
2019-01-01 12:19:52 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:19:52 DEBUG rasa_core.processor - Predicted next action 'wolfram_alpha' with prob 0.70.
2019-01-01 12:19:52 DEBUG rasa_core.actions.action - Calling action endpoint to run action 'wolfram_alpha'.
2019-01-01 12:19:52 ERROR rasa_core.actions.action - Failed to run custom action 'wolfram_alpha'. Action server responded with a non 200 status code of 404. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/
2019-01-01 12:19:52 ERROR rasa_core.processor - Encountered an exception while running action 'wolfram_alpha'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
2019-01-01 12:19:52 DEBUG rasa_core.processor - Failed to execute custom action.
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/rasa_core/actions/action.py", line 338, in run
response.raise_for_status()
File "/anaconda3/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/rasa_core/processor.py", line 351, in _run_action
events = action.run(dispatcher, tracker, self.domain)
File "/anaconda3/lib/python3.6/site-packages/rasa_core/actions/action.py", line 358, in run
raise Exception("Failed to execute custom action.")
Exception: Failed to execute custom action.
2019-01-01 12:19:52 DEBUG rasa_core.processor - Action 'wolfram_alpha' ended with events '[]'
2019-01-01 12:19:52 DEBUG rasa_core.policies.memoization - Current tracker state [{}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'prev_utter_greet': 1.0, 'entity_PERSON': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'intent_information': 1.0, 'prev_action_listen': 1.0, 'slot_PERSON_0': 1.0}, {'intent_information': 1.0, 'prev_wolfram_alpha': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:19:52 DEBUG rasa_core.policies.memoization - There is no memorised next action
2019-01-01 12:19:52 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:19:52 DEBUG rasa_core.processor - Predicted next action 'action_listen' with prob 0.98.
2019-01-01 12:19:52 DEBUG rasa_core.processor - Action 'action_listen' ended with events '[]'
127.0.0.1 - - [2019-01-01 12:19:52] "POST /webhooks/rest/webhook HTTP/1.1" 200 142 0.094410
And I will also attach my custom actions file, it just making two API calls.
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet
class ActionWeather(Action):
def name(self):
return 'action_weather'
def run(self, dispatcher, tracker, domain):
from apixu.client import ApixuClient
api_key = #your apixu key
client = ApixuClient(api_key)
loc = tracker.get_slot('location')
current = client.getCurrentWeather(q=loc)
country = current['location']['country']
city = current['location']['name']
condition = current['current']['condition']['text']
temperature_c = current['current']['temp_c']
humidity = current['current']['humidity']
wind_mph = current['current']['wind_mph']
response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph)
dispatcher.utter_message(response)
return [SlotSet('location',loc)]
class Wolfram(Action):
def name(self):
return 'wolfram_alpha'
def run(self, dispatcher, tracker, domain):
import wolframalpha
app_id = "api_key"
input = tracker.latest_message["text"]
print(input)
client = wolframalpha.Client(app_id)
res = client.query(input)
answer = next(res.results).text
response = answer
dispatcher.utter_message(response)
return