如何使用 REST API 更改 LUIS 模型How to change the LUIS model with REST APIs

在本文中,你要将示例言语添加到披萨应用并训练该应用。In this article, you will add example utterances to a Pizza app and train the app. 示例话语是映射到意向的对话式用户文本。Example utterances are conversational user text mapped to an intent. 通过提供意向的示例话语,可以教 LUIS 识别用户提供的文本类型属于哪种意向。By providing example utterances for intents, you teach LUIS what kinds of user-supplied text belongs to which intent.

参考文档 | 示例Reference documentation | Sample

先决条件Prerequisites

示例话语 JSON 文件Example utterances JSON file

示例言语采用特定格式。The example utterances follow a specific format.

text 字段包含示例话语的文本。The text field contains the text of the example utterance. intentName 字段必须对应于 LUIS 应用中的现有意向名称。The intentName field must correspond to the name of an existing intent in the LUIS app. entityLabels 字段是必填的。The entityLabels field is required. 如果不想标记任何实体,请提供一个空数组。If you don't want to label any entities, provide an empty array.

如果 entityLabels 数组不为空,则 startCharIndexendCharIndex 需要标记 entityName 字段中引用的实体。If the entityLabels array is not empty, the startCharIndex and endCharIndex need to mark the entity referred to in the entityName field. 该索引从零开始。The index is zero-based. 如果标签的起始或结尾位于文本中的空白处,则添加话语的 API 调用将失败。If you begin or end the label at a space in the text, the API call to add the utterances fails.

[
  {
    "text": "order a pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "order a large pepperoni pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 14,
        "endCharIndex": 28
      },
      {
        "entityName": "Size",
        "startCharIndex": 8,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "I want two large pepperoni pizzas on thin crust",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 17,
        "endCharIndex": 32
      },
      {
        "entityName": "Size",
        "startCharIndex": 11,
        "endCharIndex": 15
      },
      {
        "entityName": "Quantity",
        "startCharIndex": 7,
        "endCharIndex": 9
      },
      {
        "entityName": "Crust",
        "startCharIndex": 37,
        "endCharIndex": 46
      }
    ]
  }
]

创建披萨应用Create Pizza app

创建披萨应用。Create the pizza app.

  1. 选择 pizza-app-for-luis-v6.json,打开 pizza-app-for-luis.json 文件的 GitHub 页面。Select pizza-app-for-luis-v6.json to bring up the GitHub page for the pizza-app-for-luis.json file.
  2. 右键单击或长按“原始”按钮,然后选择“将链接另存为”,将 pizza-app-for-luis.json 保存到计算机 。Right-click or long tap the Raw button and select Save link as to save the pizza-app-for-luis.json to your computer.
  3. 登录到 LUIS 门户Sign into the LUIS portal.
  4. 选择我的应用Select My Apps.
  5. 在“我的应用”页面上,选择“+ 新建用于对话的应用” 。On the My Apps page, select + New app for conversation.
  6. 选择“导入为 JSON”。Select Import as JSON.
  7. 在“导入新应用”对话框中,选择“选择文件”按钮 。In the Import new app dialog, select the Choose File button.
  8. 选择下载的 pizza-app-for-luis.json 文件,然后选择“打开”。Select the pizza-app-for-luis.json file you downloaded, then select Open.
  9. 在“导入新应用”对话框的“名称”字段中,输入 Pizza 应用的名称,然后选择“完成”按钮 。In the Import new app dialog Name field, enter a name for your Pizza app, then select the Done button.

随即导入应用。The app will be imported.

如果看到一个对话框“如何创建有效的 LUIS 应用”,关闭该对话框。If you see a dialog How to create an effective LUIS app, close the dialog.

训练并发布 Pizza 应用Train and publish the Pizza app

Pizza 应用中应会显示“意向”页面,其中显示了一个意向列表。You should see the Intents page with a list of the intents in the Pizza app.

  1. 在 LUIS 网站的右上方,选择“训练”按钮。In the top-right side of the LUIS website, select the Train button.

    “训练”按钮

  2. 当“训练”按钮上的状态指示器为绿色时,即表示训练完成。Training is complete when status indicator on the Train button is green.

若要在聊天机器人或其他客户端应用程序中接收 LUIS 预测,需要将应用发布到预测终结点。In order to receive a LUIS prediction in a chat bot or other client application, you need to publish the app to the prediction endpoint.

  1. 在右上方的导航栏中选择“发布”。Select Publish in the top-right navigation.

    右上方菜单中的“LUIS 发布到终结点”按钮的屏幕截图Screenshot of LUIS publish to endpoint button in top right menu

  2. 选择“生产”槽,然后选择“完成” 。Select the Production slot, then select Done.

    “LUIS 发布到终结点”的屏幕截图Screenshot of LUIS publish to endpoint

  3. 在通知中选择“访问终结点 URL”,以转到“Azure 资源”页 。Select Access your endpoint URLs in the notification to go to the Azure Resources page. 只有你拥有与应用关联的预测资源时,才能看到 URL。You will only be able to see the URLs if you have a prediction resource associated with the app. 还可以单击“管理”来找到“Azure 资源”页 。You can also find the Azure Resources page by clicking Manage.

    指示应用已发布的消息A message that the app has been published

向披萨应用添加创作资源Add an authoring resource to the Pizza app

  1. 选择“管理”。Select MANAGE.
  2. 选择“Azure 资源”。Select Azure Resources.
  3. 选择“创作资源”。Select Authoring Resource.
  4. 选择“更改创作资源”。Select Change authoring resource.

如果你有创作资源,请输入你的创作资源的租户名称、订阅名称以及 LUIS 资源名称。If you have an authoring resource, enter the Tenant Name, Subscription Name, and LUIS resource name of your authoring resource.

如果你没有创作资源:If you do not have an authoring resource:

  1. 选择“新建资源”。Select Create new resource.
  2. 输入租户名称、资源名称、订阅名称和 Azure 资源组名称。Enter a Tenant Name, Resource Name, Subscription Name, and Azure Resource Group Name.

现在 Pizza 应用可以使用了。Your Pizza app is now ready to use.

记录 Pizza 应用的访问值Record the access values for your Pizza app

若要使用新的披萨应用,你需要该披萨应用的应用 ID、授权密钥和授权终结点。To use your new Pizza app, you will need the app ID, authoring key, and authoring endpoint of your Pizza app. 若要获取预测,需要单独的预测终结点和预测密钥。To get predictions, you will need your separate prediction endpoint and prediction key.

若要查找这些值:To find these values:

  1. 在“意向”页面,选择“管理” 。From the Intents page, select MANAGE.
  2. 在“应用程序设置”页面,记录“应用 ID” 。From the Application Settings page, record the App ID.
  3. 选择“Azure 资源”。Select Azure Resources.
  4. 选择“创作资源”。Select Authoring Resource.
  5. 从“创作资源”和“预测资源”选项卡,记录“主键” 。From the Authoring Resource and Prediction Resources tabs, record the Primary Key. 此值是你的创作密钥。This value is your authoring key.
  6. 记录“终结点 URL”。Record the Endpoint URL. 此值是你的创作终结点。This value is your authoring endpoint.

以编程方式更改模型Change model programmatically

  1. 使用项目和名为 csharp-model-with-rest 的文件夹创建一个面向 C# 语言的新控制台应用程序。Create a new console application targeting the C# language, with a project and folder name of csharp-model-with-rest.

    dotnet new console -lang C# -n csharp-model-with-rest
    
  2. 更改为创建的 csharp-model-with-rest 目录,并使用以下命令安装所需的依赖项:Change to the csharp-model-with-rest directory you created, and install required dependencies with these commands:

    cd csharp-model-with-rest
    dotnet add package System.Net.Http
    dotnet add package JsonFormatterPlus
    
  3. 将 Program.cs 改写为以下代码:Overwrite Program.cs with the following code:

//
// This quickstart shows how to add utterances to a LUIS model using the REST APIs.
//

using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;

// 3rd party NuGet packages
using JsonFormatterPlus;

namespace AddUtterances
{
    class Program
    {
        //////////
        // Values to modify.

        // YOUR-APP-ID: The App ID GUID found on the luis.azure.cn Application Settings page.
        static string appID = "YOUR-APP-ID";

        // YOUR-AUTHORING-KEY: Your LUIS authoring key, 32 character value.
        static string authoringKey = "YOUR-AUTHORING-KEY";

        // YOUR-AUTHORING-ENDPOINT: Replace this endpoint with your authoring key endpoint.
        // For example, "https://your-resource-name.cognitiveservices.azure.cn/"
        static string authoringEndpoint = "https://YOUR-AUTHORING-ENDPOINT/";

        // NOTE: Replace this your version number.
        static string appVersion = "0.1";
        //////////

        static string host = String.Format("{0}luis/authoring/v3.0-preview/apps/{1}/versions/{2}/", authoringEndpoint, appID, appVersion);

