Fulfillment with Context

This article presents a practical example of Fulfillment's contextual features.

The focus will be on how to use ContextFlow to accomplish dialogue state transfer and how to store key information in dialogue. Take Flight Ticket Booking System as an example. When one needs to book a airline ticket, three keys are required: date, departure city and arrival city. If any of these pieces of information is missing, the system will ask user questions regarding the missing information. Once the system has all necessary information, it will answer the question and save the current three keys to the session for future usage.

How the system works

  1. How ContextFlow Works
  2. Flow Graph
  3. XML State-transfer Configuration Files
  4. Write Intent and Dictionary
  5. Testing
  6. Deployment

Flow graph

Draw a simple flow graph according to the JSON data's datatype. This is optional but recommended, because it offers a graphical representation of how the dialogue flow will be and it will make writing the associated xml files easier

Writing xml configuration files

Based on the flow graph, write the xml configuration files to manage dialogue states.

  • Every entry can have multiple trans, every trans can contains condition, intent and next state, every condition contains type and args
  • Every state includes name, action, stimulate and trans. Action is consists of type and args.

example:

<?xml version="1.0" encoding="UTF-8"?>
<xml>
//entry state
<entry>
<trans>
// is the slot completed?
<condition>
<type>NOT_CONTAIN_PROP_KEY</type>
<args>arrival_city departure_city</args>
</condition>
<intent>booking_entry</intent>
<state>lack_of_cities</state>
</trans>
</entry>
//ask for information and complete the slot
<state>
<name>lack_of_cities</name>
<args>departure_city date arrival_city time number seat_class ID</args>
<action>
<type>ANSWER</type>
</action>
<stimulate>What's your departure and arrival city?(As in the example: departure_city:Toronto,arrival_city:New York)</stimulate>
<trans>
<intent>booking_leav_arr_city</intent>
<state>search</state>
</trans>
</state>
//search status
<state>
<name>search</name>
<action>
<type>ANSWER</type>
<args>departure_city date arrival_city time number seat_class ID discount ticket_price</args>
</action>
<stimulate>Please wait, we are searching for airline tickets from Toronto to New York on Monday, July 1st 8:00(External API needed for user to select flight number). Is there anything else you need help with?
<intent>booking_ID</intent>
<state>Ticketing</state>
</trans>
</state>
//Ticketing
<state>
<name>ticketing</name>
<action>
<type>ANSWER</type>
<args>ID</args>
</action>
<stimulate>Your flight ticket is being prepared, please wait...</stimulate>
</state>

Note:

  • If type is ANSWER, args need to list all the slot names needed to update at current state.
  • In search state, the stimulate section is already assigned.
  • XML is related to intent and dict in next section. For example, when you write Entry state, you can write template in intent first and found that there is a missing slot.(E.G."Book me a flight ticket for tomorrow". In this sentence, departure city and arrival city are missing). At this point you can add condition in .xml file to complete the missing slot with corresponding state inforamtion.

Intent and Dict

Intent and dict in the Whisper platform can help the program recognize the user's query and accomplish slot recognization and completion.

Intent

Used to understand the user query's intent.

Dict

Used for word-level dictionary

Testing

Testing consists of two parts: local testing and server-side testing. Local testing is for debugging. During local testing, you cannot 本地测试方便开发者调试。因无法接受解析结果,需要自行调取接口(PARSING_URL)进行解析,运行结果只可在后台看到。server测试可以直接利用eparser进行解析,运行结果可以直接连接到前端网页中,但是部署到远程服务器相对于比较麻烦。

Local Testing

  1. set PARSING_URL

    private static final String PARSING_URL ="http://dev.rsvp.ai/eparser/api/product/parse/proto?skillid=402882e66c4ee141016c4efc8c2e3f4c&sentence="

  2. Parse

    Imagine user says "Book a flight ticket to Toronto for tomorrow" to robot. This sentence will get parsed by Eparser这句话将进入EparseResult进行解析,returns all parsing results. results contains this sentence's intent and slots.

  3. Match

    Afterwards, match this state to all transitions, found that the sentence is missing one of the three keys, in this case: departure_city, program will match all transition states in xml file and found the best state---lack_of_citeis. Then the platform will give the corresponding response written in stimulate: "what is your departure city?" and guide user to complete the slot.

  4. When system have all the information needed, it will call http://dev/rsvp.ai:5001/server and enter search state. At this time external interfaces are called. External interface is written in Python and contains three files---server.py;py_sql.py;json2sql.pyserver.py will create api interface, read GET request parameters and pass them to py_sql.pypy_sql.py will connect to database and using request parameters to do data import and data query, which returns a JsonArray. User can choose which result (in this case, which flight) is desirable or make a further selection(e.g. seat class, price range). If the flag parameter controls if new data import is needed is true, then json2sql.py is called which will import new data.json2sql.py will import new data and remove duplication.

Server Testing

  1. In resources program, modify URL path

    Modify @Path

  2. Use ngrok as proxy to ease testing.

    connect answering service to this proxy

    Run StandaloneServer, you should see the message below.

  3. Test in Whisper Platform

  4. Procedure

    Program procedure just like what we write in local test, the result could be:

    list (to store flight information)
    function: Return list of cards to show a group of information belonging to the same category.
    appearance: You can choose either scroll vertically or horizontally, up to 10 cards maximum.
    interaction: Based on the value of type, the user can scroll vertically or horizontally, click the button on the card to finish interaction.
    quick_replies
    function: According to the current context, give quick replies.
    appearance: Display as horizontal scroll button above input box.
    interaction: Disappears when the user clicks, at the same time send the text in postback to the dialogue API, or open a new tab in default browser.
    message
    function: ext reply
    appearance: bubble frame
    interaction: demo
  5. Deployment

    When satisfied, package the program as war, then put war and Python files in the server, finally start Python Mysql Server. Rewirte Whisper Platform's to correct server address.

Problems you may encounter

  1. According to parse result, extract props. Every pro has a key and value pair.
  2. Timeout
  3. Fulfillment result differs from URL's result