Updated on 2023-06-06 GMT+08:00

Invoking a Q&A Bot

After configuring the Q&A data, you can directly invoke a Q&A bot by starting a dialog on the CBS console or calling APIs to implement Q&A services for your customers.

You need to develop your Q&A console based on your service requirements. After receiving a customer question, the Q&A console calls related Q&A bot APIs, interacts with the Q&A bot, and displays the answer returned by the bot to the customer. During the interaction, the Q&A bot searches the knowledge base for the customer question and returns the answer.

Starting a Dialog on the Console

After Q&A pairs are imported to a Q&A bot, you can click Start Dialog in the upper right corner to start conversations with the bot.

  1. Log in to the CBS console and click Question Answering Bot in the left navigation pane. In the Q&A bot list, click the bot ID or the Manage Bot button in the Operation column.
  2. On the Q&A Bot page, click Start Dialog in the upper right corner to open the dialog window. In the dialog box, enter your question or click the recommended question returned by the system to obtain the answer.
    Figure 1 Starting a dialog

Calling APIs

Common APIs used for QABot are as follows:

  • Obtaining questions prompted when a user enters a question

    If you do not know how to ask a question about the existing problem, you can enter a keyword of the question to obtain a prompt about your question from QABot.

    In the following example, you want to ask a question about cloud desktops.

    • Example request
      POST https://{endpoint}/v1/41551a23c2be484cb0070631e323ee52/qabots/b36a01da-7fc2-43f8-8990-218e57a94420/chat
      
      Request Header:
      Content-Type: application/json
      X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
      Request Body:
      {
          "question": "What should I do if I cannot open my cloud desktop?"
      }
    • Example response
      • Successful example response
        {
            "questions":[
               "What should I do If I cannot open my cloud desktop?",
               "What should I do if I fail to log in to my cloud desktop?"
            ]
        }
      • Failed example response
        {
          "error_code": "CBS.0022",
          "error_msg": "question can not be null"
        }
  • Q&A request
    After you send a question to a Q&A bot through the API, if the Q&A bot finds the answer in the knowledge base through semantic matching, it returns the answer; otherwise, a failure message is returned.
    • Example request
      POST https://{endpoint}/v1/1604d8170cd84440a81281e5a3a04f8b/qabots/303a0a00-c88a-43e3-aa2f-d5b8b9832b02/requests
      Request Header:
      Content-Type: application/json
      X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
      Request Body:
      {
          "user_id": "z00123456",
          "session_id": "xxxxxxxxxxxxxxxxxx",
          "operate_type":3,      
             "question":"What should I do if I fail to log in to my cloud desktop?"
      }
    • Example response
      • Successful example response

        1. If the internal threshold is disabled (threshold_enable is set to false), the number of returned results is based on the value of top.

        { 
            "request_id": "303a0a00-c88a",
            "question": "What should I do If I cannot open my cloud desktop?",
            "answers": [
                {
                    "qa_pair_id":"123",
                    "st_question":"Why does my cloud desktop fail to be opened?",
                    "answer":"Incorrect user account.",
                    "score":0.952,
                    "domain":"Cloud desktop"
             },
             {
                    "qa_pair_id":"123",
                    "st_question":"Why would my desktop fail to be opened?",
                    "answer":"Incorrect user account.",
                    "score":0.901,
                    "domain":"Cloud desktop"
                },
                {
                    "qa_pair_id":"123",
                    "st_question":"What is cloud desktop?",
                    "answer": "Cloud desktop is a system that supports remote office.",
                    "score":0.352,
                    "domain":"Cloud desktop"
                },
             {
                    "qa_pair_id":"123",
                    "st_question": "Why does my computer desktop fail to be opened?",
                    "answer": "Check whether the monitor is started.",
                    "score":0.352,
                    "domain":"Cloud desktop"
                },
            ]
        }

        2. Enable the internal threshold.

        Table 1 Internal threshold description

        No.

        Condition

        Result

        Case 1

        The highest Q&A pair score is greater than the internal threshold θ (the default value is 0.4).

        The Q&A pair with the highest score is returned, indicating an exact match.

        Case 2

        The highest Q&A pair score is greater than θ/2 but less than θ.

        The Q&A pair with the highest score and recommended questions whose scores are higher than θ/3 are returned (recommended questions are returned without answers).

        Case 3

        The highest Q&A pair score is greater than θ/3 but less than θ/2.

        Recommended questions whose scores are θ/3 to θ/2 are returned.

        Example 1
        { 
            "request_id": "303a0a00-c88a",
            "question": "What should I do If I cannot open my cloud desktop?",
            "answers": [
                {
                    "qa_pair_id":"123",
                    "st_question":"Why does my cloud desktop fail to be opened?",
                    "answer":"Incorrect user account.",
                    "top_score_question":"Why does my cloud desktop fail to be opened?",
                    "score":0.952,
                    "domain":"Cloud desktop"
                }
            ]
        }
        Example 2
        { 
            "request_id": "303a0a00-c88a",
            "question": "What should I do If I cannot open my cloud desktop?",
            "answers": [
                {
                    "qa_pair_id":"123",
                    "st_question":"Why does my cloud desktop fail to be opened?",
                    "top_score_question":"Why does my cloud desktop fail to be opened?",
                    "answer":"Incorrect user account.",
                    "score":0.352,
                    "domain":"Cloud desktop"
                }
            {
                    "qa_pair_id":"123",
                    "st_question":"Why would my desktop fail to be opened?",
                    "score":0.301,
                    "domain":"Cloud desktop"
                },
                {
                    "qa_pair_id":"123",
                    "st_question":"What is cloud desktop?",
                    "score":0.252,
                    "domain":"Cloud desktop"
                }
            ]
        }
        Example 3
        { 
            "request_id": "303a0a00-c88a",
            "question": "What should I do If I cannot open my cloud desktop?",
            "answers": [
            {
                    "qa_pair_id":"123",
                    "st_question":"Why would my desktop fail to be opened?",
                    "score":0.291,
                    "domain":"Cloud desktop"
                },
                {
                    "qa_pair_id":"123",
                    "st_question":"What is cloud desktop?",
                    "score":0.252,
                    "domain":"Cloud desktop"
                }
            ]
        }

        3. Have chit-chat or ask a question without a matched answer.

        { 
            "request_id": "303a0a00-c88a",
            "question": "Hello",
            "answers": [
            {
                    "answer": "Hello. May I help you?"
                    
                }
            ]
        }
      • Failed example response
        {
          "error_code": "CBS.0022",
          "error_msg": "session_id can not be null"
        }
  • Evaluating Q&A satisfaction

    You can give satisfaction evaluation for the answer returned by QABot through the API. Currently, values 1 and -1 are available. Value 1 indicates that the answer is satisfying, and value -1 indicates that the answer is not satisfying.

    Example code for Q&A satisfaction evaluation is as follows:

    • Example request
      POST https://{endpoint}/v1/1604d8170cd84440a81281e5a3a04f8b/qabots/303a0a00-c88a-43e3-aa2f-d5b8b9832b02/requests/303a0a00-c88a/satisfaction
      Request Header:
      Content-Type: application/json
      X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
      Request Body:
      {
          "degree":1
      }
    • Example response
      • Successful example response
        {
            "request_id":"303a0a00-c88a",
            "updated_time":"2017-02-07T17:34:02Z"
        }
      • Failed example response
        {
          "error_code": "CBS.0099",
          "error_msg": "request body invalid."
        }