Hi, i have problem with rasa : My database class in python file actions.py seems to work correctly alone. even only using dictionnary instead of database, rasaBot work with no problem. The only issue is when i try to use database on a custom action function :
Your input -> hi
hey
Your input -> which teachers are absent?
2022-12-08 22:44:57.234565: E tensorflow/core/framework/node_def_util.cc:630] NodeDef mentions attribute epsilon which is not in the op definition: Op<name=_MklFusedBatchMatMulV2; signature=x:T, y:T, args:num_args*T -> output:T; attr=T:type,allowed=[DT_BFLOAT16, DT_FLOAT]; attr=adj_x:bool,default=false; attr=adj_y:bool,default=false; attr=num_args:int,min=0; attr=fused_ops:list(string),default=[]> This may be expected if your graph generating binary is newer than this binary. Unknown attributes will be ignored. NodeDef: {{node rasa_sequence_layer_text/text_encoder/transformer_encoder_layer/multi_head_attention/add}}
2022-12-08 22:44:59 ERROR rasa.core.processor - Encountered an exception while running action 'which_teachers_are_absent'.Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.
Traceback (most recent call last):
File "C:\Users\test\anaconda3\envs\rasaenv\lib\site-packages\rasa\core\actions\action.py", line 741, in run
response: Any = await self.action_endpoint.request(
File "C:\Users\test\anaconda3\envs\rasaenv\lib\site-packages\rasa\utils\endpoints.py", line 173, in request
raise ClientResponseError(
rasa.utils.endpoints.ClientResponseError: 500, Internal Server Error, body='b'{"error":"local variable \'cursor\' referenced before assignment","request_body":{"next_action":"which_teachers_are_absent","sender_id":"f6c8fb450bbf4d759cc718262cd76239","tracker":{"sender_id":"f6c8fb450bbf4d759cc718262cd76239","slots":{"liste_profs":null,"session_started_metadata":null},"latest_message":{"intent":{"name":"demander_profs_absents","confidence":1.0},"entities":[],"text":"profs","message_id":"838491fa19164f97868d1bdd9074e9e9","metadata":{},"text_tokens":[[0,5]],"intent_ranking":[{"name":"demander_profs_absents","confidence":1.0},{"name":"salutation","confidence":9.6885177658379e-10}],"response_selector":{"all_retrieval_intents":[],"default":{"response":{"responses":null,"confidence":0.0,"intent_response_key":null,"utter_action":"utter_None"},"ranking":[]}}},"latest_event_time":1670535897.598957,"followup_action":null,"paused":false,"events":[{"event":"action","timestamp":1670535897.0299563,"metadata":{"model_id":"57c862b908fa4021afc82758d4d6cd07"},"name":"action_session_start","policy":null,"confidence":1.0,"action_text":null,"hide_rule_turn":false},{"event":"session_started","timestamp":1670535897.0299563,"metadata":{"model_id":"57c862b908fa4021afc82758d4d6cd07"}},{"event":"action","timestamp":1670535897.0299563,"metadata":{"model_id":"57c862b908fa4021afc82758d4d6cd07"},"name":"action_listen","policy":null,"confidence":null,"action_text":null,"hide_rule_turn":false},{"event":"user","timestamp":1670535897.2399557,"metadata":{"model_id":"57c862b908fa4021afc82758d4d6cd07"},"text":"profs","parse_data":{"intent":{"name":"demander_profs_absents","confidence":1.0},"entities":[],"text":"profs","message_id":"838491fa19164f97868d1bdd9074e9e9","metadata":{},"text_tokens":[[0,5]],"intent_ranking":[{"name":"demander_profs_absents","confidence":1.0},{"name":"salutation","confidence":9.6885177658379e-10}],"response_selector":{"all_retrieval_intents":[],"default":{"response":{"responses":null,"confidence":0.0,"intent_response_key":null,"utter_action":"utter_None"},"ranking":[]}}},"input_channel":"cmdline","message_id":"838491fa19164f97868d1bdd9074e9e9"},{"event":"user_featurization","timestamp":1670535897.598957,"use_text_for_featurization":false}],"latest_input_channel":"cmdline","active_loop":{},"latest_action":{"action_name":"action_listen"},"latest_action_name":"action_listen"},"domain":{"version":"3.1","intents":["demander_profs_absents","salutation"],"slots":{"liste_profs":{"type":"text","influence_conversation":false,"mappings":[{"type":"custom"}]}},"responses":{"utter_salutation":[{"text":"salut!"},{"text":"hey"}]},"actions":["which_teachers_are_absent"],"session_config":{"session_expiration_time":60,"carry_over_slots_to_new_session":true}},"version":"3.3.1"}}''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\test\anaconda3\envs\rasaenv\lib\site-packages\rasa\core\processor.py", line 874, in _run_action
events = await action.run(
File "C:\Users\test\anaconda3\envs\rasaenv\lib\site-packages\rasa\core\actions\action.py", line 765, in run
raise RasaException(
rasa.shared.exceptions.RasaException: Failed to execute custom action 'which_teachers_are_absent'
Your input ->
Here is my action class :
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher
import mysql.connector
class ActionHelloWorld(Action):
def name(self) -> Text:
return "which_teachers_are_absent"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
bd = ProfAbsentRepository()
list_profs_abs = ProfAbsentRepository.get_list_prof_absent(bd)
message = ""
for prof in list_profs_abs:
message += prof + "\n"
dispatcher.utter_message("list of absent teachers : "+message)
return [SlotSet("liste_teachers", message)]
class ProfAbsentRepository:
connection = mysql.connector.connect(host='localhost', user='root', passwd='***', database='***')
def get_list_prof_absent(self):
print("connecté")
list_prof_absent = []
cursor = self.connection.cursor()
query = 'SELECT nom, prenom FROM q210108.prof;'
cursor.execute(query)
rows = cursor.fetchall()
for row in rows:
list_prof_absent.insert(-1, row)
print(list_prof_absent)
self.connection.commit()
self.connection.close()
return list_prof_absent
The error in console of command rasa run actions
:
<class 'Exception'>
2022-12-08 22:36:40 ERROR rasa_sdk.endpoint - Exception occurred during execution of request <Request: POST /webhook>
Traceback (most recent call last):
File "handle_request", line 83, in handle_request
)
File "C:\Users\neutr\anaconda3\envs\rasaenv\lib\site-packages\rasa_sdk\endpoint.py", line 104, in webhook
result = await executor.run(action_call)
File "C:\Users\neutr\anaconda3\envs\rasaenv\lib\site-packages\rasa_sdk\executor.py", line 398, in run
action(dispatcher, tracker, domain)
File "C:\Users\neutr\Documents\Fichier\ecole\Helmo\salto\chatBotTest\helmoChatBot\Rasa\actions\actions.py", line 17, in run
list_profs_abs = ProfAbsentRepository.get_list_prof_absent(bd)
File "C:\Users\neutr\Documents\Fichier\ecole\Helmo\salto\chatBotTest\helmoChatBot\Rasa\actions\actions.py", line 37, in get_list_prof_absent
UnboundLocalError: local variable 'cursor' referenced before assignment