Domain file
intents:
- FAQ_process
entities:
- subject
slots:
subject:
type: text
auto_fill: true
influence_conversation: false
requested_slot:
type: text
influence_conversation: false"
forms:
subject_form:
required_slots:
subject:
- type: from_entity
entity: subject
actions:
- validate_subject_form
- FAQ_process_response
Stories
- story: Process related queries-1
steps:
- intent: greet
- action: utter_greet
- intent: FAQ_process
entities:
- subject: CHEA
- action: subject_form
- active_loop: subject_form
- active_loop: null
- action: FAQ_process_response
Action file
from typing import Dict, Text, Any, List, Union, Optional
from rasa_sdk import Action, Tracker, FormValidationAction
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet, ConversationPaused
from joblib import load
import numpy as np
import pandas as pd
class ValidateSubjectForm(FormValidationAction):
def name(self) -> Text:
"""Unique identifier of the form"""
return "validate_subject_form"
# validate user answers
@staticmethod
def subject_db() -> Dict[str, List]:
return {
"subject": ["children education advance", "Training need assessment", "Multi-purpose advance"]
}
def validate_subject(
self,
slot_value: Any,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate user input."""
if slot_value.lower() in self.subject_db()['subject']:
# validation succeeded, set the value of the slot to
# user-provided value
print(slot_value)
return {"subject": slot_value}
else:
return {"subject": "other"}
Output of rasa shell --debug
"2022-04-03 17:54:53 DEBUG rasa.core.actions.forms - Activated the form 'subject_form'.
2022-04-03 17:54:53 INFO rasa.shared.core.trackers - Tried to access non existent slot 'required_slots'
2022-04-03 17:54:53 DEBUG rasa.core.actions.forms - No pre-filled required slots to validate.
2022-04-03 17:54:53 DEBUG rasa.core.actions.forms - Validating user input 'UserUttered(text: How to apply for children education advance, intent: {'id': -4416616158840011380, 'name': 'FAQ_process', 'confidence': 0.9999997615814209}, entities: [{'entity': 'subject', 'start': 17, 'end': 43, 'confidence_entity': 0.8777869939804077, 'value': 'children education advance', 'extractor': 'DIETClassifier'}])'.
2022-04-03 17:54:53 ERROR rasa.core.processor - Encountered an exception while running action 'subject_form'.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:\anaconda3\envs\rasax33\lib\site-packages\rasa\core\processor.py", line 681, in _run_action
events = await action.run(output_channel, nlg, tracker, self.domain)
File "c:\anaconda3\envs\rasax33\lib\site-packages\rasa\core\actions\loops.py", line 29, in run
events += await self.do(output_channel, nlg, tracker, domain, events)
File "c:\anaconda3\envs\rasax33\lib\site-packages\rasa\core\actions\forms.py", line 653, in do
events = await self._validate_if_required(tracker, domain, output_channel, nlg)
File "c:\anaconda3\envs\rasax33\lib\site-packages\rasa\core\actions\forms.py", line 593, in _validate_if_required
return await self.validate(tracker, domain, output_channel, nlg)
File "c:\anaconda3\envs\rasax33\lib\site-packages\rasa\core\actions\forms.py", line 441, in validate
slot_values = self.extract_other_slots(tracker, domain)
File "c:\anaconda3\envs\rasax33\lib\site-packages\rasa\core\actions\forms.py", line 275, in extract_other_slots
slot_mappings = self.get_mappings_for_slot(slot, domain)
File "c:\anaconda3\envs\rasax33\lib\site-packages\rasa\core\actions\forms.py", line 107, in get_mappings_for_slot
raise TypeError("Provided incompatible slot mapping")
TypeError: Provided incompatible slot mapping
2022-04-03 17:54:53 DEBUG rasa.core.processor - Action 'subject_form' ended with events '[]'.
Please review my code. I am not getting any solution