Skip to content

Forms

forms là một loại hành động giúp ta thu thập thông tin cần thiết từ người dùng. Ta có thể hiểu nó như một loop hỏi thông tin cho tới khi nào có đủ.

Để sử dụng forms ta cần phải có RulePolicy trong mục policies:

policies:
- name: RulePolicy

Định nghĩa Form

Bạn sẽ cần chỉ định danh sách các slot cho khóa bắt buộc required_slots.

entites:
  - name
  - email
slots:
  name:
    type: any
    mappings:
      - type: from_entity
        entity: name
  email:
    type: any
    mappings:
      - type: from_entity
        entity: email
forms:
  consultant_form:
    required_slots:
      - name
      - email

Kích hoạt Form

Để kích hoạt form bạn cần thêm story hoặc rule để đặt điều kiện kích hoạt form.

rules:
  - rule: Activate consultant form
    steps:
      - intent: consultant
      - action: consultant_form
      - active_loop: consultant_form

Tắt Form

Form sẽ tự động tắt khi tất cả required_slots có giá trị. Bạn có thể định nghĩa hành động của bot sau khi form kêt thúc.

Trong ví dụ dưới, chatbot sẽ thực hiện hành động utter_submit ngay sau khi các required_slots có giá trị.

  - rule: Submit consultant form
    condition:
      # Condition that form is active.
      - active_loop: consultant_form
    steps:
      # Form is deactivated
      - action: consultant_form
      - active_loop: null
      - slot_was_set:
          - requested_slot: null
      # The actions we want to run when the form is submitted.
      - action: utter_submit

❓ Muốn biết thêm chi tiết hay có câu hỏi nào?

Hãy lên website của RASA hoặc RASA Community Forum