        // GET request with authentication
        async static Task<HttpResponseMessage> SendGet(string uri)
        {
            using (var client = new HttpClient())
            using (var request = new HttpRequestMessage())
            {
                request.Method = HttpMethod.Get;
                request.RequestUri = new Uri(uri);
                request.Headers.Add("Ocp-Apim-Subscription-Key", authoringKey);
                return await client.SendAsync(request);
            }
        }

        // POST request with authentication
        async static Task<HttpResponseMessage> SendPost(string uri, string requestBody)
        {
            using (var client = new HttpClient())
            using (var request = new HttpRequestMessage())
            {
                request.Method = HttpMethod.Post;
                request.RequestUri = new Uri(uri);

                if (!String.IsNullOrEmpty(requestBody))
                {
                    request.Content = new StringContent(requestBody, Encoding.UTF8, "text/json");
                }

                request.Headers.Add("Ocp-Apim-Subscription-Key", authoringKey);
                return await client.SendAsync(request);
            }
        }

        // Add utterances as string with POST request
        async static Task AddUtterances(string utterances)
        {
            string uri = host + "examples";

            var response = await SendPost(uri, utterances);
            var result = await response.Content.ReadAsStringAsync();
            Console.WriteLine("Added utterances.");
            Console.WriteLine(JsonFormatter.Format(result));
        }

        // Train app after adding utterances
        async static Task Train()
        {
            string uri = host  + "train";

            var response = await SendPost(uri, null);
            var result = await response.Content.ReadAsStringAsync();
            Console.WriteLine("Sent training request.");
            Console.WriteLine(JsonFormatter.Format(result));
        }

        // Check status of training
        async static Task Status()
        {
            var response = await SendGet(host  + "train");
            var result = await response.Content.ReadAsStringAsync();
            Console.WriteLine("Requested training status.");
            Console.WriteLine(JsonFormatter.Format(result));
        }

        // Add utterances, train, check status
        static void Main(string[] args)
        {
            string utterances = @"
            [
                {
                    'text': 'order a pizza',
                    'intentName': 'ModifyOrder',
                    'entityLabels': [
                        {
                            'entityName': 'Order',
                            'startCharIndex': 6,
                            'endCharIndex': 12
                        }
                    ]
                },
                {
                    'text': 'order a large pepperoni pizza',
                    'intentName': 'ModifyOrder',
                    'entityLabels': [
                        {
                            'entityName': 'Order',
                            'startCharIndex': 6,
                            'endCharIndex': 28
                        },
                        {
                            'entityName': 'FullPizzaWithModifiers',
                            'startCharIndex': 6,
                            'endCharIndex': 28
                        },
                        {
                            'entityName': 'PizzaType',
                            'startCharIndex': 14,
                            'endCharIndex': 28
                        },
                        {
                            'entityName': 'Size',
                            'startCharIndex': 8,
                            'endCharIndex': 12
                        }
                    ]
                },
                {
                    'text': 'I want two large pepperoni pizzas on thin crust',
                    'intentName': 'ModifyOrder',
                    'entityLabels': [
                        {
                            'entityName': 'Order',
                            'startCharIndex': 7,
                            'endCharIndex': 46
                        },
                        {
                            'entityName': 'FullPizzaWithModifiers',
                            'startCharIndex': 7,
                            'endCharIndex': 46
                        },
                        {
                            'entityName': 'PizzaType',
                            'startCharIndex': 17,
                            'endCharIndex': 32
                        },
                        {
                            'entityName': 'Size',
                            'startCharIndex': 11,
                            'endCharIndex': 15
                        },
                        {
                            'entityName': 'Quantity',
                            'startCharIndex': 7,
                            'endCharIndex': 9
                        },
                        {
                            'entityName': 'Crust',
                            'startCharIndex': 37,
                            'endCharIndex': 46
                        }
                    ]
                }
            ]
            ";

            AddUtterances(utterances).Wait();
            Train().Wait();
            Status().Wait();
        }
    }
}
  1. 将以 YOUR- 开头的值替换为你自己的值。Replace the values starting with YOUR- with your own values.

    信息Information 目的Purpose
    YOUR-APP-ID LUIS 应用 ID。Your LUIS app ID.
    YOUR-AUTHORING-KEY 32 字符创作密钥。Your 32 character authoring key.
    YOUR-AUTHORING-ENDPOINT 创作 URL 终结点。Your authoring URL endpoint. 例如,https://replace-with-your-resource-name.api.cognitive.azure.cn/For example, https://replace-with-your-resource-name.api.cognitive.azure.cn/. 在创建资源时设置资源名称。You set your resource name when you created the resource.

    分配的密钥和资源可以在 LUIS 门户的“Azure 资源”页上的“管理”部分中看到。Assigned keys and resources are visible in the LUIS portal in the Manage section, on the Azure resources page. 应用 ID 可以在“应用程序设置”页的同一“管理”部分中找到。The app ID is available in the same Manage section, on the Application Settings page.

  2. 生成控制台应用程序。Build the console application.

    dotnet build
    
  3. 运行控制台应用程序。Run the console application.

    dotnet run
    
  4. 查看创作响应:Review the authoring response:

    Added utterances.
    [
        {
            "value": {
                "ExampleId": 1137150691,
                "UtteranceText": "order a pizza"
            },
            "hasError": false
        },
        {
            "value": {
                "ExampleId": 1137150692,
                "UtteranceText": "order a large pepperoni pizza"
            },
            "hasError": false
        },
        {
            "value": {
                "ExampleId": 1137150693,
                "UtteranceText": "i want two large pepperoni pizzas on thin crust"
            },
            "hasError": false
        }
    ]
    Sent training request.
    {
        "statusId": 9,
        "status": "Queued"
    }
    Requested training status.
    [
        {
            "modelId": "edb46abf-0000-41ab-beb2-a41a0fe1630f",
            "details": {
                "statusId": 9,
                "status": "Queued",
                "exampleCount": 0
            }
        },
        {
            "modelId": "a5030be2-616c-4648-bf2f-380fa9417d37",
            "details": {
                "statusId": 9,
                "status": "Queued",
                "exampleCount": 0
            }
        },
        {
            "modelId": "3f2b1f31-a3c3-4fbd-8182-e9d9dbc120b9",
            "details": {
                "statusId": 9,
                "status": "Queued",
                "exampleCount": 0
            }
        },
        {
            "modelId": "e4b6704b-1636-474c-9459-fe9ccbeba51c",
            "details": {
                "statusId": 9,
                "status": "Queued",
                "exampleCount": 0
            }
        },
        {
            "modelId": "031d3777-2a00-4a7a-9323-9a3280a30000",
            "details": {
                "statusId": 9,
                "status": "Queued",
                "exampleCount": 0
            }
        },
        {
            "modelId": "9250e7a1-06eb-4413-9432-ae132ed32583",
            "details": {
                "statusId": 9,
                "status": "Queued",
                "exampleCount": 0
            }
        }
    ]
    

清理资源Clean up resources

完成本快速入门后,请从文件系统中删除项目文件夹。When you are finished with this quickstart, delete the project folder from the file system.

后续步骤Next steps

参考文档 | 示例Reference documentation | Sample

先决条件Prerequisites

示例话语 JSON 文件Example utterances JSON file

示例言语采用特定格式。The example utterances follow a specific format.

text 字段包含示例话语的文本。The text field contains the text of the example utterance. intentName 字段必须对应于 LUIS 应用中的现有意向名称。The intentName field must correspond to the name of an existing intent in the LUIS app. entityLabels 字段是必填的。The entityLabels field is required. 如果不想标记任何实体,请提供一个空数组。If you don't want to label any entities, provide an empty array.

如果 entityLabels 数组不为空,则 startCharIndexendCharIndex 需要标记 entityName 字段中引用的实体。If the entityLabels array is not empty, the startCharIndex and endCharIndex need to mark the entity referred to in the entityName field. 该索引从零开始。The index is zero-based. 如果标签的起始或结尾位于文本中的空白处,则添加话语的 API 调用将失败。If you begin or end the label at a space in the text, the API call to add the utterances fails.

[
  {
    "text": "order a pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "order a large pepperoni pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 14,
        "endCharIndex": 28
      },
      {
        "entityName": "Size",
        "startCharIndex": 8,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "I want two large pepperoni pizzas on thin crust",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 17,
        "endCharIndex": 32
      },
      {
        "entityName": "Size",
        "startCharIndex": 11,
        "endCharIndex": 15
      },
      {
        "entityName": "Quantity",
        "startCharIndex": 7,
        "endCharIndex": 9
      },
      {
        "entityName": "Crust",
        "startCharIndex": 37,
        "endCharIndex": 46
      }
    ]
  }
]

以编程方式更改模型Change model programmatically

  1. 创建一个新文件夹以保存 Java 项目,例如 java-model-with-restCreate a new folder to hold your Java project, such as java-model-with-rest.

  2. 创建一个名为 lib 的子目录,并将以下 Java 库中的内容复制到 lib 子目录:Make a subdirectory named lib and copy in the following java libs into the lib subdirectory:

  3. 创建名为 Model.java 的新文件。Create a new file named Model.java. 添加以下代码:Add the following code:

