如何在对话期间提取插槽/实体的值FormAction.slot_mappings
?
我在 中设置了值tracker.slots['template_name']
,但无法从此函数访问该值。我可以访问tracker
但required_slots
不能slot_mappings
template_name = "example"
我不想使用硬编码,而是将插槽值用于template_name
.
这看起来应该很容易解决,但我做不到!
通过查看 我认为self.from_entity(entity='reqd_form')
可以为我提供信息的文档,但它返回一个空白。
from typing import Dict, Text, Any, List, Union, Optional
from rasa_sdk import Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormAction
class ExampleForm(FormAction):
"""Example of a custom form action"""
def name(self) -> Text:
"""Unique identifier of the form"""
return "example_form"
@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
"""A list of required slots that the form has to fill"""
#get a list of the slots required for this particular user
slots_to_return = util.get_slots(tracker.slots, tracker.sender_id)
return slots_to_return
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
"""A dictionary to map required slots to
- an extracted
- intent: value pairs
- a whole message
or a list of them, where a first match will be picked"""
template_name = "example"
test_return = get_slot_mappings(template_name, self)
return test_return
def submit(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict]:
"""Define what the form has to do
after all required slots are filled"""
return []
def get_slot_mappings(form_name, form):
#get a list of the slots required for the form
slot_list = util.get_form_slots(form_name)
slot_mappings = {}
for entity_item in slot_list:
if (entity_item != "ice"):
temp_list = []
temp_list.append(form.from_entity(entity=entity_item))
temp_list.append(form.from_intent(intent="affirm", value=True))
temp_list.append(form.from_intent(intent="deny", value=False))
slot_mappings[entity_item] = temp_list
return slot_mappings