快速入门:使用预构建的家庭自动化应用Quickstart: Use prebuilt Home automation app

在本快速入门中,请使用预生成的域 HomeAutomation 来创建 LUIS 应用,以便打开和关闭灯和设备。In this quickstart, create a LUIS app that uses the prebuilt domain HomeAutomation for turning lights and appliances on and off. 此预生成的域为你提供意向、实体和示例话语。This prebuilt domain provides intents, entities, and example utterances for you. 完成本教程后,你会有一个在云中运行的 LUIS 终结点。When you're finished, you'll have a LUIS endpoint running in the cloud.

登录到 LUIS 门户Sign in to LUIS portal

LUIS 的新用户需要执行此过程:A new user to LUIS needs to follow this procedure:

  1. 登录 LUIS 门户,选择你所在的国家/地区,然后同意使用条款。Sign in to the LUIS portal, select your country/region and agree to the terms of use. 如果看到“我的应用”,则 LUIS 资源已存在,你应该跳过此过程,开始创建应用。If you see My Apps instead, a LUIS resource already exists and you should skip ahead to create an app. 有两种注册方式:You will have two options signing up:

    • 使用 Azure 资源(推荐)- 可将 LUIS 帐户与新的或现有的 Azure 创作资源进行关联。Using an Azure resource (recommended) - allows you to link your LUIS account with a new or existing Azure Authoring resource. 这与已迁移注册的效果一样。This is equivalent to signing up already migrated. 稍后无需再执行迁移过程You won't need to go through the migration process later on.

    • 使用试用密钥。Using a trial key. 这使你能够使用无需设置的试用资源登录到 LUIS。This allows you to sign in to LUIS with a trial resource that you don't need to set up. 如果选择此方式,则最终需要迁移帐户并将应用程序与创作资源关联。If you choose this option, you will eventually be required to migrate your account and link your applications to an authoring resource.

  2. 在出现的“选择创作”窗口中,找到你的 Azure 订阅和 LUIS 创作资源。In the Choose an authoring window that appears, find your Azure subscription, and LUIS authoring resource. 如果没有资源,可新建一个。If you don't have a resource, you can create a new one.

    选择语言理解创作资源的类型。

    创建新的创作资源时,请提供以下信息:When you create a new authoring resource, provide the following information:

    • 租户名称 - 与 Azure 订阅关联的租户。Tenant name - the tenant your Azure subscription is associated with.
    • Azure 订阅名称 - 将对资源计费的订阅。Azure subscription name - the subscription that will be billed for the resource.
    • Azure 资源组名称 - 你选择或创建的自定义资源组名称。Azure resource group name - a custom resource group name you choose or create. 使用资源组可将 Azure 资源分组,以便进行访问和管理。Resource groups allow you to group Azure resources for access and management.
    • Azure 资源名称 - 你选择的自定义名称,用作创作和预测终结点查询的 URL 的一部分。Azure resource name - a custom name you choose, used as part of the URL for your authoring and prediction endpoint queries.
    • 定价层 - 定价层确定每秒和每月的最大事务数。Pricing tier - the pricing tier determines the maximum transaction per second and month.

选择订阅和创作资源Select subscription and authoring resource

当你选择特定订阅和创作资源时,你将看到与之关联的应用的列表。When you select a specific subscription and authoring resource, you will see a list of apps associated with it.

选择创作订阅和创作资源

创建新应用Create a new app

可在“我的应用”中创建和管理应用程序。You can create and manage your applications on My Apps.

创建应用程序Create an application

若要创建应用程序,请单击“+ 新建应用”。To create an application, click + New app.

在显示的窗口中,输入以下信息:In the window that appears, enter the following information:

名称Name 说明Description
ANameAName 应用的名称。A name for the your app. 例如“home automation”。For example "home automation".
环境Culture 应用能够理解和显示的语言。The language that your app understands and speaks.
说明Description 应用的说明。A description for your app.
预测资源Prediction resource 将接收查询的预测资源。The prediction resource that will receive queries.

选择“完成”。Select Done.

备注