//
// This quickstart shows how to add utterances to a LUIS model using the REST APIs.
//

import java.io.*;
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

// To compile, execute this command at the console:
//      Windows: javac -cp ";lib/*" Model.java
//      macOs: javac -cp ":lib/*" Model.java
//      Linux: javac -cp ":lib/*" Model.java

// To run, execute this command at the console:
//      Windows: java -cp ";lib/*" Model
//      macOs: java -cp ":lib/*" Model
//      Linux: java -cp ":lib/*" Model

public class Model
{
    public static void main(String[] args)
    {
        try
        {
            //////////
            // Values to modify.

            // YOUR-APP-ID: The App ID GUID found on the luis.azure.cn Application Settings page.
            String AppId = "YOUR-APP-ID";

            // YOUR-AUTHORING-KEY: Your LUIS authoring key, 32 character value.
            String Key = "YOUR-AUTHORING-KEY";

            // YOUR-AUTHORING-ENDPOINT: Replace this with your authoring key endpoint.
            // For example, "https://your-resource-name.cognitiveservices.azure.cn/"
            String Endpoint = "https://YOUR-AUTHORING-ENDPOINT/";

            // NOTE: Replace this your version number. The Pizza app uses a version number of "0.1".
            String Version = "0.1";
            //////////

            // The list of utterances to add, in JSON format.
            String Utterances = "[{'text': 'order a pizza', 'intentName': 'ModifyOrder', 'entityLabels': [{'entityName': 'Order', 'startCharIndex': 6, 'endCharIndex': 12}]}, {'text': 'order a large pepperoni pizza', 'intentName': 'ModifyOrder', 'entityLabels': [{'entityName': 'Order', 'startCharIndex': 6, 'endCharIndex': 28}, {'entityName': 'FullPizzaWithModifiers', 'startCharIndex': 6, 'endCharIndex': 28}, {'entityName': 'PizzaType', 'startCharIndex': 14, 'endCharIndex': 28}, {'entityName': 'Size', 'startCharIndex': 8, 'endCharIndex': 12}]}, {'text': 'I want two large pepperoni pizzas on thin crust', 'intentName': 'ModifyOrder', 'entityLabels': [{'entityName': 'Order', 'startCharIndex': 7, 'endCharIndex': 46}, {'entityName': 'FullPizzaWithModifiers', 'startCharIndex': 7, 'endCharIndex': 46}, {'entityName': 'PizzaType', 'startCharIndex': 17, 'endCharIndex': 32}, {'entityName': 'Size', 'startCharIndex': 11, 'endCharIndex': 15}, {'entityName': 'Quantity', 'startCharIndex': 7, 'endCharIndex': 9}, {'entityName': 'Crust', 'startCharIndex': 37, 'endCharIndex': 46}]}]";

            // Create the URLs for uploading example utterances and for training.
            URIBuilder addUtteranceURL = new URIBuilder(Endpoint + "luis/authoring/v3.0-preview/apps/" + AppId + "/versions/" + Version + "/examples");
            URIBuilder trainURL = new URIBuilder(Endpoint + "luis/authoring/v3.0-preview/apps/" + AppId + "/versions/" + Version + "/train");
            URI addUtterancesURI = addUtteranceURL.build();
            URI trainURI = trainURL.build();


            // Add the utterances.

            // Create the request.
            HttpClient addUtterancesClient = HttpClients.createDefault();
            HttpPost addUtterancesRequest = new HttpPost(addUtterancesURI);

            // Add the headers.
            addUtterancesRequest.setHeader("Ocp-Apim-Subscription-Key",Key);
            addUtterancesRequest.setHeader("Content-type","application/json");

            // Add the body.
            StringEntity stringEntity = new StringEntity(Utterances);
            addUtterancesRequest.setEntity(stringEntity);

            // Execute the request and obtain the response.
            HttpResponse addUtterancesResponse = addUtterancesClient.execute(addUtterancesRequest);
            HttpEntity addUtterancesEntity = addUtterancesResponse.getEntity();

            // Print the response on the console.
            if (addUtterancesEntity != null)
            {
                System.out.println(EntityUtils.toString(addUtterancesEntity));
            }


            // Train the model.

            // Create the request.
            HttpClient trainClient = HttpClients.createDefault();
            HttpPost trainRequest = new HttpPost(trainURI);

            // Add the headers.
            trainRequest.setHeader("Ocp-Apim-Subscription-Key",Key);
            trainRequest.setHeader("Content-type","application/json");

            // Execute the request and obtain the response.
            HttpResponse trainResponse = trainClient.execute(trainRequest);
            HttpEntity trainEntity = trainResponse.getEntity();

            // Print the response on the console.
            if (trainEntity != null)
            {
                System.out.println(EntityUtils.toString(trainEntity));
            }


            // Get the training status.


            // Create the request.
            HttpClient trainStatusClient = HttpClients.createDefault();
            HttpGet trainStatusRequest = new HttpGet(trainURI);

            // Add the headers.
            trainStatusRequest.setHeader("Ocp-Apim-Subscription-Key",Key);
            trainStatusRequest.setHeader("Content-type","application/json");

            // Execute the request and obtain the response.
            HttpResponse trainStatusResponse = trainStatusClient.execute(trainStatusRequest);
            HttpEntity trainStatusEntity = trainStatusResponse.getEntity();

            // Print the response on the console.
            if (trainStatusEntity != null)
            {
                System.out.println(EntityUtils.toString(trainStatusEntity));
            }
        }

        // Display errors if they occur.
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}
  1. 将以 YOUR- 开头的值替换为你自己的值。Replace the values starting with YOUR- with your own values.

    信息Information 目的Purpose
    YOUR-APP-ID LUIS 应用 ID。Your LUIS app ID.
    YOUR-AUTHORING-KEY 32 字符创作密钥。Your 32 character authoring key.
    YOUR-AUTHORING-ENDPOINT 创作 URL 终结点。Your authoring URL endpoint. 例如,https://replace-with-your-resource-name.api.cognitive.azure.cn/For example, https://replace-with-your-resource-name.api.cognitive.azure.cn/. 在创建资源时设置资源名称。You set your resource name when you created the resource.

    分配的密钥和资源可以在 LUIS 门户的“Azure 资源”页上的“管理”部分中看到。Assigned keys and resources are visible in the LUIS portal in the Manage section, on the Azure resources page. 应用 ID 可以在“应用程序设置”页的同一“管理”部分中找到。The app ID is available in the same Manage section, on the Application Settings page.

  2. 在创建 Model.java 文件的同一目录中,在命令提示符下输入以下命令来编译 Java 文件:With a command prompt in the same directory as where you created the Model.java file, enter the following command to compile the Java file:

    • 如果使用的是 Windows,请使用此命令:javac -cp ";lib/*" Model.javaIf you are using Windows, use this command: javac -cp ";lib/*" Model.java
    • 如果使用的是 macOS 或 Linux,请使用此命令:javac -cp ":lib/*" Model.javaIf you are using macOS or Linux, use this command: javac -cp ":lib/*" Model.java
  3. 通过在命令提示符下输入以下文本从命令行运行 Java 应用程序:Run the Java application from the command line by entering the following text in the command prompt:

    • 如果使用的是 Windows,请使用此命令:java -cp ";lib/*" ModelIf you are using Windows, use this command: java -cp ";lib/*" Model
    • 如果使用的是 macOS 或 Linux,请使用此命令:java -cp ":lib/*" ModelIf you are using macOS or Linux, use this command: java -cp ":lib/*" Model
  4. 查看创作响应:Review the authoring response:

