Rasa 2.8 开发指南
Rasa是一个开源聊天机器人框架,使用python编写,在大数据时代,Rasa可以很方便的集成很多机器学习和NLP的组件
初始化机器人项目
rasa init
自定义action
在项目的action文件夹下,找到action.py文件。
自定义一个类:
from rasa_sdk import Action
class ActionItemShow(Action):
def name(self):
# define the name of the action which can then be included in training stories
return "item_show"
def run(self, dispatcher, tracker, domain):
# what your action should do
dispatcher.utter_message('展示一个Item') #send the message back to the user
return []
在domain.yml中申明这个action:(domain.yml是一些全局变量的声明文件)
actions:
- item_show
在data的stories文件夹下找到stories.yml:(stories.yml是具体对话的流程配置)
- story: search item 1
steps:
- intent: item_search_by_code
entities:
- name: item_code
- action: utter_item_search
- intent: affirm
- action: item_show
在/data/nlu.yml中定义好intent:(nlu.yml是聊天意图判断的配置文件)
- intent: item_search_by_code
examples: |
- 我想查[412342](item_code)这个单品
- 我想查[412342](item_code)这个item
- 帮我查一下[412342](item_code)这个item
- 帮我查一下[412342](item_code)这个单品
- 我想查[412342](item_code)这个item code
- 帮我查一下[412342](item_code)这个item code
- 帮我查一下[412342](item_code)这个单品code
- 我想查[412342](item_code)这个单品code
- 帮我查一个ITEM[412342](item_code)
在endpoint.yml中定义好action服务器:(endpoint.yml 是各种外部资源的配置文件)
action_endpoint:
url: "http://localhost:5055/webhook"
运行
由于使用了自定义action,所以必须先启动自定义action server。然后可以执行rasa shell来进行会话。
rasa run actions
rasa shell