使用後續追蹤提示來建立多回合對話

使用後續提示和內容,針對您的 Bot,管理從一個問題到另一個問題的多個回合 (稱為「多回合」)。

若要查看多回合的運作方式,請觀看下列示範影片:

 QnA Maker 中的多回合對話

注意

QnA Maker 服務即將於 2025 年 3 月 31 日淘汰。 現在,Azure AI 語言提供較新版本的問題和解答功能。 如需瞭解語言服務內的問題解答功能,請參閱問題解答。 從 2022 年 10 月 1 日開始,您將無法建立新的 QnA Maker 資源。 如需將現有的 QnA Maker 知識庫移轉至問題解答的相關資訊,請參閱移轉指南

什麼是多回合交談?

某些問題無法在單一回合中回答。 當您設計用戶端應用程式 (聊天機器人) 交談時,使用者可能會詢問需要篩選或調整才能判斷正確答案的問題。 您可以向使用者顯示「後續提示」,讓此流程得以完成問題。

當使用者提出問題時,QnA Maker 會傳回答案與任何後續提示。 此回應可讓您將後續問題顯示為選項。

警告

多回合提示無法從常見問題文件中擷取。 如果您需要多回合擷取,請移除將 QnA 配對指定為常見問題的問號。

使用聊天機器人的多回合交談範例

使用多回合,聊天機器人就能管理與使用者的交談來判斷最終答案,如下圖所示:

多回合對話,其中包含能引導使用者完成對話的提示

