RASA - 규칙 및 테스트 양식

7021 단어 chatbotairasanlp
에서 우리는 회보 양식을 만들고 그것에 대한 이야기를 썼습니다. 이것이 효과가 있었지만 구독 의도가 인식될 때 양식 루프를 호출하는 더 좋은 방법이 있습니다.

그러나 변경하기 전에 양식에 대한 테스트를 작성하여 변경하려는 변경 사항이 아무 것도 손상시키지 않는지 확인하십시오.

테스트 양식 행복 경로

Let's add the following test story to our tests/test_stories.yml file.

# tests/test_stories.yml
# ... previous contents ...
  - story: newsletter form happy path
    steps:
      - user: |
          hi
        intent: greet
      - action: utter_greet
      - user: |
          I want to subscribe
        intent: subscribe
      - action: newsletter_form
      - active_loop: newsletter_form
      - user: |
          my email is [[email protected]](email)
        intent: inform_email
      - action: newsletter_form
      - user: |
          twice a week
        intent: inform_frequency
      - action: newsletter_form
      - active_loop: null
      - action: utter_subscribed

Let's go though this test line by line.

  • First, we are saying, that when a user writes "hi", it should be classified as greet intent, followed by utter_greet action.
  • Then, when user writes "I want to subscribe", it should be classified as subscribe intent, followed by newsletter_form action and newsletter_form should be activated.
  • Then, user writes "my email is [email protected] ". 이것은 inform_email intent로 분류되어야 하며 또한 [email protected] 이 메시지에서 email entity로 분류되어야 합니다.
  • inform_email 다음에 또 다른 newsletter_form 작업(이메일 빈도 요청)이 와야 합니다.
  • 그런 다음 사용자가 "주 2회"라고 쓰면 inform_frequency 인텐트로 분류되어야 합니다.
  • 이 시점에서 양식의 모든 슬롯이 채워지고 양식이 - action: newsletter_form- active_loop: null 로 끝나야 합니다.
  • 그러면 챗봇이 utter_subscribed 작업을 수행하여 구독 세부 정보를 알려야 합니다.
  • rasa test 를 실행하여 테스트가 통과하는지 확인하십시오.
    이제 개선 사항으로 돌아가 봅시다!

    규칙



    규칙은 대화에서 이전에 말한 내용에 관계없이 항상 동일한 경로를 따라야 하는 대화 부분을 설명합니다.
    우리는 어시스턴트가 항상 특정 작업으로 특정 의도에 응답하기를 원하므로 규칙을 사용하여 해당 작업을 의도에 매핑합니다.
    우리의 경우 사용자가 구독 의도를 표현할 때마다 newsletter_form을 트리거하려고 합니다.

    # data/rules.yml
    version: "2.0"
    
    rules:
      - rule: activate subscribe form
        steps:
          - intent: subscribe
          - action: newsletter_form
          - active_loop: newsletter_form
    

    또한 모든 필수 정보가 제공되면 utter_subscribed 작업을 트리거하려고 합니다.

    # data/rules.yml
    # ... previous contents ...
      - rule: submit form
        condition:
          - active_loop: newsletter_form
        steps:
          - action: newsletter_form
          - active_loop: null
          - action: utter_subscribed
    

    제출 양식 규칙은 처음부터 newsletter_form이 활성화된 경우에만 적용됩니다. 더 이상 활성화되지 않으면( - active_loop: null ) 양식이 완성됩니다.

    이제 인사 및 구독 스토리가 더 이상 필요하지 않으며 data/stories.yml에서 삭제할 수 있습니다.
    rasa test를 실행하면 두 테스트 모두 통과했음을 알 수 있습니다!

    그러나 규칙은 보이지 않는 대화로 일반화되지 않습니다. 단일 전환 대화 스니펫용으로 예약하고 스토리를 사용하여 다중 전환 대화를 훈련해야 합니다. 자세한 내용은 documentation .

    documentation에서 규칙에 대해 자세히 알아볼 수 있습니다.

    다음 장에서는 불행한 경로를 처리하는 방법을 살펴보겠습니다.

    이 튜토리얼의 저장소:


    펫7555 / rasa-dev-튜토리얼






    이 튜토리얼의 끝에서 다음을 실행하여 리포지토리의 상태를 체크아웃할 수 있습니다.

    git clone --branch 04-rules-and-testing-forms [email protected]:petr7555/rasa-dev-tutorial.git
    

    좋은 웹페이지 즐겨찾기