Reputation: 13
This is my actions.py file :-
from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher from rasa_sdk.events import SlotSet import json
class ActionHr(Action): def name(self): print('in self method') return 'action_leave'
def run (self, dispatcher, tracker, domain):
print('in run method')
i = tracker.get_slot('name')
print(i)
with open('data1.txt') as json_file:
data = json.loads(json_file.read())
for result in data['current']:
print('name'+ result['name'])
if result['name'].lower() == i.lower():
print('name Found')
name = result['name']
SickLeave = result['Sick Leaves']
CasualLeave = result['Casual Leaves']
TotalLeave = result['Total Leaves']
LeavesLeft = result['Leaves Left']
response ="""The Leaves left for name {} is {} . You took {} casual leaves and {} sick leaves.""".format(SickLeave,CasualLeave,TotalLeave)
print(response)
dispatcher.utter_message(response)
return [SlotSet('name',i)]
and this is my json file :
{ "current": [ { "name": "Vedant", "Sick Leaves": 3, "Casual Leaves": 1, "Total Leaves": 4, "Leaves Left": 14 }, { "name": "Debasmita", "Sick Leaves": 1, "Casual Leaves": 5, "Total Leaves": 6, "Leaves Left": 12 }, { "name": "Akoparna", "Sick Leaves": 4, "Casual Leaves": 2, "Total Leaves": 6, "Leaves Left": 12 }, { "name": "Ankita", "Sick Leaves": 1, "Casual Leaves": 0, "Total Leaves": 1, "Leaves Left": 17 }, { "name": "Sana", "Sick Leaves": 0, "Casual Leaves": 6, "Total Leaves": 6, "Leaves Left": 12 } ] }
when I am running both rasa run actions and rasa shell , I am getting this error when I'm trying to get the leave details for the input name ..
Here is my error :
in run method Debasmita nameVedant nameDebasmita name Found nameAkoparna nameAnkita nameSana Exception occurred while handling uri: 'http://localhost:5055/webhook' Traceback (most recent call last): File "c:\users\debasmita\anaconda3\envs\hr\lib\site-packages\sanic\app.py", line 976, in handle_request response = await response File "c:\users\debasmita\anaconda3\envs\hr\lib\site-packages\rasa_sdk\endpoint.py", line 102, in webhook result = await executor.run(action_call) File "c:\users\debasmita\anaconda3\envs\hr\lib\site-packages\rasa_sdk\executor.py", line 387, in run events = action(dispatcher, tracker, domain) File "E:\New\actions.py", line 57, in run response ="""The Leaves left for name {} is {} . You took {} casual leaves and {} sick leaves.""".format(SickLeave,CasualLeave,TotalLeave) IndexError: tuple index out of range
Please help me .
Upvotes: 1
Views: 249
Reputation: 937
The problem seems to be in the line where you try to 'format' the result:
response ="""The Leaves left for name {} is {} . You took {} casual leaves and {} sick leaves.""".format(SickLeave,CasualLeave,TotalLeave)
Please notice that you have 4 curly brackets and just 3 arguments, so the replacement process using 'format' can not be completed, I reproduced the error as follow:
Please try to add the missing argument to see if the error persists.
Upvotes: 0