创建应用程序后将无法更改区域性。The culture cannot be changed once the application is created.

添加预生成域Add prebuilt domain

  1. 在左侧导航栏中选择“预生成域”。In the left navigation, select Prebuilt domains.

  2. 搜索“HomeAutomation”。Search for HomeAutomation.

  3. 在 HomeAutomation 卡上选择“添加域”。Select Add domain on the HomeAutomation card.

    选择“预生成域”,然后搜索“HomeAutomation”。Select 'Prebuilt domains' then search for 'HomeAutomation'. 在 HomeAutomation 卡上选择“添加域”。Select 'Add domain' on the HomeAutomation card.

    成功添加域以后,预生成域框会显示“删除域”按钮。When the domain is successfully added, the prebuilt domain box displays a Remove domain button.

意向和实体Intents and entities

  1. 在左侧导航菜单中选择“意向”,以便查看 HomeAutomation 域意向。Select Intents in the left navigation menu to see the HomeAutomation domain intents. 它具有示例言语,例如 HomeAutomation.QueryStateHomeAutomation.SetDeviceIt has example utterances, such as HomeAutomation.QueryState and HomeAutomation.SetDevice.

    备注

    “无”是由所有 LUIS 应用提供的意向。None is an intent provided by all LUIS apps. 可以使用它来处理与应用提供的功能无法对应的话语。You use it to handle utterances that don't correspond to functionality your app provides.

  2. 选择 HomeAutomation.TurnOff 意向。Select the HomeAutomation.TurnOff intent. 此意向包含一系列使用实体标记的示例言语。The intent contains a list of example utterances that are labeled with entities.

    HomeAutomation.TurnOff 意向的屏幕截图Screenshot of HomeAutomation.TurnOff intent

  3. 如果你想要查看应用的实体,请选择“实体”。If you want to view the entities for the app, select Entities. 如果单击某个实体(例如 HomeAutomation.DeviceName),你将看到与之关联的值的列表。If you click on one of the entities, such as HomeAutomation.DeviceName you will see a list of values associated with it.

    图像替换文字

训练 LUIS 应用Train the LUIS 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.

测试应用Test your app

训练完应用以后,即可测试它。Once you've trained your app, you can test it.

  1. 在右上方导航中选择“测试”。Select Test from the top-right navigation.

  2. 在“交互式测试”窗格中键入 Turn off the lights 之类的测试言语,然后按 Enter。Type a test utterance like Turn off the lights into the interactive test pane, and press Enter. 例如,“关闭照明设备”。For example, Turn off the lights.

    在以下示例中,Turn off the lights 被正确标识为“HomeAutomation.TurnOff”的评分最高的意向。In this example, Turn off the lights is correctly identified as the top scoring intent of HomeAutomation.TurnOff.

    “测试”面板的屏幕截图,其中突出显示了话语

  3. 选择“检查”以查看有关预测的详细信息。Select Inspect to view more information about the prediction.

    包含检查信息的测试面板的屏幕截图Screenshot of Test panel with inspection information

  4. 关闭“测试”窗格。Close the test pane.

发布应用以获取终结点 URLPublish the app to get the endpoint URL

若要在聊天机器人或其他客户端应用程序中接收 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 corner of the window.

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

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

  3. 在通知中选择“访问终结点 URL”链接,转到“Azure 资源”页。 Select the Access your endpoint URLs link in the notification to go to the Azure Resources page. 终结点 URL 作为“示例查询”列出。The endpoint URLs are listed as the Example Query.

