无法填充话语模板Rasa聊天机器人

2024-04-28 12:20:51 发布

您现在位置:Python中文网/ 问答频道 /正文

首先运行命令rasa run actions,然后运行rasa train,然后运行rasa x。我犯了一个错误

无法填充话语模板“玩游戏[]{mario_link}”。试图替换“mario_链接”,但找不到该链接的值。没有具有此名称的插槽,也没有在调用模板时显式传递值。返回模板而不填充模板

domain.yml文件

session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true
intents:
- mario
responses:
  utter_game_mario:
  - text: Play the game [ ] {mario_link}
actions:
- action_mario

actions.py文件

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher


class ActionHelloWorld(Action):
    def name(self) -> Text:
        return "action_mario"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
            # dispatcher.utter_message(text="Hello World!")

            link = "https://supermarioemulator.com/supermario.php"

            dispatcher.utter_template("utter_game_mario", tracker, link=link)
            return []

nlu.md文件

## intent:mario
- i want to play mario
- start mario
- play mario

endpoints.yml文件

action_endpoint:
  url: "http://localhost:5055/webhook"

stories.md文件

## game
* mario
    - action_mario

我使用了这些参考资料,但不适用于我:

  • 重新安装Rasa的最新版本:https://forum.rasa.com/t/getting-an-error-while-using-custom-output-payload/11802

  • 不知道这里的解决方案是什么:https://github.com/RasaHQ/rasa/issues/4550

  • 这没有任何意义:https://github.com/RasaHQ/rasa/pull/4079/files/6c14ab262e915369915876425670843ab348201e

  • 请帮忙。为什么我会犯这个错误


    Tags: 文件textfromhttpsimportcomactions模板
    2条回答

    进行以下更改,它应该可以工作

    域中。yml:

    - text: Play the game {mario_link}
    

    在动作中。py

    添加这一行

    tracker.get_slot('mario_link')
    

    换一个

    dispatcher.utter_template("utter_game_mario", tracker, mario_link=link)
    

    但我个人会做的是,在这里根本不使用utter_响应,而是使用动作并使用dispatcher.utter_message()打印答案。

    完全的反应不应该是动态的。使用动作本身创建动态响应

    相关问题 更多 >