    [{"value":{"ExampleId":1137150691,"UtteranceText":"order a pizza"},"hasError":false},{"value":{"ExampleId":1137150692,"UtteranceText":"order a large pepperoni pizza"},"hasError":false},{"value":{"ExampleId":1137150693,"UtteranceText":"i want two large pepperoni pizzas on thin crust"},"hasError":false}]
    {"statusId":9,"status":"Queued"}
    [{"modelId":"edb46abf-0000-41ab-beb2-a41a0fe1630f","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"a5030be2-616c-4648-bf2f-380fa9417d37","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"3f2b1f31-a3c3-4fbd-8182-e9d9dbc120b9","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"e4b6704b-1636-474c-9459-fe9ccbeba51c","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"031d3777-2a00-4a7a-9323-9a3280a30000","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"9250e7a1-06eb-4413-9432-ae132ed32583","details":{"statusId":3,"status":"InProgress","exampleCount":0,"progressSubstatus":"CollectingData"}}]
    

    下面是为提高可读性而进行了格式设置的输出:Here is the output formatted for readability:

    [
      {
        "value": {
          "ExampleId": 1137150691,
          "UtteranceText": "order a pizza"
        },
        "hasError": false
      },
      {
        "value": {
          "ExampleId": 1137150692,
          "UtteranceText": "order a large pepperoni pizza"
        },
        "hasError": false
      },
      {
        "value": {
          "ExampleId": 1137150693,
          "UtteranceText": "i want two large pepperoni pizzas on thin crust"
        },
        "hasError": false
      }
    ]
    {
      "statusId": 9,
      "status": "Queued"
    }
    [
      {
        "modelId": "edb46abf-0000-41ab-beb2-a41a0fe1630f",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "a5030be2-616c-4648-bf2f-380fa9417d37",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "3f2b1f31-a3c3-4fbd-8182-e9d9dbc120b9",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "e4b6704b-1636-474c-9459-fe9ccbeba51c",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "031d3777-2a00-4a7a-9323-9a3280a30000",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "9250e7a1-06eb-4413-9432-ae132ed32583",
        "details": {
          "statusId": 3,
          "status": "InProgress",
          "exampleCount": 0,
          "progressSubstatus": "CollectingData"
        }
      }
    ]
    

清理资源Clean up resources

完成本快速入门后,请从文件系统中删除项目文件夹。When you are finished with this quickstart, delete the project folder from the file system.

后续步骤Next steps

参考文档 | 示例Reference documentation | Sample

先决条件Prerequisites

示例话语 JSON 文件Example utterances JSON file

示例言语采用特定格式。The example utterances follow a specific format.

text 字段包含示例话语的文本。The text field contains the text of the example utterance. intentName 字段必须对应于 LUIS 应用中的现有意向名称。The intentName field must correspond to the name of an existing intent in the LUIS app. entityLabels 字段是必填的。The entityLabels field is required. 如果不想标记任何实体,请提供一个空数组。If you don't want to label any entities, provide an empty array.

如果 entityLabels 数组不为空,则 startCharIndexendCharIndex 需要标记 entityName 字段中引用的实体。If the entityLabels array is not empty, the startCharIndex and endCharIndex need to mark the entity referred to in the entityName field. 该索引从零开始。The index is zero-based. 如果标签的起始或结尾位于文本中的空白处,则添加话语的 API 调用将失败。If you begin or end the label at a space in the text, the API call to add the utterances fails.

[
  {
    "text": "order a pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "order a large pepperoni pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 14,
        "endCharIndex": 28
      },
      {
        "entityName": "Size",
        "startCharIndex": 8,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "I want two large pepperoni pizzas on thin crust",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 17,
        "endCharIndex": 32
      },
      {
        "entityName": "Size",
        "startCharIndex": 11,
        "endCharIndex": 15
      },
      {
        "entityName": "Quantity",
        "startCharIndex": 7,
        "endCharIndex": 9
      },
      {
        "entityName": "Crust",
        "startCharIndex": 37,
        "endCharIndex": 46
      }
    ]
  }
]

创建披萨应用Create Pizza app

创建披萨应用。Create the pizza app.

  1. 选择 pizza-app-for-luis-v6.json,打开 pizza-app-for-luis.json 文件的 GitHub 页面。Select pizza-app-for-luis-v6.json to bring up the GitHub page for the pizza-app-for-luis.json file.
  2. 右键单击或长按“原始”按钮,然后选择“将链接另存为”,将 pizza-app-for-luis.json 保存到计算机 。Right-click or long tap the Raw button and select Save link as to save the pizza-app-for-luis.json to your computer.
  3. 登录到 LUIS 门户Sign into the LUIS portal.
  4. 选择我的应用Select My Apps.
  5. 在“我的应用”页面上,选择“+ 新建用于对话的应用” 。On the My Apps page, select + New app for conversation.
  6. 选择“导入为 JSON”。Select Import as JSON.
  7. 在“导入新应用”对话框中,选择“选择文件”按钮 。In the Import new app dialog, select the Choose File button.
  8. 选择下载的 pizza-app-for-luis.json 文件,然后选择“打开”。Select the pizza-app-for-luis.json file you downloaded, then select Open.
  9. 在“导入新应用”对话框的“名称”字段中,输入 Pizza 应用的名称,然后选择“完成”按钮 。In the Import new app dialog Name field, enter a name for your Pizza app, then select the Done button.

随即导入应用。The app will be imported.

如果看到一个对话框“如何创建有效的 LUIS 应用”,关闭该对话框。If you see a dialog How to create an effective LUIS app, close the dialog.

训练并发布 Pizza 应用Train and publish the Pizza app

Pizza 应用中应会显示“意向”页面,其中显示了一个意向列表。You should see the Intents page with a list of the intents in the Pizza app.

  1. 在 LUIS 网站的右上方,选择“训练”按钮。In the top-right side of the LUIS website, select the Train button.

    “训练”按钮

  2. 当“训练”按钮上的状态指示器为绿色时,即表示训练完成。Training is complete when status indicator on the Train button is green.

若要在聊天机器人或其他客户端应用程序中接收 LUIS 预测,需要将应用发布到预测终结点。In order to receive a LUIS prediction in a chat bot or other client application, you need to publish the app to the prediction endpoint.

  1. 在右上方的导航栏中选择“发布”。Select Publish in the top-right navigation.

    右上方菜单中的“LUIS 发布到终结点”按钮的屏幕截图Screenshot of LUIS publish to endpoint button in top right menu

  2. 选择“生产”槽,然后选择“完成” 。Select the Production slot, then select Done.

    “LUIS 发布到终结点”的屏幕截图Screenshot of LUIS publish to endpoint

  3. 在通知中选择“访问终结点 URL”,以转到“Azure 资源”页 。Select Access your endpoint URLs in the notification to go to the Azure Resources page. 只有你拥有与应用关联的预测资源时,才能看到 URL。You will only be able to see the URLs if you have a prediction resource associated with the app. 还可以单击“管理”来找到“Azure 资源”页 。You can also find the Azure Resources page by clicking Manage.

    指示应用已发布的消息A message that the app has been published

向披萨应用添加创作资源Add an authoring resource to the Pizza app

  1. 选择“管理”。Select MANAGE.
  2. 选择“Azure 资源”。Select Azure Resources.
  3. 选择“创作资源”。Select Authoring Resource.
  4. 选择“更改创作资源”。Select Change authoring resource.

如果你有创作资源,请输入你的创作资源的租户名称、订阅名称以及 LUIS 资源名称。If you have an authoring resource, enter the Tenant Name, Subscription Name, and LUIS resource name of your authoring resource.

如果你没有创作资源:If you do not have an authoring resource:

  1. 选择“新建资源”。Select Create new resource.
  2. 输入租户名称、资源名称、订阅名称和 Azure 资源组名称。Enter a Tenant Name, Resource Name, Subscription Name, and Azure Resource Group Name.

现在 Pizza 应用可以使用了。Your Pizza app is now ready to use.

记录 Pizza 应用的访问值Record the access values for your Pizza app

若要使用新的披萨应用,你需要该披萨应用的应用 ID、授权密钥和授权终结点。To use your new Pizza app, you will need the app ID, authoring key, and authoring endpoint of your Pizza app. 若要获取预测,需要单独的预测终结点和预测密钥。To get predictions, you will need your separate prediction endpoint and prediction key.

若要查找这些值:To find these values:

  1. 在“意向”页面,选择“管理” 。From the Intents page, select MANAGE.
  2. 在“应用程序设置”页面,记录“应用 ID” 。From the Application Settings page, record the App ID.
  3. 选择“Azure 资源”。Select Azure Resources.
  4. 选择“创作资源”。Select Authoring Resource.
  5. 从“创作资源”和“预测资源”选项卡,记录“主键” 。From the Authoring Resource and Prediction Resources tabs, record the Primary Key. 此值是你的创作密钥。This value is your authoring key.
  6. 记录“终结点 URL”。Record the Endpoint URL. 此值是你的创作终结点。This value is your authoring endpoint.

以编程方式更改模型Change model programmatically

  1. 创建名为 predict.go 的新文件。Create a new file named predict.go. 添加以下代码:Add the following code:
//
// This quickstart shows how to add utterances to a LUIS model using the REST APIs.
//

// dependencies
package main
import (
    "fmt"
    "net/http"
    "io/ioutil"
    "log"
    "strings"
)

// main function
func main() {

    //////////
    // Values to modify.

    // YOUR-APP-ID: The App ID GUID found on the luis.azure.cn Application Settings page.
    var appID = "YOUR-APP-ID"

    // YOUR-AUTHORING-KEY: Your LUIS authoring key, 32 character value.
    var authoringKey = "YOUR-AUTHORING-KEY"

    //  YOUR-AUTHORING-ENDPOINT: Replace this with your authoring key endpoint.
    // For example, "https://your-resource-name.cognitiveservices.azure.cn/"
    var endpoint = "https://YOUR-AUTHORING-ENDPOINT/"

    // NOTE: Replace this your version number. The Pizza app uses a version number of "0.1".
    var version = "0.1"
    //////////

    var exampleUtterances = "[{'text': 'order a pizza', 'intentName': 'ModifyOrder', 'entityLabels': [{'entityName': 'Order', 'startCharIndex': 6, 'endCharIndex': 12}]}, {'text': 'order a large pepperoni pizza', 'intentName': 'ModifyOrder', 'entityLabels': [{'entityName': 'Order', 'startCharIndex': 6, 'endCharIndex': 28}, {'entityName': 'FullPizzaWithModifiers', 'startCharIndex': 6, 'endCharIndex': 28}, {'entityName': 'PizzaType', 'startCharIndex': 14, 'endCharIndex': 28}, {'entityName': 'Size', 'startCharIndex': 8, 'endCharIndex': 12}]}, {'text': 'I want two large pepperoni pizzas on thin crust', 'intentName': 'ModifyOrder', 'entityLabels': [{'entityName': 'Order', 'startCharIndex': 7, 'endCharIndex': 46}, {'entityName': 'FullPizzaWithModifiers', 'startCharIndex': 7, 'endCharIndex': 46}, {'entityName': 'PizzaType', 'startCharIndex': 17, 'endCharIndex': 32}, {'entityName': 'Size', 'startCharIndex': 11, 'endCharIndex': 15}, {'entityName': 'Quantity', 'startCharIndex': 7, 'endCharIndex': 9}, {'entityName': 'Crust', 'startCharIndex': 37, 'endCharIndex': 46}]}]"

    fmt.Println("add example utterances requested")
    addUtterance(authoringKey, appID, version, exampleUtterances, endpoint)

    fmt.Println("training selected")
    requestTraining(authoringKey, appID, version, endpoint)

    fmt.Println("training status selected")
    getTrainingStatus(authoringKey, appID, version, endpoint)
}

// Send the list of utterances to the model.
func addUtterance(authoringKey string, appID string,  version string, labeledExampleUtterances string, endpoint string){

    var authoringUrl = fmt.Sprintf("%sluis/authoring/v3.0-preview/apps/%s/versions/%s/examples", endpoint, appID, version)

    httpRequest("POST", authoringUrl, authoringKey, labeledExampleUtterances)
}

// Request training.
func requestTraining(authoringKey string, appID string,  version string, endpoint string){

    trainApp("POST", authoringKey, appID, version, endpoint)
}


func trainApp(httpVerb string, authoringKey string, appID string,  version string, endpoint string){

    var authoringUrl = fmt.Sprintf("%sluis/authoring/v3.0-preview/apps/%s/versions/%s/train", endpoint, appID, version)

    httpRequest(httpVerb,authoringUrl, authoringKey, "")
}


func getTrainingStatus(authoringKey string, appID string, version string, endpoint string){

    trainApp("GET", authoringKey, appID, version, endpoint)
}

// generic HTTP request
// includes setting header with authoring key
func httpRequest(httpVerb string, url string, authoringKey string, body string){

    client := &http.Client{}

    request, err := http.NewRequest(httpVerb, url, strings.NewReader(body))
    request.Header.Add("Ocp-Apim-Subscription-Key", authoringKey)

    fmt.Println("body")
    fmt.Println(body)

    response, err := client.Do(request)

    if err != nil {
        log.Fatal(err)
    } else {
        defer response.Body.Close()

        contents, err := ioutil.ReadAll(response.Body)

        if err != nil {
            log.Fatal(err)
        }

        fmt.Println("   ", response.StatusCode)
        fmt.Println(string(contents))
    }
}
  1. 将以 YOUR- 开头的值替换为你自己的值。Replace the values starting with YOUR- with your own values.

    信息Information 目的Purpose
    YOUR-APP-ID LUIS 应用 ID。Your LUIS app ID.
    YOUR-AUTHORING-KEY 32 字符创作密钥。Your 32 character authoring key.
    YOUR-AUTHORING-ENDPOINT 创作 URL 终结点。Your authoring URL endpoint. 例如,https://replace-with-your-resource-name.api.cognitive.azure.cn/For example, https://replace-with-your-resource-name.api.cognitive.azure.cn/. 在创建资源时设置资源名称。You set your resource name when you created the resource.

    分配的密钥和资源可以在 LUIS 门户的“Azure 资源”页上的“管理”部分中看到。Assigned keys and resources are visible in the LUIS portal in the Manage section, on the Azure resources page. 应用 ID 可以在“应用程序设置”页的同一“管理”部分中找到。The app ID is available in the same Manage section, on the Application Settings page.

  2. 在创建该文件的同一目录中,在命令提示符下输入以下命令来编译 Go 文件:With a command prompt in the same directory as where you created the file, enter the following command to compile the Go file:

    go build model.go
    
  3. 通过在命令提示符下输入以下文本从命令行运行 Go 应用程序:Run the Go application from the command line by entering the following text in the command prompt:

    go run model.go
    
  4. 查看创作响应:Review the authoring response:

    add example utterances requested
    body
    [{'text': 'order a pizza', 'intentName': 'ModifyOrder', 'entityLabels': [{'entityName': 'Order', 'startCharIndex': 6, 'endCharIndex': 12}]}, {'text': 'order a large pepperoni pizza', 'intentName': 'ModifyOrder', 'entityLabels': [{'entityName': 'Order', 'startCharIndex': 6, 'endCharIndex': 28}, {'entityName': 'FullPizzaWithModifiers', 'startCharIndex': 6, 'endCharIndex': 28}, {'entityName': 'PizzaType', 'startCharIndex': 14, 'endCharIndex': 28}, {'entityName': 'Size', 'startCharIndex': 8, 'endCharIndex': 12}]}, {'text': 'I want two large pepperoni pizzas on thin crust', 'intentName': 'ModifyOrder', 'entityLabels': [{'entityName': 'Order', 'startCharIndex': 7, 'endCharIndex': 46}, {'entityName': 'FullPizzaWithModifiers', 'startCharIndex': 7, 'endCharIndex': 46}, {'entityName': 'PizzaType', 'startCharIndex': 17, 'endCharIndex': 32}, {'entityName': 'Size', 'startCharIndex': 11, 'endCharIndex': 15}, {'entityName': 'Quantity', 'startCharIndex': 7, 'endCharIndex': 9}, {'entityName': 'Crust', 'startCharIndex': 37, 'endCharIndex': 46}]}]
        201
    [{"value":{"ExampleId":1137150691,"UtteranceText":"order a pizza"},"hasError":false},{"value":{"ExampleId":1137150692,"UtteranceText":"order a large pepperoni pizza"},"hasError":false},{"value":{"ExampleId":1137150693,"UtteranceText":"i want two large pepperoni pizzas on thin crust"},"hasError":false}]
    training selected
    body
    
        202
    {"statusId":9,"status":"Queued"}
    training status selected
    body
    
        200
    [{"modelId":"edb46abf-0000-41ab-beb2-a41a0fe1630f","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"a5030be2-616c-4648-bf2f-380fa9417d37","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"3f2b1f31-a3c3-4fbd-8182-e9d9dbc120b9","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"e4b6704b-1636-474c-9459-fe9ccbeba51c","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"031d3777-2a00-4a7a-9323-9a3280a30000","details":{"statusId":9,"status":"Queued","exampleCount":0}},{"modelId":"9250e7a1-06eb-4413-9432-ae132ed32583","details":{"statusId":9,"status":"Queued","exampleCount":0}}]
    

    下面是为提高可读性而进行了格式设置的输出:Here is the output formatted for readability:

    add example utterances requested
    body
    [
      {
        'text': 'order a pizza',
        'intentName': 'ModifyOrder',
        'entityLabels': [
          {
            'entityName': 'Order',
            'startCharIndex': 6,
            'endCharIndex': 12
          }
        ]
      },
      {
        'text': 'order a large pepperoni pizza',
        'intentName': 'ModifyOrder',
        'entityLabels': [
          {
            'entityName': 'Order',
            'startCharIndex': 6,
            'endCharIndex': 28
          },
          {
            'entityName': 'FullPizzaWithModifiers',
            'startCharIndex': 6,
            'endCharIndex': 28
          },
          {
            'entityName': 'PizzaType',
            'startCharIndex': 14,
            'endCharIndex': 28
          },
          {
            'entityName': 'Size',
            'startCharIndex': 8,
            'endCharIndex': 12
          }
        ]
      },
      {
        'text': 'I want two large pepperoni pizzas on thin crust',
        'intentName': 'ModifyOrder',
        'entityLabels': [
          {
            'entityName': 'Order',
            'startCharIndex': 7,
            'endCharIndex': 46
          },
          {
            'entityName': 'FullPizzaWithModifiers',
            'startCharIndex': 7,
            'endCharIndex': 46
          },
          {
            'entityName': 'PizzaType',
            'startCharIndex': 17,
            'endCharIndex': 32
          },
          {
            'entityName': 'Size',
            'startCharIndex': 11,
            'endCharIndex': 15
          },
          {
            'entityName': 'Quantity',
            'startCharIndex': 7,
            'endCharIndex': 9
          },
          {
            'entityName': 'Crust',
            'startCharIndex': 37,
            'endCharIndex': 46
          }
        ]
      }
    ]
    
        201
    [
      {
        "value": {
          "ExampleId": 1137150691,
          "UtteranceText": "order a pizza"
        },
        "hasError": false
      },
      {
        "value": {
          "ExampleId": 1137150692,
          "UtteranceText": "order a large pepperoni pizza"
        },
        "hasError": false
      },
      {
        "value": {
          "ExampleId": 1137150693,
          "UtteranceText": "i want two large pepperoni pizzas on thin crust"
        },
        "hasError": false
      }
    ]
    training selected
    body
    
        202
    {
      "statusId": 9,
      "status": "Queued"
    }
    training status selected
    body
    
        200
    [
      {
        "modelId": "edb46abf-0000-41ab-beb2-a41a0fe1630f",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "a5030be2-616c-4648-bf2f-380fa9417d37",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "3f2b1f31-a3c3-4fbd-8182-e9d9dbc120b9",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "e4b6704b-1636-474c-9459-fe9ccbeba51c",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "031d3777-2a00-4a7a-9323-9a3280a30000",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "9250e7a1-06eb-4413-9432-ae132ed32583",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      }
    ]
    

清理资源Clean up resources

完成本快速入门后,请从文件系统中删除该文件。When you are finished with this quickstart, delete the file from the file system.

后续步骤Next steps

参考文档 | 示例Reference documentation | Sample

先决条件Prerequisites

示例话语 JSON 文件Example utterances JSON file

示例言语采用特定格式。The example utterances follow a specific format.

text 字段包含示例话语的文本。The text field contains the text of the example utterance. intentName 字段必须对应于 LUIS 应用中的现有意向名称。The intentName field must correspond to the name of an existing intent in the LUIS app. entityLabels 字段是必填的。The entityLabels field is required. 如果不想标记任何实体,请提供一个空数组。If you don't want to label any entities, provide an empty array.

如果 entityLabels 数组不为空,则 startCharIndexendCharIndex 需要标记 entityName 字段中引用的实体。If the entityLabels array is not empty, the startCharIndex and endCharIndex need to mark the entity referred to in the entityName field. 该索引从零开始。The index is zero-based. 如果标签的起始或结尾位于文本中的空白处,则添加话语的 API 调用将失败。If you begin or end the label at a space in the text, the API call to add the utterances fails.

[
  {
    "text": "order a pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "order a large pepperoni pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 14,
        "endCharIndex": 28
      },
      {
        "entityName": "Size",
        "startCharIndex": 8,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "I want two large pepperoni pizzas on thin crust",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 17,
        "endCharIndex": 32
      },
      {
        "entityName": "Size",
        "startCharIndex": 11,
        "endCharIndex": 15
      },
      {
        "entityName": "Quantity",
        "startCharIndex": 7,
        "endCharIndex": 9
      },
      {
        "entityName": "Crust",
        "startCharIndex": 37,
        "endCharIndex": 46
      }
    ]
  }
]

创建 Node.js 项目Create the Node.js project

  1. 创建一个新文件夹以保存 Node.js 项目,例如 node-model-with-restCreate a new folder to hold your Node.js project, such as node-model-with-rest.

  2. 打开新的命令提示符,导航到你创建的文件夹,并执行以下命令:Open a new Command Prompt, navigate to the folder you created and execute the following command:

    npm init
    

    在每个提示符下按 Enter 以接受默认设置。Press Enter at each prompt to accept the default settings.

  3. 输入以下命令安装“请求-承诺”模块:Install the request-promise module by entering the following command:

    npm install --save request
    npm install --save request-promise
    npm install --save querystring
    

以编程方式更改模型Change model programmatically

  1. 创建名为 model.js 的新文件。Create a new file named model.js. 添加以下代码:Add the following code:
//
// This quickstart shows how to add utterances to a LUIS model using the REST APIs.
//

var request = require('request-promise');

//////////
// Values to modify.

// YOUR-APP-ID: The App ID GUID found on the luis.azure.cn Application Settings page.
const LUIS_appId = "YOUR-APP-ID";

// YOUR-AUTHORING-KEY: Your LUIS authoring key, 32 character value.
const LUIS_authoringKey = "YOUR-AUTHORING-KEY";

// YOUR-AUTHORING-ENDPOINT: Replace this with your authoring key endpoint.
// For example, "https://your-resource-name.cognitiveservices.azure.cn/"
const LUIS_endpoint = "https://YOUR-AUTHORING-ENDPOINT/";

// NOTE: Replace this your version number. The Pizza app uses a version number of "0.1".
const LUIS_versionId = "0.1";
//////////

const addUtterancesURI = `${LUIS_endpoint}luis/authoring/v3.0-preview/apps/${LUIS_appId}/versions/${LUIS_versionId}/examples`;
const addTrainURI = `${LUIS_endpoint}luis/authoring/v3.0-preview/apps/${LUIS_appId}/versions/${LUIS_versionId}/train`;

const utterances = [
    {
        'text': 'order a pizza',
        'intentName': 'ModifyOrder',
        'entityLabels': [
            {
                'entityName': 'Order',
                'startCharIndex': 6,
                'endCharIndex': 12
            }
        ]
    },
    {
        'text': 'order a large pepperoni pizza',
        'intentName': 'ModifyOrder',
        'entityLabels': [
            {
                'entityName': 'Order',
                'startCharIndex': 6,
                'endCharIndex': 28
            },
            {
                'entityName': 'FullPizzaWithModifiers',
                'startCharIndex': 6,
                'endCharIndex': 28
            },
            {
                'entityName': 'PizzaType',
                'startCharIndex': 14,
                'endCharIndex': 28
            },
            {
                'entityName': 'Size',
                'startCharIndex': 8,
                'endCharIndex': 12
            }
        ]
    },
    {
        'text': 'I want two large pepperoni pizzas on thin crust',
        'intentName': 'ModifyOrder',
        'entityLabels': [
            {
                'entityName': 'Order',
                'startCharIndex': 7,
                'endCharIndex': 46
            },
            {
                'entityName': 'FullPizzaWithModifiers',
                'startCharIndex': 7,
                'endCharIndex': 46
            },
            {
                'entityName': 'PizzaType',
                'startCharIndex': 17,
                'endCharIndex': 32
            },
            {
                'entityName': 'Size',
                'startCharIndex': 11,
                'endCharIndex': 15
            },
            {
                'entityName': 'Quantity',
                'startCharIndex': 7,
                'endCharIndex': 9
            },
            {
                'entityName': 'Crust',
                'startCharIndex': 37,
                'endCharIndex': 46
            }
        ]
    }
];

// Main function.
const main = async() =>{

    await addUtterances(utterances);
    await train("POST");
    await train("GET");

}

// Adds the utterances to the model.
const addUtterances = async (utterances) => {

    const options = {
        uri: addUtterancesURI,
        method: 'POST',
        headers: {
            'Ocp-Apim-Subscription-Key': LUIS_authoringKey
        },
        json: true,
        body: utterances
    };

    const response = await request(options)
    console.log("addUtterance:\n" + JSON.stringify(response, null, 2));
}

// With verb === "POST", sends a training request.
// With verb === "GET", obtains the training status.
const train = async (verb) => {

    const options = {
        uri: addTrainURI,
        method: verb,
        headers: {
            'Ocp-Apim-Subscription-Key': LUIS_authoringKey
        },
        json: true,
        body: null // The body can be empty for a training request
    };

    const response = await request(options)
    console.log("train " + verb + ":\n" + JSON.stringify(response, null, 2));
}

// MAIN
main().then(() => console.log("done")).catch((err)=> console.log(err));
  1. 将以 YOUR- 开头的值替换为你自己的值。Replace the values starting with YOUR- with your own values.

    信息Information 目的Purpose
    YOUR-APP-ID LUIS 应用 ID。Your LUIS app ID.
    YOUR-AUTHORING-KEY 32 字符创作密钥。Your 32 character authoring key.
    YOUR-AUTHORING-ENDPOINT 创作 URL 终结点。Your authoring URL endpoint. 例如,https://replace-with-your-resource-name.api.cognitive.azure.cn/For example, https://replace-with-your-resource-name.api.cognitive.azure.cn/. 在创建资源时设置资源名称。You set your resource name when you created the resource.

    分配的密钥和资源可以在 LUIS 门户的“Azure 资源”页上的“管理”部分中看到。Assigned keys and resources are visible in the LUIS portal in the Manage section, on the Azure resources page. 应用 ID 可以在“应用程序设置”页的同一“管理”部分中找到。The app ID is available in the same Manage section, on the Application Settings page.

  2. 在命令提示符处,输入下列命令以运行项目:At the command prompt, enter the following command to run the project:

    node model.js
    
  3. 查看创作响应:Review the authoring response:

    addUtterance:
    [
      {
        "value": {
          "ExampleId": 1137150691,
          "UtteranceText": "order a pizza"
        },
        "hasError": false
      },
      {
        "value": {
          "ExampleId": 1137150692,
          "UtteranceText": "order a large pepperoni pizza"
        },
        "hasError": false
      },
      {
        "value": {
          "ExampleId": 1137150693,
          "UtteranceText": "i want two large pepperoni pizzas on thin crust"
        },
        "hasError": false
      }
    ]
    train POST:
    {
      "statusId": 9,
      "status": "Queued"
    }
    train GET:
    [
      {
        "modelId": "edb46abf-0000-41ab-beb2-a41a0fe1630f",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "a5030be2-616c-4648-bf2f-380fa9417d37",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "3f2b1f31-a3c3-4fbd-8182-e9d9dbc120b9",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "e4b6704b-1636-474c-9459-fe9ccbeba51c",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "031d3777-2a00-4a7a-9323-9a3280a30000",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      },
      {
        "modelId": "9250e7a1-06eb-4413-9432-ae132ed32583",
        "details": {
          "statusId": 9,
          "status": "Queued",
          "exampleCount": 0
        }
      }
    ]
    done
    

清理资源Clean up resources

完成本快速入门后,请从文件系统中删除项目文件夹。When you are finished with this quickstart, delete the project folder from the file system.

后续步骤Next steps

参考文档 | 示例Reference documentation | Sample

先决条件Prerequisites

示例话语 JSON 文件Example utterances JSON file

示例言语采用特定格式。The example utterances follow a specific format.

text 字段包含示例话语的文本。The text field contains the text of the example utterance. intentName 字段必须对应于 LUIS 应用中的现有意向名称。The intentName field must correspond to the name of an existing intent in the LUIS app. entityLabels 字段是必填的。The entityLabels field is required. 如果不想标记任何实体,请提供一个空数组。If you don't want to label any entities, provide an empty array.

如果 entityLabels 数组不为空,则 startCharIndexendCharIndex 需要标记 entityName 字段中引用的实体。If the entityLabels array is not empty, the startCharIndex and endCharIndex need to mark the entity referred to in the entityName field. 该索引从零开始。The index is zero-based. 如果标签的起始或结尾位于文本中的空白处,则添加话语的 API 调用将失败。If you begin or end the label at a space in the text, the API call to add the utterances fails.

[
  {
    "text": "order a pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "order a large pepperoni pizza",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 6,
        "endCharIndex": 28
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 14,
        "endCharIndex": 28
      },
      {
        "entityName": "Size",
        "startCharIndex": 8,
        "endCharIndex": 12
      }
    ]
  },
  {
    "text": "I want two large pepperoni pizzas on thin crust",
    "intentName": "ModifyOrder",
    "entityLabels": [
      {
        "entityName": "Order",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "FullPizzaWithModifiers",
        "startCharIndex": 7,
        "endCharIndex": 46
      },
      {
        "entityName": "PizzaType",
        "startCharIndex": 17,
        "endCharIndex": 32
      },
      {
        "entityName": "Size",
        "startCharIndex": 11,
        "endCharIndex": 15
      },
      {
        "entityName": "Quantity",
        "startCharIndex": 7,
        "endCharIndex": 9
      },
      {
        "entityName": "Crust",
        "startCharIndex": 37,
        "endCharIndex": 46
      }
    ]
  }
]

创建披萨应用Create Pizza app

创建披萨应用。Create the pizza app.

  1. 选择 pizza-app-for-luis-v6.json,打开 pizza-app-for-luis.json 文件的 GitHub 页面。Select pizza-app-for-luis-v6.json to bring up the GitHub page for the pizza-app-for-luis.json file.
  2. 右键单击或长按“原始”按钮,然后选择“将链接另存为”,将 pizza-app-for-luis.json 保存到计算机 。Right-click or long tap the Raw button and select Save link as to save the pizza-app-for-luis.json to your computer.
  3. 登录到 LUIS 门户Sign into the LUIS portal.
  4. 选择我的应用Select My Apps.
  5. 在“我的应用”页面上,选择“+ 新建用于对话的应用” 。On the My Apps page, select + New app for conversation.
  6. 选择“导入为 JSON”。Select Import as JSON.
  7. 在“导入新应用”对话框中,选择“选择文件”按钮 。In the Import new app dialog, select the Choose File button.
  8. 选择下载的 pizza-app-for-luis.json 文件,然后选择“打开”。Select the pizza-app-for-luis.json file you downloaded, then select Open.
  9. 在“导入新应用”对话框的“名称”字段中,输入 Pizza 应用的名称,然后选择“完成”按钮 。In the Import new app dialog Name field, enter a name for your Pizza app, then select the Done button.

随即导入应用。The app will be imported.

如果看到一个对话框“如何创建有效的 LUIS 应用”,关闭该对话框。If you see a dialog How to create an effective LUIS app, close the dialog.

训练并发布 Pizza 应用Train and publish the Pizza app

Pizza 应用中应会显示“意向”页面,其中显示了一个意向列表。You should see the Intents page with a list of the intents in the Pizza app.

  1. 在 LUIS 网站的右上方,选择“训练”按钮。In the top-right side of the LUIS website, select the Train button.

    “训练”按钮

  2. 当“训练”按钮上的状态指示器为绿色时,即表示训练完成。Training is complete when status indicator on the Train button is green.

若要在聊天机器人或其他客户端应用程序中接收 LUIS 预测,需要将应用发布到预测终结点。In order to receive a LUIS prediction in a chat bot or other client application, you need to publish the app to the prediction endpoint.

  1. 在右上方的导航栏中选择“发布”。Select Publish in the top-right navigation.

    右上方菜单中的“LUIS 发布到终结点”按钮的屏幕截图Screenshot of LUIS publish to endpoint button in top right menu

  2. 选择“生产”槽,然后选择“完成” 。Select the Production slot, then select Done.

    “LUIS 发布到终结点”的屏幕截图Screenshot of LUIS publish to endpoint

  3. 在通知中选择“访问终结点 URL”,以转到“Azure 资源”页 。Select Access your endpoint URLs in the notification to go to the Azure Resources page. 只有你拥有与应用关联的预测资源时,才能看到 URL。You will only be able to see the URLs if you have a prediction resource associated with the app. 还可以单击“管理”来找到“Azure 资源”页 。You can also find the Azure Resources page by clicking Manage.

    指示应用已发布的消息A message that the app has been published

向披萨应用添加创作资源Add an authoring resource to the Pizza app

  1. 选择“管理”。Select MANAGE.
  2. 选择“Azure 资源”。Select Azure Resources.
  3. 选择“创作资源”。Select Authoring Resource.
  4. 选择“更改创作资源”。Select Change authoring resource.

如果你有创作资源,请输入你的创作资源的租户名称、订阅名称以及 LUIS 资源名称。If you have an authoring resource, enter the Tenant Name, Subscription Name, and LUIS resource name of your authoring resource.

如果你没有创作资源:If you do not have an authoring resource:

  1. 选择“新建资源”。Select Create new resource.
  2. 输入租户名称、资源名称、订阅名称和 Azure 资源组名称。Enter a Tenant Name, Resource Name, Subscription Name, and Azure Resource Group Name.

现在 Pizza 应用可以使用了。Your Pizza app is now ready to use.

记录 Pizza 应用的访问值Record the access values for your Pizza app

若要使用新的披萨应用,你需要该披萨应用的应用 ID、授权密钥和授权终结点。To use your new Pizza app, you will need the app ID, authoring key, and authoring endpoint of your Pizza app. 若要获取预测,需要单独的预测终结点和预测密钥。To get predictions, you will need your separate prediction endpoint and prediction key.

若要查找这些值:To find these values:

  1. 在“意向”页面,选择“管理” 。From the Intents page, select MANAGE.
  2. 在“应用程序设置”页面,记录“应用 ID” 。From the Application Settings page, record the App ID.
  3. 选择“Azure 资源”。Select Azure Resources.
  4. 选择“创作资源”。Select Authoring Resource.
  5. 从“创作资源”和“预测资源”选项卡,记录“主键” 。From the Authoring Resource and Prediction Resources tabs, record the Primary Key. 此值是你的创作密钥。This value is your authoring key.
  6. 记录“终结点 URL”。Record the Endpoint URL. 此值是你的创作终结点。This value is your authoring endpoint.

以编程方式更改模型Change model programmatically

  1. 创建名为 model.py 的新文件。Create a new file named model.py. 添加以下代码:Add the following code:
########### Python 3.6 #############

#
# This quickstart shows how to add utterances to a LUIS model using the REST APIs.
#

import requests