查询 V3 API 预测终结点Query the V3 API prediction endpoint

  1. 在 LUIS 门户中的“Azure 资源”页面(左菜单)上的“预测资源”选项卡的“管理”部分(右上菜单)中,复制页面底部的“示例查询” 。In the LUIS portal, in the Manage section (top-right menu), on the Azure Resources page (left menu), on the Prediction Resources tab, copy the Example Query at the bottom of the page. 该 URL 具有应用 ID、密钥和槽名称。The URL has your app ID, key, and slot name. V3 预测终结点 URL 的格式如下:https://YOUR-RESOURCE-NAME.api.cognitive.azure.cn/luis/prediction/v3.0/apps/APP-ID/slots/SLOT-NAME/predict?subscription-key=YOUR-PREDICTION-KEY&<optional-name-value-pairs>&query=YOUR_QUERY_HEREThe V3 prediction endpoint URL has the form of: https://YOUR-RESOURCE-NAME.api.cognitive.azure.cn/luis/prediction/v3.0/apps/APP-ID/slots/SLOT-NAME/predict?subscription-key=YOUR-PREDICTION-KEY&<optional-name-value-pairs>&query=YOUR_QUERY_HERE

    预测资源部分中的示例查询

    将 URL 粘贴到新的浏览器选项卡中。如果看不到该 URL,则表明你没有预测资源,需要创建一个。Paste the URL into a new browser tab. If you don't see the URL, you don't have a prediction resource and will need to create one.

  1. 对于查询字符串,在浏览器地址栏中确保以下名称和值栏在 URL 中。In the browser address bar, for the query string, make sure the following name and value bars are in the URL. 如果它们不在查询字符串中,请添加它们:If they are not in the query string, add them:

    名称/值对Name/value pair
    verbose=true
    show-all-intents=true
  2. 在浏览器地址栏中,转到 URL 末尾,对于查询,输入 turn off the living room light 值,然后按 Enter。In the browser address bar, go to the end of the URL and enter turn off the living room light for the query value, then press Enter.

    {
        "query": "turn off the living room light",
        "prediction": {
            "topIntent": "HomeAutomation.TurnOff",
            "intents": {
                "HomeAutomation.TurnOff": {
                    "score": 0.969448864
                },
                "HomeAutomation.QueryState": {
                    "score": 0.0122336326
                },
                "HomeAutomation.TurnUp": {
                    "score": 0.006547436
                },
                "HomeAutomation.TurnDown": {
                    "score": 0.0050634006
                },
                "HomeAutomation.SetDevice": {
                    "score": 0.004951761
                },
                "HomeAutomation.TurnOn": {
                    "score": 0.00312553928
                },
                "None": {
                    "score": 0.000552945654
                }
            },
            "entities": {
                "HomeAutomation.Location": [
                    "living room"
                ],
                "HomeAutomation.DeviceName": [
                    [
                        "living room light"
                    ]
                ],
                "HomeAutomation.DeviceType": [
                    [
                        "light"
                    ]
                ],
                "$instance": {
                    "HomeAutomation.Location": [
                        {
                            "type": "HomeAutomation.Location",
                            "text": "living room",
                            "startIndex": 13,
                            "length": 11,
                            "score": 0.902181149,
                            "modelTypeId": 1,
                            "modelType": "Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ],
                    "HomeAutomation.DeviceName": [
                        {
                            "type": "HomeAutomation.DeviceName",
                            "text": "living room light",
                            "startIndex": 13,
                            "length": 17,
                            "modelTypeId": 5,
                            "modelType": "List Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ],
                    "HomeAutomation.DeviceType": [
                        {
                            "type": "HomeAutomation.DeviceType",
                            "text": "light",
                            "startIndex": 25,
                            "length": 5,
                            "modelTypeId": 5,
                            "modelType": "List Entity Extractor",
                            "recognitionSources": [
                                "model"
                            ]
                        }
                    ]
                }
            }
        }
    }
    

    详细了解 V3 预测终结点Learn more about the V3 prediction endpoint.

清理资源Clean up resources

不再需要 LUIS 应用时,请将其删除。When no longer needed, delete the LUIS app. 为此,请在左上角的菜单中选择“我的应用”。To do so, select My apps from the top left menu. 在应用列表中选择应用名称右侧的省略号 (...),然后选择“删除”。Select the ellipsis (...) to the right of the app name in the app list, select Delete. 在弹出的“删除应用?”对话框中,选择“确定”。On the pop-up dialog Delete app?, select Ok.

后续步骤Next steps

可以从代码调用终结点:You can call the endpoint from code: