본문으로 바로가기

라사(Rasa) 튜토리얼 -3 : Actions 소개

category Bot 2020. 8. 8. 22:54

Actions

 

라사는 사용자 입력에 대한 응답으로 다음 4가지의 응답 유형을 제공합니다.

  • Utterance actions: domain.yml 에 정의된 응답

  • Retrieval actions:  단일 질의에 대한 응답

  • Custom actions: 파이썬을 코드로 작성하는 응답

  • Default actions: 라사에서 제공하는 default action

 

Actions

Learn about about how to write your own custom actions with the open source Rasa framework to be able to interact with the external world - ranging from databases to third-party APIs.

rasa.com

 

Utterance Actions

 

domain.yml 에 정의하는 수동적인 응답입니다.

responses:
  utter_greet:
  - text: "안녕 인간"
  - text: "반갑다 인간"

  utter_cheer_up:
  - text: "힘내라 인간"
  - text: "나도 힘들다 인간"

 

Retreival Actions

 

공식문서에서는 Small Talk and Simple Question 에 사용한다고 설명하고 있습니다.

잡담이나 대화 흐름에 동떨어진 작은 질문들을 처리한다고 생각하시면 되겠습니다.

 

Retrieval Actions

Use a retrieval model to select chatbot responses in open source bot framework Rasa.

rasa.com

 

사용방법

 

사용방법이 조금 까다롭습니다.

작은 규모의 챗봇을 제작하시고자 한다면 비추천하구요.

Utterance action 으로 감당이 되지 않을 경우에만 사용하시면 될 것 같습니다.

 

 

두 개의 retreival action 에 대한 설정 예시입니다.

 

nlu.md

## intent: faq/ask_me
- 소개해봐
- 너에 대해 소개해
- 라사 소개

...

## intent: chitchat/age
- 몇 살이야 ? 
- 나이는 ?

 

stories.md

## faq
* faq
  -respond_faq

## chitchat
* chitchat
  - respond_chitchat

 

responses.md (생성)

## ask me
* faq/ask_me
    - 라사는 텍스트 및 음성 기반 대화를 자동화 하는 프레임워크이다.

## ask channel 
* faq/ask_channel
    - Facebook Messenger, Telegram ...

## chitchat
* chitchat/funny
    - 웃지마

## age
* chitchat/age
    - 21살

## loc
* chitchat/loc
    - 서울

 

domain.yml

intents:
  ....
  - chitchat
  - faq

...

actions:
  - respond_faq
  - respond_chitchat

 

config.yml

....

  - name: ResponseSelector
    retrieval_intent: faq
  - name: ResponseSelector
    retrieval_intent: chitchat  
    
...

 

 

지난 포스팅에 이어 Retreival action 을 추가한 결과입니다.

 

 

 

Custom Actions

 

파이썬 코드로 작성하는 응답이므로 크롤링, DB 연동 등 다양한 활용이 가능하므로 필수적인 요소입니다.

 

 

사용방법

 

endpoints.yml 파일의 해당되는 부분의 주석을 제거합니다.

 

 

rasa init 으로 생기는 actions.py 입니다.

def name 함수에서 리턴되는 "action_hello_world" 부분이 응답 이름으로

stories, domain.yml 에 명시해야합니다.

# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/core/actions/#custom-actions/


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher


class ActionHelloWorld(Action):

    def name(self) -> Text:
        return "action_hello_world"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        dispatcher.utter_message(text="Hello World!")

        return []

 

사용하기 위해서는 action server 를 구동시켜야 합니다.

rasa run actions
2020-08-08 22:49:36 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2020-08-08 22:49:36 INFO     rasa_sdk.executor  - Registered function for 'action_hello_world'.
2020-08-08 22:49:36 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http://localhost:5055

 

 

stories.md, domain.yml 에도 각각 정의했구요.

 

 

 

Default Actions

 

default action 은 다음과 같은 기능들을 제공하구요.

필요에 따라 더 자세하게 포스팅하도록 하겠습니다.

 

https://rasa.com/docs/rasa/core/actions/#retrieval-actions