try:

    ##########
    # Values to modify.

    # YOUR-APP-ID: The App ID GUID found on the luis.azure.cn Application Settings page.
    appId = "YOUR-APP-ID"

    # YOUR-AUTHORING-KEY: Your LUIS authoring key, 32 character value.
    authoring_key = "YOUR-AUTHORING-KEY"

    # YOUR-AUTHORING-ENDPOINT: Replace this with your authoring key endpoint.
    # For example, "https://your-resource-name.cognitiveservices.azure.cn/"
    authoring_endpoint = "https://YOUR-AUTHORING-ENDPOINT/"

    # The version number of your LUIS app
    app_version = "0.1"
    ##########

    # The headers to use in this REST call.
    headers = {'Ocp-Apim-Subscription-Key': authoring_key}

    # The URL parameters to use in this REST call.
    params ={
        #'timezoneOffset': '0',
        #'verbose': 'true',
        #'show-all-intents': 'true',
        #'spellCheck': 'false',
        #'staging': 'false'
    }

    # List of example utterances to send to the LUIS app.
    data = """[
    {
        'text': 'order a pizza',
        'intentName': 'ModifyOrder',
        'entityLabels': [
            {
                'entityName': 'Order',
                'startCharIndex': 6,
                'endCharIndex': 12
            }
        ]
    },
    {
        'text': 'order a large pepperoni pizza',
        'intentName': 'ModifyOrder',
        'entityLabels': [
            {
                'entityName': 'Order',
                'startCharIndex': 6,
                'endCharIndex': 28
            },
            {
                'entityName': 'FullPizzaWithModifiers',
                'startCharIndex': 6,
                'endCharIndex': 28
            },
            {
                'entityName': 'PizzaType',
                'startCharIndex': 14,
                'endCharIndex': 28
            },
            {
                'entityName': 'Size',
                'startCharIndex': 8,
                'endCharIndex': 12
            }
        ]
    },
    {
        'text': 'I want two large pepperoni pizzas on thin crust',
        'intentName': 'ModifyOrder',
        'entityLabels': [
            {
                'entityName': 'Order',
                'startCharIndex': 7,
                'endCharIndex': 46
            },
            {
                'entityName': 'FullPizzaWithModifiers',
                'startCharIndex': 7,
                'endCharIndex': 46
            },
            {
                'entityName': 'PizzaType',
                'startCharIndex': 17,
                'endCharIndex': 32
            },
            {
                'entityName': 'Size',
                'startCharIndex': 11,
                'endCharIndex': 15
            },
            {
                'entityName': 'Quantity',
                'startCharIndex': 7,
                'endCharIndex': 9
            },
            {
                'entityName': 'Crust',
                'startCharIndex': 37,
                'endCharIndex': 46
            }
        ]
    }
]
"""


    # Make the REST call to POST the list of example utterances.
    response = requests.post(f'{authoring_endpoint}luis/authoring/v3.0-preview/apps/{appId}/versions/{app_version}/examples',
        headers=headers, params=params, data=data)

    # Display the results on the console.
    print('Add the list of utterances:')
    print(response.json())


    # Make the REST call to initiate a training session.
    response = requests.post(f'{authoring_endpoint}luis/authoring/v3.0-preview/apps/{appId}/versions/{app_version}/train',
        headers=headers, params=params, data=None)

    # Display the results on the console.
    print('Request training:')
    print(response.json())


    # Make the REST call to request the status of training.
    response = requests.get(f'{authoring_endpoint}luis/authoring/v3.0-preview/apps/{appId}/versions/{app_version}/train',
        headers=headers, params=params, data=None)

    # Display the results on the console.
    print('Request training status:')
    print(response.json())


except Exception as e:
    # Display the error string.
    print(f'{e}')
  1. 将以 YOUR- 开头的值替换为你自己的值。Replace the values starting with YOUR- with your own values.

    信息Information 目的Purpose
    YOUR-APP-ID LUIS 应用 ID。Your LUIS app ID.
    YOUR-AUTHORING-KEY 32 字符创作密钥。Your 32 character authoring key.
    YOUR-AUTHORING-ENDPOINT 创作 URL 终结点。Your authoring URL endpoint. 例如,https://replace-with-your-resource-name.api.cognitive.azure.cn/For example, https://replace-with-your-resource-name.api.cognitive.azure.cn/. 在创建资源时设置资源名称。You set your resource name when you created the resource.

    分配的密钥和资源可以在 LUIS 门户的“Azure 资源”页上的“管理”部分中看到。Assigned keys and resources are visible in the LUIS portal in the Manage section, on the Azure resources page. 应用 ID 可以在“应用程序设置”页的同一“管理”部分中找到。The app ID is available in the same Manage section, on the Application Settings page.

  2. 在创建该文件的同一目录中,在命令提示符下输入以下命令来运行文件:With a command prompt in the same directory as where you created the file, enter the following command to run the file:

    python model.py
    
  3. 查看创作响应:Review the authoring response:

    Add the list of utterances:
    [{'value': {'ExampleId': 1137150691, 'UtteranceText': 'order a pizza'}, 'hasError': False}, {'value': {'ExampleId': 1137150692, 'UtteranceText': 'order a large pepperoni pizza'}, 'hasError': False}, {'value': {'ExampleId': 1137150693, 'UtteranceText': 'i want two large pepperoni pizzas on thin crust'}, 'hasError': False}]
    Request training:
    {'statusId': 9, 'status': 'Queued'}
    Request training status:
    [{'modelId': 'edb46abf-0000-41ab-beb2-a41a0fe1630f', 'details': {'statusId': 3, 'status': 'InProgress', 'exampleCount': 0, 'progressSubstatus': 'CollectingData'}}, {'modelId': 'a5030be2-616c-4648-bf2f-380fa9417d37', 'details': {'statusId': 3, 'status': 'InProgress', 'exampleCount': 0, 'progressSubstatus': 'CollectingData'}}, {'modelId': '3f2b1f31-a3c3-4fbd-8182-e9d9dbc120b9', 'details': {'statusId': 3, 'status': 'InProgress', 'exampleCount': 0, 'progressSubstatus': 'CollectingData'}}, {'modelId': 'e4b6704b-1636-474c-9459-fe9ccbeba51c', 'details': {'statusId': 3, 'status': 'InProgress', 'exampleCount': 0, 'progressSubstatus': 'CollectingData'}}, {'modelId': '031d3777-2a00-4a7a-9323-9a3280a30000', 'details': {'statusId': 3, 'status': 'InProgress', 'exampleCount': 0, 'progressSubstatus': 'CollectingData'}}, {'modelId': '9250e7a1-06eb-4413-9432-ae132ed32583', 'details': {'statusId': 3, 'status': 'InProgress', 'exampleCount': 0, 'progressSubstatus': 'CollectingData'}}]
    

    下面是为提高可读性而进行了格式设置的输出:Here is the output formatted for readability:

    Add the list of utterances:
    [
      {
        'value': {
          'ExampleId': 1137150691,
          'UtteranceText': 'order a pizza'
        },
        'hasError': False
      },
      {
        'value': {
          'ExampleId': 1137150692,
          'UtteranceText': 'order a large pepperoni pizza'
        },
        'hasError': False
      },
      {
        'value': {
          'ExampleId': 1137150693,
          'UtteranceText': 'i want two large pepperoni pizzas on thin crust'
        },
        'hasError': False
      }
    ]
    
    Request training:
    {
      'statusId': 9,
      'status': 'Queued'
    }
    
    Request training status:
    [
      {
        'modelId': 'edb46abf-0000-41ab-beb2-a41a0fe1630f',
        'details': {
          'statusId': 3,
          'status': 'InProgress',
          'exampleCount': 0,
          'progressSubstatus': 'CollectingData'
        }
      },
      {
        'modelId': 'a5030be2-616c-4648-bf2f-380fa9417d37',
        'details': {
          'statusId': 3,
          'status': 'InProgress',
          'exampleCount': 0,
          'progressSubstatus': 'CollectingData'
        }
      },
      {
        'modelId': '3f2b1f31-a3c3-4fbd-8182-e9d9dbc120b9',
        'details': {
          'statusId': 3,
          'status': 'InProgress',
          'exampleCount': 0,
          'progressSubstatus': 'CollectingData'
        }
      },
      {
        'modelId': 'e4b6704b-1636-474c-9459-fe9ccbeba51c',
        'details': {
          'statusId': 3,
          'status': 'InProgress',
          'exampleCount': 0,
          'progressSubstatus': 'CollectingData'
        }
      },
      {
        'modelId': '031d3777-2a00-4a7a-9323-9a3280a30000',
        'details': {
          'statusId': 3,
          'status': 'InProgress',
          'exampleCount': 0,
          'progressSubstatus': 'CollectingData'
        }
      },
      {
        'modelId': '9250e7a1-06eb-4413-9432-ae132ed32583',
        'details': {
          'statusId': 3,
          'status': 'InProgress',
          'exampleCount': 0,
          'progressSubstatus': 'CollectingData'
        }
      }
    ]
    

清理资源Clean up resources

完成本快速入门后,请从文件系统中删除该文件。When you are finished with this quickstart, delete the file from the file system.

后续步骤Next steps