I’m creating a custom action that accesses an API that returns a list of fun facts. I am trying to save this return in a list slot, but I can’t access it.
When I try to do this, I get the following error:
2020-10-19 01:02:50 ERROR rasa.core.processor - Encountered an exception while running action 'action_cat_facts'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.
2020-10-19 01:02:50 DEBUG rasa.core.processor - Failed to execute custom action.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/rasa/core/actions/action.py", line 551, in run
json=json_body, method="post", timeout=DEFAULT_REQUEST_TIMEOUT
File "/usr/local/lib/python3.7/site-packages/rasa/utils/endpoints.py", line 154, in request
response.status, response.reason, await response.content.read()
rasa.utils.endpoints.ClientResponseError: 500, Internal Server Error, body='b'\n <h1>Internal Server Error</h1>\n <p>\n The server encountered an internal error and cannot complete\n your request.\n </p>\n''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/rasa/core/processor.py", line 650, in _run_action
events = await action.run(output_channel, nlg, tracker, self.domain)
File "/usr/local/lib/python3.7/site-packages/rasa/core/actions/action.py", line 574, in run
raise Exception("Failed to execute custom action.") from e
Exception: Failed to execute custom action.
2020-10-19 01:02:50 DEBUG rasa.core.processor - Action 'action_cat_facts' ended with events '[]'.
domain.yml
slots:
fatos_sobre_gatos:
type: list
actions:
- action_cat_facts
stories.md
## fato_sobre_gato
* fatos_sobre_gatos
- utter_fato_sobre_gatos
- action_cat_facts
action.py
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet
import requests
from random import randint
class ActionCatFacts(Action):
def name(self) -> Text:
return "action_cat_facts"
def run(self, dispatcher, tracker, domain):
if len(tracker.get_slot("fatos_sobre_gatos")) == 0:
req = requests.request('GET', "https://cat-fact.herokuapp.com/facts")
lista = []
for n in range(3):
lista.append(req.json()["all"][n]["text"])
fato = lista[randint(0, 2)]
try:
dispatcher.utter_message("{}".format(fato))
except ValueError:
dispatcher.utter_message(ValueError)
return [SlotSet("fatos_sobre_gatos", lista)]
else:
fato = tracker.get_slot("fatos_sobre_gatos")[randint(0, 2)]
try:
dispatcher.utter_message("{}".format(fato))
except ValueError:
dispatcher.utter_message(ValueError)
return []