首页 > 解决方案 > 我正在实施一个行动表单来收集一些处理所需的所有数据,但我收到了这个错误:

问题描述

在此处输入图像描述

当我运行动作时,这是一个问题。插槽提取失败。

enter image description here

enter code here 

动作.py

from rasa_sdk.forms import FormAction
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from typing import Any, Text, Dict, List

class flightForm(FormAction):
    "Collects sales information and adds it to the spreadsheet"

    def name(self):
        return "flight_form"
    @staticmethod
    def required_slots(tracker):
        return [
         
            "from",
            "to",
            "Departure_date",
            "Arrival_date",
            "Ticket_type",
            "airlines",
            "class",
            "fare_price",
            "payment_mode"
            ]
    def submit(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[Dict]:
        dispatcher.utter_message("Thanks for getting in touch, we’ll contact you soon")
        return []

nlu.md

## intent:greet
- hey
- hello
- hi
- good morning
- good evening
- hey there

## intent:goodbye
- bye
- goodbye
- see you around
- see you later


## intent:mood_great
- perfect
- very good
- great
- amazing
- wonderful
- I am feeling very good
- I am great
- I'm good

## intent:mood_unhappy
- sad
- very sad
- unhappy
- bad
- very bad
- awful
- terrible
- not very good
- extremely sad
- so sad

## intent:bot_challenge
- are you a bot?
- are you a human?
- am I talking to a bot?
- am I talking to a human?

## intent:Book_flight
- I want to book a flight
- I want to book a flight from USA to China
- I want a flight
- I need flight

## intent:cancel
- I want to cancel a flight
- Cancel my flight

## intent:inform
- [DEL](location)
- [MUM](location)
- [BAN](location)
- [09-01-2019](Departure_date)
- [09-04-2019](Departure_date)
- [10-02-2019](Arrival_date)
- [09-02-2019](Departure_date)
- [10-03-2019](Arrival_date)
- It's a [First](class) class
- [Business](class)
- [First](class)
- [Qatar](airlines)
- [AirIndia](airlines)
- [1000](fare_price)
- [2000](fare_price)
- [$1000](fare_price)
- [$2000](fare_price)
- [$100](fare_price)
- [$200](fare_price)
- [Multiple](Ticket_type)
- [Single](Ticket_type)
- [single](Ticket_type)
- [Round](Ticket_type)
- [debit](payment_mode)
- [Debit](payment_mode)
- [Credit](payment_mode)
- [purse](baggage)
- [Bag](baggage)


## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct

## intent:deny
- no
- never
- I don't think so
- don't like that
- no way
- not really

故事.md

## greet
* greet
  - utter_greet

## thank
* thank
  - utter_noworries

## goodbye
* bye
  - utter_bye
  
## Some questions From FAQ
* faq
  - respond_faq

## sales form
* contact_sales
    - sales_form
    - form{"name": "sales_form"}
    - form{"name": null}

域.yml

intents:
  - greet
  - goodbye
  - mood_great
  - mood_unhappy
  - bot_challenge
  - Book_flight
  - cancel
  - inform
  - affirm
  - deny

entities:
  - location
  - Departure_date
  - Arrival_date
  - Ticket_type
  - airlines
  - class
  - fare_price
  - payment_mode
  

slots:
  
  from:
    type: unfeaturized
  to:
    type: unfeaturized
  Departure_date:
    type: unfeaturized
  Arrival_date:
    type: unfeaturized
  Ticket_type:
    type: unfeaturized
  airlines:
    type: unfeaturized
  class:
    type: unfeaturized
  fare_price:
    type: unfeaturized
  payment_mode:
    type: unfeaturized
  

actions:
  
  - utter_boarding
  - utter_destination
  - utter_Depature_date
  - utter_Arrival_date
  - utter_confirm
  - utter_Ticket_type
  - utter_airlines
  - utter_fare_price
  - utter_class
  - utter_payment_mode


  

responses:
  
  
  utter_boarding:
    - text: "We'll help you find the latest flight schedule. First, please provide your origin airport name?"
  
  utter_destination:
    - text: "And the destination airport code?"
  
  utter_Depature_date:
    - text: "What is the date of your departure(in dd-mm-yyyy)?"
  
  utter_Arrival_date:
    - text: "What is the date of your Arrival(in dd-mm-yyyy)?"

  utter_confirm:
    - text: "I will be making inquiry for flight from {from} to {to} on {Departure_date}. Is that correct?"
  
  utter_Ticket_type:
    - text: "What is your ticket type: One-way, Round?"
  
  utter_airlines:
    - text: "Which Airlines, Do you want to travel : Qatar Airways, Air Inidia, Air Asia, Jet Airways?"
  
  utter_fare_price:
    - text: "Here are the fare prices: First Class: $2000, Business class: $1200, Economy Class: $800"
  
  utter_class:
    - text: "Which class you want?"
  
  utter_payment_mode:
    - text: "How Would you like to pay, Should I charge you with card i.e saved. Else you can pay through Debit, Credit, Pay pal and Paypath"
  
  utter_greet:
    - text: "Hey! How are you?"

  utter_cheer_up:
    - text: "Here is something to cheer you up:"
      image: "https://i.imgur.com/nGF1K8f.jpg"

  utter_did_that_help:
  - text: "Did that help you?"

  utter_happy:
    - text: "Great, carry on!"

  utter_goodbye:
    - text: "Bye"

  utter_iamabot:
    - text: "I am a bot, powered by Rasa."

   
forms:
  - flight_form

session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

配置.yml

Rasa NLU 的配置。

https://rasa.com/docs/rasa/nlu/components/

语言:在管道中:

Rasa 核心的配置。

https://rasa.com/docs/rasa/core/policies/

政策:

请看看缺少什么

标签: chatbotrasa-nlurasa

解决方案


首先,由于您没有提供任何slot_mapping,它将默认将插槽映射到同名实体。您没有任何flight_from实体,因此这不起作用。您可以为此目的使用实体角色slot_mapping,并包括.

def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
    """A dictionary to map required slots to
        - an extracted entity
        - intent: value pairs
        - a whole message
        or a list of them, where a first match will be picked"""

    return {
        "flight_from": self.from_entity(entity="location", role="from"),
...
    }

您还应该检查其他插槽的 slot_mappings 并考虑要使用什么逻辑来获取该信息。我建议您阅读在此处填写表格空位的不同方式


推荐阅读