Python Rasa-获取用于自定义操作的插槽值

Python Rasa-获取用于自定义操作的插槽值,python,rasa,Python,Rasa,如何在FormAction.slot\u mappings中的对话期间提取slot/实体的值 我在tracker.slots['template\u name']中设置了该值,但无法从此函数访问该值。我可以访问所需的\u插槽中的跟踪器,但不能访问插槽映射 我不想硬编码template\u name=“example”而是想使用template\u name的插槽值 这似乎应该是简单的工作,但我不能 我以为self.from_entity(entity='reqd_form')会给我提供信息,但它

如何在
FormAction.slot\u mappings
中的对话期间提取slot/实体的值

我在
tracker.slots['template\u name']
中设置了该值,但无法从此函数访问该值。我可以访问
所需的\u插槽中的
跟踪器
,但不能访问
插槽映射

我不想硬编码
template\u name=“example”
而是想使用
template\u name
的插槽值

这似乎应该是简单的工作,但我不能

我以为
self.from_entity(entity='reqd_form')
会给我提供信息,但它返回一个空白

从键入导入Dict、Text、Any、List、Union、可选
从rasa_sdk导入跟踪程序
从rasa_sdk.executor导入CollectionDispatcher
从rasa_sdk.forms导入表单
课堂示例形式(形式):
“”“自定义表单操作的示例”“”
def名称(自身)->文本:
“”“表单的唯一标识符”“”
返回“示例表格”
@静力学方法
所需def_插槽(跟踪器:跟踪器)->列表[文本]:
“”“表单必须填写的所需插槽列表”“”
#获取此特定用户所需插槽的列表
slots\u to\u return=util.get\u slots(tracker.slots,tracker.sender\u id)
返回插槽\u至\u返回
def slot_映射(self)->Dict[Text,Union[Dict,List[Dict]]:
“”“将所需插槽映射到的字典”
-摘录
-意图:值对
-完整的信息
或者是他们的名单,在那里第一个匹配将被挑选出来
模板\u name=“示例”
test\u return=get\u slot\u映射(模板名称,self)
返回测试
def提交(
自己
调度程序:正在收集调度程序,
跟踪器:跟踪器,
域:Dict[Text,Any],
)->列表[Dict]:
“”“定义窗体必须执行的操作
在所有必需的插槽填满之后“”
返回[]
def get_插槽_映射(表单名称、表单):
#获取表单所需插槽的列表
slot\u list=util.get\u form\u slot(form\u name)
时隙映射={}
对于插槽列表中的实体项目:
如果(实体项目!=“ice”):
临时列表=[]
临时列表追加(来自实体的表单(实体=实体项目))
temp\u list.append(form.from\u intent(intent=“确认”,value=True))
temp\u list.append(form.from\u intent(intent=“deny”,value=False))
插槽映射[实体项目]=临时列表
返回时隙映射

您可以这样访问插槽值。是否要对提取的值执行更多操作

    return {
        "new_entity": [
            self.from_entity(entity="template_name")
        ]
    }

您可以像这样访问插槽值。是否要对提取的值执行更多操作

    return {
        "new_entity": [
            self.from_entity(entity="template_name")
        ]
    }

要在自定义操作中获取插槽值,您可以执行以下操作:

 from rasa_sdk import Action, Tracker

 class ActionHelloWorld(Action):

 def name(self) -> Text:
     return "action_hello_world"

 def run(self, dispatcher: CollectingDispatcher,
         tracker: Tracker,
         domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

     slot_value = tracker.get_slot('slot_name')

     dispatcher.utter_message(text="Hello World!")

     return []

要在自定义操作中获取插槽值,您可以执行以下操作:

 from rasa_sdk import Action, Tracker

 class ActionHelloWorld(Action):

 def name(self) -> Text:
     return "action_hello_world"

 def run(self, dispatcher: CollectingDispatcher,
         tracker: Tracker,
         domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

     slot_value = tracker.get_slot('slot_name')

     dispatcher.utter_message(text="Hello World!")

     return []