python rasa聊天机器人教程四:action查询今天是星期几

1.修改nlm.yml

添加意图

1
2
3
4
5
- intent: ask_day
  examples: |
    - 今天是星期几?
    - 今天星期几?
    - 现在是星期几?

2.修改domain.yml

intents里面增加

1
2
intents:
  - ask_day

 actions里面增加

1
2
actions:
- action_get_day

 3.修改rules.yml

1
2
3
4
- rule: respond to day queries
  steps:
  - intent: ask_day
  - action: action_get_day

 4.修改endpoints.yml

增加

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

 

 5.修改actions.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.训练和启动交互模型

命令行中执行训练命令

1
rasa train

 启动rasa动作服务器

1
rasa run actions

 再打开新的命令行(进去项目目录)

 启动rasa

1
rasa shell --endpoints endpoints.yml

 7.测试

1
2
3
4
5
6
Your input ->  hi
Hey! How are you?
Your input ->  你是谁
我是一个AI机器人。
Your input ->  今天星期几
今天是星期四。

8.在网页里面测试

停止rasa 输入/stop

然后启动rasa

1
rasa run --enable-api --cors '*'

 然后打开浏览器输入

http://localhost:8800/

输入测试语句测试

 

posted @   繁华博客  阅读(188)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
点击右上角即可分享
微信分享提示