在上圖中,使用者已透過輸入我的帳戶來開始交談。 知識庫有三個連結的問答配對。 若要精簡答案,使用者可以在知識庫中選取這三個選項之一。 問題 (#1) 有三個後續提示,其會在聊天機器人中顯示為三個選項 (#2)。

當使用者選取選項 (#3) 時,即會顯示下一份精簡選項清單 (#4)。 此序列會繼續 (#5),直到使用者判斷正確的最終答案 (#6) 為止。

在 Bot 中使用多回合

發佈您的 KB 之後,您可以選取 [建立 Bot] 按鈕,將 QnA Maker Bot 部署至 Azure AI Bot Service。 提示將出現在您已為機器人啟用的聊天用戶端中。

從文件的結構建立多回合交談

當您建立知識庫時,[填入您的知識庫] 區段會顯示 [啟用從 URL、.pdf 或 .docx 檔案進行的多回合擷取] 核取方塊。

啟用多回合擷取的核取方塊

當您選取此選項時,QnA Maker 會擷取文件結構中出現的階層。 階層會轉換成後續提示,而階層的根會作為父 QnA。 在某些文件中,階層的根沒有可作為答案的內容。 您可以使用「預設答案文字」作為替代答案文字,以擷取此類階層。

您只能從 URL、PDF 檔案或 DOCX 檔案推斷多回合結構。 如需結構的範例,請檢視 Microsoft Surface 使用者手冊 PDF 檔案的影像。

此螢幕擷取畫面顯示使用者手冊中的結構範例。

建置您自己的多回合文件

如果您要建立多回合文件,請記住下列指導方針:

  • 使用標題和子標題來表示階層。 例如,使用 h1 來表示父 QnA,並使用 h2 來表示應以提示形式取得的 QnA。 使用小型標題大小來表示後續階層。 請勿使用樣式、色彩或某些其他機制來暗示文件中的結構,QnA Maker 將不會擷取多回合提示。

  • 標題的第一個字元必須為大寫。

  • 請勿以問號 ? 當成標題結尾。

  • 您可以使用範例文件當作範例,來建立自己的多回合文件。

將檔案新增至多回合知識庫

當您新增階層式文件時,QnA Maker 會從結構判斷後續提示,以建立交談流程。

  1. 在 QnA Maker 中,選取現有的知識庫,它是透過啟用 [啟用從 URL、.pdf 或 .docx 檔案進行的多回合擷取] 來建立。
  2. 移至 [設定] 頁面,選取要新增的檔案或 URL。
  3. 儲存並定型知識庫。

警告

不支援使用匯出的 TSV 或 XLS 多回合知識庫檔案作為新的或空白知識庫的資料來源。 您必須從 QnA Maker 入口網站的 [設定] 頁面匯入該檔案類型,才能將匯出的多回合提示新增至知識庫。

使用建立 API 來建立具有多回合提示的知識庫

您可以使用 QnA Maker 建立 API,來建立具有多回合提示的知識庫。 提示會在 context 屬性的 prompts 陣列中新增。

顯示問題和答案以及內容

將顯示的問答配對縮減為只具有內容相關交談的配對。

選取 [檢視選項],然後選取 [顯示內容]。 此清單會顯示包含後續提示的問答配對。

利用內容對話篩選問答配對

多回合內容會顯示在第一個資料行中。

此螢幕擷取畫面顯示反白顯示的 [內容] 區段。

在上圖中,#1 代表資料行中的粗體文字,其表示目前的問題。 父問題是資料列中的最上層項目。 其下的任何問題都是連結的問答配對。 這些項目都是可選取的,讓您能夠立即移至其他內容項目。

將現有的問答配對新增為後續提示

原始問題 (即我的帳戶) 具有後續提示,例如帳戶和登入

「帳戶和登入」的答案和後續提示

將後續提示新增至目前尚未連結的現有問答配對。 由於問題並未連結到任何問答配對,因此必須變更目前的檢視設定。

  1. 若要連結現有的問答配對以作為後續提示,請選取問答配對的資料列。 針對 Surface 手冊,搜尋登出以縮減清單。

  2. 在 [登出] 的資料列中,選取 [答案] 資料行中的 [新增後續提示]。

  3. 在 [後續提示] 快顯視窗的欄位中,輸入下列值:

    欄位
    顯示文字 輸入關閉裝置。 這是要在後續提示中顯示的自訂文字。
    僅內容 選取此核取方塊。 只有當問題指定內容時,才會傳回答案。
    答案的連結 輸入使用登入畫面來尋找現有的問答配對。
  4. 隨即傳回一個相符項目。 選取此答案作為後續,然後選取 [儲存]。

    「後續提示」頁面

  5. 當您新增後續提示之後,選取頂端導覽中的 [儲存並定型]。

編輯顯示文字

當您建立後續提示,並輸入現有的問答配對作為答案的連結時,您可以輸入新的顯示文字。 此文字不會取代現有問題,也不會新增替代問題。 它與那些值不同。

  1. 若要編輯顯示文字,請在 [內容] 欄位中搜尋並選取問題。

  2. 在該問題的資料列中,選取 [答案] 資料行中的後續提示。

  3. 選取您要編輯的顯示文字,然後選取 [編輯]。

    顯示文字的 [編輯] 命令

  4. 在 [後續提示] 快顯視窗中,變更現有的顯示文字。

  5. 當您完成編輯顯示文字時,選取 [儲存]。

  6. 在頂端導覽列中,選取 [儲存並定型]。

將新的問答配對新增為後續提示

當您將新的問答配對新增至知識庫時,每個配對都應該連結至現有問題以作為後續提示。

  1. 在知識庫工具列上,針對帳戶和登入搜尋並選取現有的問答配對。

  2. 在此問題的 [答案] 資料行中,選取 [新增後續提示]。

  3. 在 [後續提示 (預覽)] 中,輸入下列值來建立新的後續提示:

    欄位
    顯示文字 建立 Windows 帳戶。 要在後續提示中顯示的自訂文字。
    僅內容 選取此核取方塊。 只有當問題指定內容時,才會傳回此答案。
    答案的連結 輸入下列文字作為答案:
    使用新的或現有的電子郵件帳戶建立 Windows 帳戶
    當您儲存並定型資料庫時,將會轉換此文字。

    建立新的提示問題和答案

  4. 選取 [建立新的],然後選取 [儲存]。

    此動作會建立新的問答配對,並連結選取的問題以作為後續提示。 這兩個問題的 [內容] 資料行會指出後續提示關聯性。

  5. 選取 [檢視選項],然後選取 [顯示內容 (預覽)]。

    新問題會顯示其連結方式。

    建立新的後續提示

    父問題會將新問題顯示為它的其中一個選項。

    此螢幕擷取畫面顯示這兩個問題的 [內容] 資料行會指出後續提示關聯性。

  6. 當您新增後續提示之後,選取頂端導覽列中的 [儲存並定型]。

在測試後續提示期間檢視多回合

當您在 [測試] 窗格中使用後續提示測試問題時,回應會包含後續提示。

回應包含後續提示

傳回初始答案和後續提示的 JSON 要求

使用空的 context 物件來要求使用者問題的答案,並包含後續提示。

{
  "question": "accounts and signing in",
  "top": 10,
  "userId": "Default",
  "isTest": false,
  "context": {}
}

傳回初始答案和後續提示的 JSON 回應

上一節已要求有關帳戶和登入的答案及任何後續提示。 回應會包含提示資訊 (位於 answers[0].context) 以及要向使用者顯示的文字。

{
    "answers": [
        {
            "questions": [
                "Accounts and signing in"
            ],
            "answer": "**Accounts and signing in**\n\nWhen you set up your Surface, an account is set up for you. You can create additional accounts later for family and friends, so each person using your Surface can set it up just the way he or she likes. For more info, see All about accounts on Surface.com. \n\nThere are several ways to sign in to your Surface Pro 4: ",
            "score": 100.0,
            "id": 15,
            "source": "product-manual.pdf",
            "metadata": [],
            "context": {
                "isContextOnly": true,
                "prompts": [
                    {
                        "displayOrder": 0,
                        "qnaId": 16,
                        "qna": null,
                        "displayText": "Use the sign-in screen"
                    }
                ]
            }
        },
        {
            "questions": [
                "Sign out"
            ],
            "answer": "**Sign out**\n\nHere's how to sign out: \n\n  Go to Start, and right-click your name. Then select Sign out. ",
            "score": 38.01,
            "id": 18,
            "source": "product-manual.pdf",
            "metadata": [],
            "context": {
                "isContextOnly": true,
                "prompts": [
                    {
                        "displayOrder": 0,
                        "qnaId": 16,
                        "qna": null,
                        "displayText": "Turn off the device"
                    }
                ]
            }
        },
        {
            "questions": [
                "Use the sign-in screen"
            ],
            "answer": "**Use the sign-in screen**\n\n1.  \n\nTurn on or wake your Surface by pressing the power button. \n\n2.  \n\nSwipe up on the screen or tap a key on the keyboard. \n\n3.  \n\nIf you see your account name and account picture, enter your password and select the right arrow or press Enter on your keyboard. \n\n4.  \n\nIf you see a different account name, select your own account from the list at the left. Then enter your password and select the right arrow or press Enter on your keyboard. ",
            "score": 27.53,
            "id": 16,
            "source": "product-manual.pdf",
            "metadata": [],
            "context": {
                "isContextOnly": true,
                "prompts": []
            }
        }
    ]
}

prompts 陣列提供 displayText 屬性中的文字和 qnaId 值。 您可以在交談流程中將這些答案顯示為下一個顯示的選項,然後在下列要求中,將選取的 qnaId 傳送回 QnA Maker。

傳回非初始答案和後續提示的 JSON 要求

填入 context 物件,以包含先前的內容。

在下列 JSON 要求中,目前的問題是「使用 Windows Hello 登入」,而先前的問題是「帳戶和登入」。

{
  "question": "Use Windows Hello to sign in",
  "top": 10,
  "userId": "Default",
  "isTest": false,
  "qnaId": 17,
  "context": {
    "previousQnAId": 15,
    "previousUserQuery": "accounts and signing in"
  }
}

傳回非初始答案和後續提示的 JSON 回應

QnA Maker GenerateAnswer JSON 回應會在 answers 物件第一個項目的 context 屬性中包含後續提示:

{
    "answers": [
        {
            "questions": [
                "Use Windows Hello to sign in"
            ],
            "answer": "**Use Windows Hello to sign in**\n\nSince Surface Pro 4 has an infrared (IR) camera, you can set up Windows Hello to sign in just by looking at the screen. \n\nIf you have the Surface Pro 4 Type Cover with Fingerprint ID (sold separately), you can set up your Surface sign you in with a touch. \n\nFor more info, see What is Windows Hello? on Windows.com. ",
            "score": 100.0,
            "id": 17,
            "source": "product-manual.pdf",
            "metadata": [],
            "context": {
                "isContextOnly": true,
                "prompts": []
            }
        },
        {
            "questions": [
                "Meet Surface Pro 4"
            ],
            "answer": "**Meet Surface Pro 4**\n\nGet acquainted with the features built in to your Surface Pro 4. \n\nHere's a quick overview of Surface Pro 4 features: \n\n\n\n\n\n\n\nPower button \n\n\n\n\n\nPress the power button to turn your Surface Pro 4 on. You can also use the power button to put it to sleep and wake it when you're ready to start working again. \n\n\n\n\n\n\n\nTouchscreen \n\n\n\n\n\nUse the 12.3" display, with its 3:2 aspect ratio and 2736 x 1824 resolution, to watch HD movies, browse the web, and use your favorite apps. \n\nThe new Surface G5 touch processor provides up to twice the touch accuracy of Surface Pro 3 and lets you use your fingers to select items, zoom in, and move things around. For more info, see Surface touchscreen on Surface.com. \n\n\n\n\n\n\n\nSurface Pen \n\n\n\n\n\nEnjoy a natural writing experience with a pen that feels like an actual pen. Use Surface Pen to launch Cortana in Windows or open OneNote and quickly jot down notes or take screenshots. \n\nSee Using Surface Pen (Surface Pro 4 version) on Surface.com for more info. \n\n\n\n\n\n\n\nKickstand \n\n\n\n\n\nFlip out the kickstand and work or play comfortably at your desk, on the couch, or while giving a hands-free presentation. \n\n\n\n\n\n\n\nWi-Fi and Bluetooth® \n\n\n\n\n\nSurface Pro 4 supports standard Wi-Fi protocols (802.11a/b/g/n/ac) and Bluetooth 4.0. Connect to a wireless network and use Bluetooth devices like mice, printers, and headsets. \n\nFor more info, see Add a Bluetooth device and Connect Surface to a wireless network on Surface.com. \n\n\n\n\n\n\n\nCameras \n\n\n\n\n\nSurface Pro 4 has two cameras for taking photos and recording video: an 8-megapixel rear-facing camera with autofocus and a 5-megapixel, high-resolution, front-facing camera. Both cameras record video in 1080p, with a 16:9 aspect ratio. Privacy lights are located on the right side of both cameras. \n\nSurface Pro 4 also has an infrared (IR) face-detection camera so you can sign in to Windows without typing a password. For more info, see Windows Hello on Surface.com. \n\nFor more camera info, see Take photos and videos with Surface and Using autofocus on Surface 3, Surface Pro 4, and Surface Book on Surface.com. \n\n\n\n\n\n\n\nMicrophones \n\n\n\n\n\nSurface Pro 4 has both a front and a back microphone. Use the front microphone for calls and recordings. Its noise-canceling feature is optimized for use with Skype and Cortana. \n\n\n\n\n\n\n\nStereo speakers \n\n\n\n\n\nStereo front speakers provide an immersive music and movie playback experience. To learn more, see Surface sound, volume, and audio accessories on Surface.com. \n\n\n\n\n",
            "score": 21.92,
            "id": 3,
            "source": "product-manual.pdf",
            "metadata": [],
            "context": {
                "isContextOnly": true,
                "prompts": [
                    {
                        "displayOrder": 0,
                        "qnaId": 4,
                        "qna": null,
                        "displayText": "Ports and connectors"
                    }
                ]
            }
        },
        {
            "questions": [
                "Use the sign-in screen"
            ],
            "answer": "**Use the sign-in screen**\n\n1.  \n\nTurn on or wake your Surface by pressing the power button. \n\n2.  \n\nSwipe up on the screen or tap a key on the keyboard. \n\n3.  \n\nIf you see your account name and account picture, enter your password and select the right arrow or press Enter on your keyboard. \n\n4.  \n\nIf you see a different account name, select your own account from the list at the left. Then enter your password and select the right arrow or press Enter on your keyboard. ",
            "score": 19.04,
            "id": 16,
            "source": "product-manual.pdf",
            "metadata": [],
            "context": {
                "isContextOnly": true,
                "prompts": []
            }
        }
    ]
}

使用 QnA Maker 識別碼查詢知識庫

如果您要建置自訂應用程式,在初始問題的回應中,會傳回任何後續提示與其相關聯的 qnaId。 既然您已有識別碼,您可以在後續提示的要求本文中傳遞該識別碼。 如果要求本文包含 qnaId 和內容物件 (其中包含先前的 QnA Maker 屬性),則 GenerateAnswer 將依識別碼傳回確切的問題,而不是使用排名演算法來依問題文字尋找答案。

更新 API 中支援顯示順序

更新 API 支援編輯在 JSON 回應中傳回的顯示文字和顯示順序

使用更新 API 新增或刪除多回合提示

您可以使用 QnA Maker 更新 API 來新增或刪除多回合提示。 提示會在 context 屬性的 promptsToAdd 陣列和 promptsToDelete 陣列中新增。

匯出知識庫以進行版本控制

QnA Maker 透過在匯出的檔案中包含多回合交談步驟來支援版本控制。

下一步