1.修改nlm.yml
添加意图
- intent: ask_day examples: | - 今天是星期几? - 今天星期几? - 现在是星期几?
2.修改domain.yml
intents里面增加
intents: - ask_day
actions里面增加
actions: - action_get_day
3.修改rules.yml
- rule: respond to day queries steps: - intent: ask_day - action: action_get_day
4.修改endpoints.yml
增加
action_endpoint: url: "http://localhost:5055/webhook"
5.修改actions.py
from datetime import datetime from rasa_sdk import Action class ActionGetDay(Action): def name(self) -> str: return "action_get_day" def run(self, dispatcher, tracker, domain): days_in_chinese = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] today = datetime.now().weekday() # 这会返回0(星期一)到6(星期日) response = "今天是" + days_in_chinese[today] + "。" dispatcher.utter_message(text=response) return []
6.训练和启动交互模型
命令行中执行训练命令
rasa train
启动rasa动作服务器
rasa run actions
再打开新的命令行(进去项目目录)
启动rasa
rasa shell --endpoints endpoints.yml
7.测试
Your input -> hi Hey! How are you? Your input -> 你是谁 我是一个AI机器人。 Your input -> 今天星期几 今天是星期四。
8.在网页里面测试
停止rasa 输入/stop
然后启动rasa
rasa run --enable-api --cors '*'
然后打开浏览器输入
http://localhost:8800/
输入测试语句测试
标签:星期,rasa,python,actions,day,action,yml From: https://www.cnblogs.com/fanhua999/p/17638554.html