Hi I have a use case where I need to reset every slot but the ones provided in the last user message. Code:
class ActionEspecialidad(Action):
def name(self):
return 'action_especialidad'
def run(self, dispatcher, tracker, domain):
print(tracker.current_slot_values())
keep_slots = last_message_slots(tracker.latest_message.text)
for key, _ in tracker.current_slot_values().items():
if key in keep_slots:
continue
else:
tracker._set_slot(key=key, value=None)
print(tracker.current_slot_values())
response = build_responses(tracker)
dispatcher.utter_message('$' + response)
# dispatcher.utter_message(especialidad)
return [SlotSet('especialidad', tracker.get_slot('especialidad'))]
def last_message_slots(message):
from rasa_core.interpreter import RasaNLUInterpreter
interpreter = RasaNLUInterpreter('/'.join([model_dir, project_name, fixed_model_name]))
stuff = interpreter.parse(message)
entities = [x['entity'] for x in stuff['entities']]
return entities
I know that exists something called reset_slots, but this reset every slot and I want to keep the ones on the last message. Does anyone know another approach? This one works but there is probably a better one.