Rasa入门笔记2-使用nlu单独提取出意图与词槽

Rasa入门笔记2-使用nlu单独提取出意图与词槽

    • 1、提取方法
    • 2、服务启动

1、提取方法

①在actions.py文件中使用tracker.latest_message方法获取到输入信息的意图与实体的所有信息。

代码示例:

#coding:utf-8
from typing import Text, Dict, Any
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from py2neo import Graph
import json,re,pickle
from rasa_sdk.events import SlotSet,AllSlotsReset
from markdownify import markdownify as md
from rasa_sdk.events import UserUtteranceReverted


class ActionSearchGarbage(Action):
    def name(self) -> Text:
        return "action_search_garbage"

    # 查找垃圾
    def run(self, dispatcher, tracker,domain):
        result = {
     }
        dic = {
     }
        entities = []

        #获得nlu数据(意图和词槽数据)
        content = tracker.latest_message
        # print('=====>', content)
        
        #传送nlu数据
        dispatcher.utter_message("{0} ".format(content ))

        # return [SlotSet("user_garbage", garbage)]
        return []

2、服务启动

①rasa项目建立与配置参考:https://jiangdg.blog.csdn.net/article/details/104328946

启动:

Action服务启动(端口号默认5005,可省略):

rasa run actions --port 5055 --actions actions --debug

Rasa服务启动(端口号默认5005,可省略):

rasa run --port 5005 --endpoints endpoints.yml --credentials credentials.yml --debug

你可能感兴趣的:(Rasa系列,自然语言处理,机器学习)