Rasa2.x机器人实现《买瓜》完整代码

结果

Rasa2.x机器人实现《买瓜》完整代码

第一次安装

参考https://rasa.com/docs/rasa/installation

注意:
1.最好不要装在C盘,虚拟环境占用的空间很大
2.虚拟环境不能随意移动,移动后无法运行
3.首先按提示更新pip版本再pip install rasa, 否则会报错
4.rasa init 出现问题,需要pip uninstall keras, pip install keras==2.6.0

使用

cmd
.\venv\Scripts\activate	启动虚拟环境
cd E:\python_exercise\RasaVenv\rasa_project1	进入项目
rasa shell	加载模型 开启回话
rasa train  训练

实例

问句

- intent: buy_watermelon
  examples: |
    - 你这瓜多少钱一斤啊?
    - 哥们儿 这瓜多少钱一斤呐
    - 哥们儿,这瓜多少钱一斤呐?
    
- intent: mood_expensive
  examples: |
    - what's up,这瓜皮子是金子做的,还是瓜粒子是金子做的?
    - what's up 这瓜皮子是金子做的 还是瓜粒子是金子做的
    
- intent: mood_choose
  examples: |
    - 给我挑一个
    
- intent: mood_mature1
  examples: |
    - 这瓜保熟吗?
    
- intent: mood_mature2
  examples: |
    - 我问你这瓜保熟吗?
    
- intent: mood_notMature
  examples: |
    - 你这瓜要熟我肯定要啊?那它要是不熟怎么办呀?  
    - 要熟我肯定要啊
    
- intent: mood_scale
  examples: |
    - 你这哪够十五斤哪?
    - 你这哪够十五斤哪?你这称有问题呀。
    
- intent: mood_magnet
  examples: |
    - 吸铁石 另外你说的 这瓜要是生的 你自己吞进去 啊。

机器人答句

intents:
  - buy_watermelon
  - mood_expensive
  - mood_choose
  - mood_mature1
  - mood_mature2
  - mood_notMature
  - mood_scale
  - mood_magnet

  utter_watermelon_money:
  - text: "两块钱一斤"
  
  utter_answer_expensive:
  - text: "你瞧瞧这现在哪有瓜呀?这都是大棚的瓜,你贤惠我还贤惠呢。"
  
  utter_answer_yes:
  - text: "行(转身挑瓜)"

  utter_give_one_melon:
  - text: "(咚咚咚)这个怎么样?"
  
  utter_answer_mature1 :
  - text: "我开水果摊儿的,能卖给你生瓜蛋子啊"
  
  utter_answer_mature2:
  - text: "你是故意找岔儿是不是?你要不要吧!"
  
  utter_answer_not_mature:
  - text: "(指西瓜)哎,要是不熟,我自己吃了它,满意了吧?"
  
  utter_count_money:
  - text: "(把瓜放到称上,扒拉了一下秤砣)15斤,30块。"
  
  utter_buy_or_not:
  - text: "你**故意找茬儿是不是?你要不要吧?你要不要?"

  utter_cut:
  - text: "你**劈我瓜是吧,我……"
  
  utter_kill:
  - text: "萨日朗!萨日朗!"

编写story:

- story: Buy watermelon
  steps:
  - intent: buy_watermelon
  - action: utter_watermelon_money
  - intent: mood_expensive
  - action: utter_answer_expensive
  - intent: mood_choose
  - action: utter_answer_yes
  - action: utter_give_one_melon
  - intent: mood_mature1
  - action: utter_answer_mature1 
  - intent: mood_mature2
  - action: utter_answer_mature2
  - intent: mood_notMature
  - action: utter_answer_not_mature
  - action: utter_count_money
  - intent: mood_scale
  - action: utter_buy_or_not
  - intent: mood_magnet
  - action: utter_cut
  - action: utter_kill
 

训练,然后就可以会话了!
参考: https://blog.csdn.net/AndrExpert/article/details/104328946?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163713716416780357245411%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=163713716416780357245411&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-104328946.first_rank_v2_pc_rank_v29&utm_term=rasa&spm=1018.2226.3001.4187

上一篇:怎么使用github action定时运行js脚本?


下一篇:React-Hooks中的useReducer