Een intentie bepalen met behulp van de REST API's

In dit artikel gebruikt u een LUIS-app om de intentie van een gebruiker te bepalen aan de hand van beschrijvende tekst. Verzend de intentie van de gebruiker als tekst naar het HTTP-voorspellingseindpunt van de Pizza-app. Bij het eindpunt wordt via LUIS het model van de Pizza-app toegepast om de betekenis van tekst in natuurlijke taal te analyseren. Hiermee wordt de algehele intentie bepaald en worden gegevens geëxtraheerd die relevant zijn voor het onderwerpdomein van de app.

Voor dit artikel hebt u een gratis LUIS-account nodig.

Referentiedocumentatie | Voorbeeld

Vereisten

Pizza-app maken

  1. Selecteer pizza-app-for-luis-v6.json om de GitHub-pagina voor het pizza-app-for-luis.json-bestand te openen.
  2. Klik met de rechtermuisknop of tik lang op de knop Onbewerkt en selecteer Koppeling opslaan als om de pizza-app-for-luis.json op uw computer op te slaan.
  3. Meld u aan bij de LUIS-portal.
  4. Selecteer Mijn apps.
  5. Selecteer op de pagina Mijn apps de optie + Nieuwe app voor conversatie.
  6. Selecteer Importeren als JSON.
  7. Selecteer in het dialoogvenster Nieuwe app importeren de knop Bestand kiezen.
  8. Selecteer het pizza-app-for-luis.json-bestand dat u hebt gedownload en selecteer Openen.
  9. Voer in het veld Naam in het dialoogvenster Nieuwe app importeren een naam in voor uw Pizza-app en selecteer vervolgens de knop Gereed.

De app wordt geïmporteerd.

Sluit het dialoogvenster Een effectieve LUIS-app maken zodra dit wordt weergegeven.

De Pizza-app trainen en publiceren

Als het goed is, wordt de pagina Intenties weergegeven, met een lijst van de intenties in de Pizza-app.

  1. Selecteer rechts bovenaan op de LUIS-website de knop Train.

    De knop Train

  2. De training is voltooid wanneer de statusindicator op de Train groen is.

Om een voorspelling van LUIS te ontvangen in een chatbot of een andere clienttoepassing, moet u de app publiceren naar het voorspellingseindpunt.

  1. Selecteer Publiceren in de navigatiebalk rechtsboven.

    Schermopname van knop om vanuit LUIS te publiceren naar eindpunt in menu rechtsboven

  2. Selecteer de Productiesite en selecteer vervolgens Gereed.

    Schermopname van publiceren naar eindpunt vanuit LUIS

  3. Selecteer Uw eindpunt-URL's openen in de melding om naar de pagina Azure-resources te gaan. U kunt de URL's alleen zien als u een voorspellingsresource hebt die aan de app is gekoppeld. U vindt de pagina Azure-resources ook door op Beheren te klikken.

    Een bericht dat de app is gepubliceerd

Uw Pizza-app is nu klaar voor gebruik.

De app-id, de voorspellingssleutel en het voorspellingseindpunt van uw Pizza-app vastleggen

Als u uw nieuwe Pizza-app wilt gebruiken, hebt u de app-id, een voorspellingssleutel en een voorspellingseindpunt van uw Pizza-app nodig.

Deze waarden zoeken:

  1. Selecteer op de pagina Intenties de optie BEHEREN.
  2. Noteer de app-id op de pagina Toepassingsinstellingen.
  3. Selecteer Azure-resources.
  4. Noteer de primaire sleutel op de pagina Azure-resources. Deze waarde is uw voorspellingssleutel.
  5. Noteer de eindpunt-URL. Deze waarde is uw voorspellingseindpunt.

De intentie programmatisch ophalen

Gebruik C# (.NET Core) om een query uit te voeren op het voorspellingseindpunt en een voorspellingsresultaat op te halen.

  1. Maak een nieuwe consoletoepassing die op de C#-taal is gericht, met een project- en mapnaam van csharp-predict-with-rest.

    dotnet new console -lang C# -n csharp-predict-with-rest
    
  2. Ga naar de csharp-predict-with-rest-map die u hebt gemaakt en installeer de vereiste afhankelijkheid met deze opdracht:

    cd csharp-predict-with-rest
    dotnet add package System.Net.Http
    
  3. Open Program.cs in uw favoriete IDE of editor. Overschrijf Program.cs met de volgende code:

    //
    // This quickstart shows how to predict the intent of an utterance by using the LUIS REST APIs.
    //
    
    using System;
    using System.Net.Http;
    using System.Web;
    
    namespace predict_with_rest
    {
        class Program
        {
            static void Main(string[] args)
            {
                //////////
                // Values to modify.
    
                // YOUR-APP-ID: The App ID GUID found on the www.luis.ai Application Settings page.
                var appId = "PASTE_YOUR_LUIS_APP_ID_HERE";
    
                // YOUR-PREDICTION-KEY: 32 character key.
                var predictionKey = "PASTE_YOUR_LUIS_PREDICTION_SUBSCRIPTION_KEY_HERE";
    
                // YOUR-PREDICTION-ENDPOINT: Example is "https://westus.api.cognitive.microsoft.com/"
                var predictionEndpoint = "PASTE_YOUR_LUIS_PREDICTION_ENDPOINT_HERE";
    
                // An utterance to test the pizza app.
                var utterance = "I want two large pepperoni pizzas on thin crust please";
                //////////
    
                MakeRequest(predictionKey, predictionEndpoint, appId, utterance);
    
                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();
            }
    
            static async void MakeRequest(string predictionKey, string predictionEndpoint, string appId, string utterance)
            {
                var client = new HttpClient();
                var queryString = HttpUtility.ParseQueryString(string.Empty);
    
                // The request header contains your subscription key
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", predictionKey);
    
                // The "q" parameter contains the utterance to send to LUIS
                queryString["query"] = utterance;
    
                // These optional request parameters are set to their default values
                // queryString["verbose"] = "true";
                // queryString["show-all-intents"] = "true";
                // queryString["staging"] = "false";
                // queryString["timezoneOffset"] = "0";
    
                var predictionEndpointUri = String.Format("{0}luis/prediction/v3.0/apps/{1}/slots/production/predict?{2}", predictionEndpoint, appId, queryString);
    
                // Remove these before updating the article.
                Console.WriteLine("endpoint: " + predictionEndpoint);
                Console.WriteLine("appId: " + appId);
                Console.WriteLine("queryString: " + queryString);
                Console.WriteLine("endpointUri: " + predictionEndpointUri);
    
                var response = await client.GetAsync(predictionEndpointUri);
    
                var strResponseContent = await response.Content.ReadAsStringAsync();
    
                // Display the JSON result from LUIS.
                Console.WriteLine(strResponseContent.ToString());
            }
        }
    }
    
  4. Vervang de waarden die beginnen met YOUR- door uw eigen waarden.

    Informatie Doel
    YOUR-APP-ID Uw app-ID. De pagina met toepassingsinstellingen voor uw app in het LUIS-portal.
    YOUR-PREDICTION-KEY Uw voorspellingssleutel van 32 tekens. De Azure Resources-pagina voor uw app in het LUIS-portal.
    YOUR-PREDICTION-ENDPOINT Het eindpunt voor de voorspellings-URL. De Azure Resources-pagina voor uw app in het LUIS-portal.
    Bijvoorbeeld https://westus.api.cognitive.microsoft.com/.
  5. Bouw de consoletoepassing met deze opdracht:

    dotnet build
    
  6. Voer de consoletoepassing uit. De console-uitvoer bestaat uit de JSON die u eerder hebt gezien in het browservenster.

    dotnet run
    
  7. Controleer het voorspellingsantwoord dat geretourneerd wordt als JSON:

    {"query":"I want two large pepperoni pizzas on thin crust please","prediction":{"topIntent":"ModifyOrder","intents":{"ModifyOrder":{"score":1.0},"None":{"score":8.55E-09},"Greetings":{"score":1.82222226E-09},"CancelOrder":{"score":1.47272727E-09},"Confirmation":{"score":9.8125E-10}},"entities":{"Order":[{"FullPizzaWithModifiers":[{"PizzaType":["pepperoni pizzas"],"Size":[["Large"]],"Quantity":[2],"Crust":[["Thin"]],"$instance":{"PizzaType":[{"type":"PizzaType","text":"pepperoni pizzas","startIndex":17,"length":16,"score":0.9978157,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Size":[{"type":"SizeList","text":"large","startIndex":11,"length":5,"score":0.9984481,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Quantity":[{"type":"builtin.number","text":"two","startIndex":7,"length":3,"score":0.999770939,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Crust":[{"type":"CrustList","text":"thin crust","startIndex":37,"length":10,"score":0.933985531,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}]}}],"$instance":{"FullPizzaWithModifiers":[{"type":"FullPizzaWithModifiers","text":"two large pepperoni pizzas on thin crust","startIndex":7,"length":40,"score":0.90681237,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}]}}],"ToppingList":[["Pepperoni"]],"$instance":{"Order":[{"type":"Order","text":"two large pepperoni pizzas on thin crust","startIndex":7,"length":40,"score":0.9047088,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"ToppingList":[{"type":"ToppingList","text":"pepperoni","startIndex":17,"length":9,"modelTypeId":5,"modelType":"List Entity Extractor","recognitionSources":["model"]}]}}}}
    

    Het JSON-antwoord dat is opgemaakt voor leesbaarheid:

    {
      "query": "I want two large pepperoni pizzas on thin crust please",
      "prediction": {
        "topIntent": "ModifyOrder",
        "intents": {
          "ModifyOrder": {
            "score": 1
          },
          "None": {
            "score": 8.55e-9
          },
          "Greetings": {
            "score": 1.82222226e-9
          },
          "CancelOrder": {
            "score": 1.47272727e-9
          },
          "Confirmation": {
            "score": 9.8125e-10
          }
        },
        "entities": {
          "Order": [
            {
              "FullPizzaWithModifiers": [
                {
                  "PizzaType": [
                    "pepperoni pizzas"
                  ],
                  "Size": [
                    [
                      "Large"
                    ]
                  ],
                  "Quantity": [
                    2
                  ],
                  "Crust": [
                    [
                      "Thin"
                    ]
                  ],
                  "$instance": {
                    "PizzaType": [
                      {
                        "type": "PizzaType",
                        "text": "pepperoni pizzas",
                        "startIndex": 17,
                        "length": 16,
                        "score": 0.9978157,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Size": [
                      {
                        "type": "SizeList",
                        "text": "large",
                        "startIndex": 11,
                        "length": 5,
                        "score": 0.9984481,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Quantity": [
                      {
                        "type": "builtin.number",
                        "text": "two",
                        "startIndex": 7,
                        "length": 3,
                        "score": 0.999770939,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Crust": [
                      {
                        "type": "CrustList",
                        "text": "thin crust",
                        "startIndex": 37,
                        "length": 10,
                        "score": 0.933985531,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ]
                  }
                }
              ],
              "$instance": {
                "FullPizzaWithModifiers": [
                  {
                    "type": "FullPizzaWithModifiers",
                    "text": "two large pepperoni pizzas on thin crust",
                    "startIndex": 7,
                    "length": 40,
                    "score": 0.90681237,
                    "modelTypeId": 1,
                    "modelType": "Entity Extractor",
                    "recognitionSources": [
                      "model"
                    ]
                  }
                ]
              }
            }
          ],
          "ToppingList": [
            [
              "Pepperoni"
            ]
          ],
          "$instance": {
            "Order": [
              {
                "type": "Order",
                "text": "two large pepperoni pizzas on thin crust",
                "startIndex": 7,
                "length": 40,
                "score": 0.9047088,
                "modelTypeId": 1,
                "modelType": "Entity Extractor",
                "recognitionSources": [
                  "model"
                ]
              }
            ],
            "ToppingList": [
              {
                "type": "ToppingList",
                "text": "pepperoni",
                "startIndex": 17,
                "length": 9,
                "modelTypeId": 5,
                "modelType": "List Entity Extractor",
                "recognitionSources": [
                  "model"
                ]
              }
            ]
          }
        }
      }
    }
    

Resources opschonen

Wanneer u klaar bent met deze quickstart, verwijdert u de projectmap uit het bestandssysteem.

Volgende stappen

Referentiedocumentatie | Voorbeeld

Vereisten

Pizza-app maken

  1. Selecteer pizza-app-for-luis-v6.json om de GitHub-pagina voor het pizza-app-for-luis.json-bestand te openen.
  2. Klik met de rechtermuisknop of tik lang op de knop Onbewerkt en selecteer Koppeling opslaan als om de pizza-app-for-luis.json op uw computer op te slaan.
  3. Meld u aan bij de LUIS-portal.
  4. Selecteer Mijn apps.
  5. Selecteer op de pagina Mijn apps de optie + Nieuwe app voor conversatie.
  6. Selecteer Importeren als JSON.
  7. Selecteer in het dialoogvenster Nieuwe app importeren de knop Bestand kiezen.
  8. Selecteer het pizza-app-for-luis.json-bestand dat u hebt gedownload en selecteer Openen.
  9. Voer in het veld Naam in het dialoogvenster Nieuwe app importeren een naam in voor uw Pizza-app en selecteer vervolgens de knop Gereed.

De app wordt geïmporteerd.

Sluit het dialoogvenster Een effectieve LUIS-app maken zodra dit wordt weergegeven.

De Pizza-app trainen en publiceren

Als het goed is, wordt de pagina Intenties weergegeven, met een lijst van de intenties in de Pizza-app.

  1. Selecteer rechts bovenaan op de LUIS-website de knop Train.

    De knop Train

  2. De training is voltooid wanneer de statusindicator op de Train groen is.

Om een voorspelling van LUIS te ontvangen in een chatbot of een andere clienttoepassing, moet u de app publiceren naar het voorspellingseindpunt.

  1. Selecteer Publiceren in de navigatiebalk rechtsboven.

    Schermopname van knop om vanuit LUIS te publiceren naar eindpunt in menu rechtsboven

  2. Selecteer de Productiesite en selecteer vervolgens Gereed.

    Schermopname van publiceren naar eindpunt vanuit LUIS

  3. Selecteer Uw eindpunt-URL's openen in de melding om naar de pagina Azure-resources te gaan. U kunt de URL's alleen zien als u een voorspellingsresource hebt die aan de app is gekoppeld. U vindt de pagina Azure-resources ook door op Beheren te klikken.

    Een bericht dat de app is gepubliceerd

Uw Pizza-app is nu klaar voor gebruik.

De app-id, de voorspellingssleutel en het voorspellingseindpunt van uw Pizza-app vastleggen

Als u uw nieuwe Pizza-app wilt gebruiken, hebt u de app-id, een voorspellingssleutel en een voorspellingseindpunt van uw Pizza-app nodig.

Deze waarden zoeken:

  1. Selecteer op de pagina Intenties de optie BEHEREN.
  2. Noteer de app-id op de pagina Toepassingsinstellingen.
  3. Selecteer Azure-resources.
  4. Noteer de primaire sleutel op de pagina Azure-resources. Deze waarde is uw voorspellingssleutel.
  5. Noteer de eindpunt-URL. Deze waarde is uw voorspellingseindpunt.

De intentie programmatisch ophalen

Gebruik Go om een query uit te voeren op het voorspellingseindpunt en een voorspellingsresultaat op te halen.

  1. Maak een nieuw bestand met de naam predict.go. Voeg de volgende code toe:

    //
    // This quickstart shows how to predict the intent of an utterance by using the LUIS REST APIs.
    //
    
    package main
    
    // Import dependencies.
    import (
        "fmt"
        "net/http"
        "net/url"
        "io/ioutil"
        "log"
    )
    
    func main() {
    
        //////////
        // Values to modify.
    
        // YOUR-APP-ID: The App ID GUID found on the www.luis.ai Application Settings page.
        var appID = "PASTE_YOUR_LUIS_APP_ID_HERE"
    
        // YOUR-PREDICTION-KEY: Your LUIS authoring key, 32 character value.
        var predictionKey = "PASTE_YOUR_LUIS_PREDICTION_SUBSCRIPTION_KEY_HERE"
    
        // YOUR-PREDICTION-ENDPOINT: Replace with your authoring key endpoint.
        // For example, "https://westus.api.cognitive.microsoft.com/"
        var predictionEndpoint = "PASTE_YOUR_LUIS_PREDICTION_ENDPOINT_HERE"
    
        // utterance for public app
        var utterance = "I want two large pepperoni pizzas on thin crust please"
        //////////
    
        // Call the prediction endpoint.
        endpointPrediction(appID, predictionKey, predictionEndpoint, utterance)
    }
    
    // Calls the prediction endpoint and displays the prediction results on the console.
    func endpointPrediction(appID string, predictionKey string, predictionEndpoint string, utterance string) {
    
        var endpointUrl = fmt.Sprintf("%sluis/prediction/v3.0/apps/%s/slots/production/predict?subscription-key=%s&verbose=true&show-all-intents=true&query=%s", predictionEndpoint, appID, predictionKey, url.QueryEscape(utterance))
    
        response, err := http.Get(endpointUrl)
    
        if err != nil {
            // handle error
            fmt.Println("error from Get")
            log.Fatal(err)
        }
    
        response2, err2 := ioutil.ReadAll(response.Body)
    
        if err2 != nil {
            // handle error
            fmt.Println("error from ReadAll")
            log.Fatal(err2)
        }
    
        fmt.Println("response")
        fmt.Println(string(response2))
    }
    
  2. Vervang de waarden die beginnen met YOUR- door uw eigen waarden.

    Informatie Doel
    YOUR-APP-ID Uw app-ID. De pagina met toepassingsinstellingen voor uw app in het LUIS-portal.
    YOUR-PREDICTION-KEY Uw voorspellingssleutel van 32 tekens. De Azure Resources-pagina voor uw app in het LUIS-portal.
    YOUR-PREDICTION-ENDPOINT Het eindpunt voor de voorspellings-URL. De Azure Resources-pagina voor uw app in het LUIS-portal.
    Bijvoorbeeld https://westus.api.cognitive.microsoft.com/.
  3. Voer, in dezelfde map waarin u het bestand hebt gemaakt, met een opdrachtprompt de volgende opdracht uit om het Go-bestand te compileren:

    go build predict.go
    
  4. Voer de Go-toepassing uit vanaf de opdrachtregel door de volgende tekst in te voeren in de opdrachtprompt:

    go run predict.go
    
  5. Controleer het voorspellingsantwoord dat geretourneerd wordt als JSON:

    response
    {"query":"I want two large pepperoni pizzas on thin crust please","prediction":{"topIntent":"ModifyOrder","intents":{"ModifyOrder":{"score":1.0},"None":{"score":8.55E-09},"Greetings":{"score":1.82222226E-09},"CancelOrder":{"score":1.47272727E-09},"Confirmation":{"score":9.8125E-10}},"entities":{"Order":[{"FullPizzaWithModifiers":[{"PizzaType":["pepperoni pizzas"],"Size":[["Large"]],"Quantity":[2],"Crust":[["Thin"]],"$instance":{"PizzaType":[{"type":"PizzaType","text":"pepperoni pizzas","startIndex":17,"length":16,"score":0.9978157,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Size":[{"type":"SizeList","text":"large","startIndex":11,"length":5,"score":0.9984481,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Quantity":[{"type":"builtin.number","text":"two","startIndex":7,"length":3,"score":0.999770939,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Crust":[{"type":"CrustList","text":"thin crust","startIndex":37,"length":10,"score":0.933985531,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}]}}],"$instance":{"FullPizzaWithModifiers":[{"type":"FullPizzaWithModifiers","text":"two large pepperoni pizzas on thin crust","startIndex":7,"length":40,"score":0.90681237,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}]}}],"ToppingList":[["Pepperoni"]],"$instance":{"Order":[{"type":"Order","text":"two large pepperoni pizzas on thin crust","startIndex":7,"length":40,"score":0.9047088,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"ToppingList":[{"type":"ToppingList","text":"pepperoni","startIndex":17,"length":9,"modelTypeId":5,"modelType":"List Entity Extractor","recognitionSources":["model"]}]}}}}
    

    JSON-antwoord opgemaakt voor leesbaarheid:

    response
    {
      "query": "I want two large pepperoni pizzas on thin crust please",
      "prediction": {
        "topIntent": "ModifyOrder",
        "intents": {
          "ModifyOrder": {
            "score": 1
          },
          "None": {
            "score": 8.55e-9
          },
          "Greetings": {
            "score": 1.82222226e-9
          },
          "CancelOrder": {
            "score": 1.47272727e-9
          },
          "Confirmation": {
            "score": 9.8125e-10
          }
        },
        "entities": {
          "Order": [
            {
              "FullPizzaWithModifiers": [
                {
                  "PizzaType": [
                    "pepperoni pizzas"
                  ],
                  "Size": [
                    [
                      "Large"
                    ]
                  ],
                  "Quantity": [
                    2
                  ],
                  "Crust": [
                    [
                      "Thin"
                    ]
                  ],
                  "$instance": {
                    "PizzaType": [
                      {
                        "type": "PizzaType",
                        "text": "pepperoni pizzas",
                        "startIndex": 17,
                        "length": 16,
                        "score": 0.9978157,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Size": [
                      {
                        "type": "SizeList",
                        "text": "large",
                        "startIndex": 11,
                        "length": 5,
                        "score": 0.9984481,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Quantity": [
                      {
                        "type": "builtin.number",
                        "text": "two",
                        "startIndex": 7,
                        "length": 3,
                        "score": 0.999770939,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Crust": [
                      {
                        "type": "CrustList",
                        "text": "thin crust",
                        "startIndex": 37,
                        "length": 10,
                        "score": 0.933985531,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ]
                  }
                }
              ],
              "$instance": {
                "FullPizzaWithModifiers": [
                  {
                    "type": "FullPizzaWithModifiers",
                    "text": "two large pepperoni pizzas on thin crust",
                    "startIndex": 7,
                    "length": 40,
                    "score": 0.90681237,
                    "modelTypeId": 1,
                    "modelType": "Entity Extractor",
                    "recognitionSources": [
                      "model"
                    ]
                  }
                ]
              }
            }
          ],
          "ToppingList": [
            [
              "Pepperoni"
            ]
          ],
          "$instance": {
            "Order": [
              {
                "type": "Order",
                "text": "two large pepperoni pizzas on thin crust",
                "startIndex": 7,
                "length": 40,
                "score": 0.9047088,
                "modelTypeId": 1,
                "modelType": "Entity Extractor",
                "recognitionSources": [
                  "model"
                ]
              }
            ],
            "ToppingList": [
              {
                "type": "ToppingList",
                "text": "pepperoni",
                "startIndex": 17,
                "length": 9,
                "modelTypeId": 5,
                "modelType": "List Entity Extractor",
                "recognitionSources": [
                  "model"
                ]
              }
            ]
          }
        }
      }
    }
    

Resources opschonen

Wanneer u klaar bent met deze quickstart, verwijdert u het bestand uit het bestandssysteem.

Volgende stappen

Referentiedocumentatie | Voorbeeld

Vereisten

Pizza-app maken

  1. Selecteer pizza-app-for-luis-v6.json om de GitHub-pagina voor het pizza-app-for-luis.json-bestand te openen.
  2. Klik met de rechtermuisknop of tik lang op de knop Onbewerkt en selecteer Koppeling opslaan als om de pizza-app-for-luis.json op uw computer op te slaan.
  3. Meld u aan bij de LUIS-portal.
  4. Selecteer Mijn apps.
  5. Selecteer op de pagina Mijn apps de optie + Nieuwe app voor conversatie.
  6. Selecteer Importeren als JSON.
  7. Selecteer in het dialoogvenster Nieuwe app importeren de knop Bestand kiezen.
  8. Selecteer het pizza-app-for-luis.json-bestand dat u hebt gedownload en selecteer Openen.
  9. Voer in het veld Naam in het dialoogvenster Nieuwe app importeren een naam in voor uw Pizza-app en selecteer vervolgens de knop Gereed.

De app wordt geïmporteerd.

Sluit het dialoogvenster Een effectieve LUIS-app maken zodra dit wordt weergegeven.

De Pizza-app trainen en publiceren

Als het goed is, wordt de pagina Intenties weergegeven, met een lijst van de intenties in de Pizza-app.

  1. Selecteer rechts bovenaan op de LUIS-website de knop Train.

    De knop Train

  2. De training is voltooid wanneer de statusindicator op de Train groen is.

Om een voorspelling van LUIS te ontvangen in een chatbot of een andere clienttoepassing, moet u de app publiceren naar het voorspellingseindpunt.

  1. Selecteer Publiceren in de navigatiebalk rechtsboven.

    Schermopname van knop om vanuit LUIS te publiceren naar eindpunt in menu rechtsboven

  2. Selecteer de Productiesite en selecteer vervolgens Gereed.

    Schermopname van publiceren naar eindpunt vanuit LUIS

  3. Selecteer Uw eindpunt-URL's openen in de melding om naar de pagina Azure-resources te gaan. U kunt de URL's alleen zien als u een voorspellingsresource hebt die aan de app is gekoppeld. U vindt de pagina Azure-resources ook door op Beheren te klikken.

    Een bericht dat de app is gepubliceerd

Uw Pizza-app is nu klaar voor gebruik.

De app-id, de voorspellingssleutel en het voorspellingseindpunt van uw Pizza-app vastleggen

Als u uw nieuwe Pizza-app wilt gebruiken, hebt u de app-id, een voorspellingssleutel en een voorspellingseindpunt van uw Pizza-app nodig.

Deze waarden zoeken:

  1. Selecteer op de pagina Intenties de optie BEHEREN.
  2. Noteer de app-id op de pagina Toepassingsinstellingen.
  3. Selecteer Azure-resources.
  4. Noteer de primaire sleutel op de pagina Azure-resources. Deze waarde is uw voorspellingssleutel.
  5. Noteer de eindpunt-URL. Deze waarde is uw voorspellingseindpunt.

De intentie programmatisch ophalen

Gebruik Java om een query uit te voeren op het voorspellingseindpunt en een voorspellingsresultaat op te halen.

  1. Een nieuwe map maken voor uw Java-project, zoals java-predict-with-rest.

  2. Maak een submap met de naam lib en kopieer deze in de volgende Java-bibliotheken naar de lib-submap:

  3. Kopieer de volgende code om een klasse te maken in een bestand met de naam Predict.java:

    //
    // This quickstart shows how to predict the intent of an utterance by using the LUIS 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.utils.URIBuilder;
    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/*" Predict.java
    //      macOs: javac -cp ":lib/*" Predict.java
    //      Linux: javac -cp ":lib/*" Predict.java
    
    // To run, execute this command at the console:
    //      Windows: java -cp ";lib/*" Predict
    //      macOs: java -cp ":lib/*" Predict
    //      Linux: java -cp ":lib/*" Predict
    
    public class Predict {
    
        public static void main(String[] args)
        {
            HttpClient httpclient = HttpClients.createDefault();
    
            try
            {
                //////////
                // Values to modify.
    
                // YOUR-APP-ID: The App ID GUID found on the www.luis.ai Application Settings page.
                String AppId = "PASTE_YOUR_LUIS_APP_ID_HERE";
    
                // YOUR-PREDICTION-KEY: Your LUIS authoring key, 32 character value.
                String Key = "PASTE_YOUR_LUIS_PREDICTION_SUBSCRIPTION_KEY_HERE";
    
                // YOUR-PREDICTION-ENDPOINT: Replace this with your authoring key endpoint.
                // For example, "https://westus.api.cognitive.microsoft.com/"
                String Endpoint = "PASTE_YOUR_LUIS_PREDICTION_ENDPOINT_HERE";
    
                // The utterance you want to use.
                String Utterance = "I want two large pepperoni pizzas on thin crust please";
                //////////
    
                // Begin building the endpoint URL.
                URIBuilder endpointURLbuilder = new URIBuilder(Endpoint + "luis/prediction/v3.0/apps/" + AppId + "/slots/production/predict?");
    
                // Create the query string params.
                endpointURLbuilder.setParameter("query", Utterance);
                endpointURLbuilder.setParameter("subscription-key", Key);
                endpointURLbuilder.setParameter("show-all-intents", "true");
                endpointURLbuilder.setParameter("verbose", "true");
    
                // Create the prediction endpoint URL.
                URI endpointURL = endpointURLbuilder.build();
    
                // Create the HTTP object from the URL.
                HttpGet request = new HttpGet(endpointURL);
    
                // Access the LUIS endpoint to analyze the text utterance.
                HttpResponse response = httpclient.execute(request);
    
                // Get the response.
                HttpEntity entity = response.getEntity();
    
                // Print the response on the console.
                if (entity != null)
                {
                    System.out.println(EntityUtils.toString(entity));
                }
            }
    
            // Display errors if they occur.
            catch (Exception e)
            {
                System.out.println(e.getMessage());
            }
        }
    }
    
  4. Vervang de waarden die beginnen met YOUR- door uw eigen waarden.

    Informatie Doel
    YOUR-APP-ID Uw app-ID. De pagina met toepassingsinstellingen voor uw app in het LUIS-portal.
    YOUR-PREDICTION-KEY Uw voorspellingssleutel van 32 tekens. De Azure Resources-pagina voor uw app in het LUIS-portal.
    YOUR-PREDICTION-ENDPOINT Het eindpunt voor de voorspellings-URL. De Azure Resources-pagina voor uw app in het LUIS-portal.
    Bijvoorbeeld https://westus.api.cognitive.microsoft.com/.
  5. Compileer het java-programma vanaf de opdrachtregel.

    • Als u Windows gebruikt, gebruikt u deze opdracht: javac -cp ";lib/*" Predict.java
    • Als u macOS of Linux gebruikt, gebruikt u deze opdracht: javac -cp ":lib/*" Predict.java
  6. Voer het java-programma uit vanaf de opdrachtregel:

    • Als u Windows gebruikt, gebruikt u deze opdracht: java -cp ";lib/*" Predict
    • Als u macOS of Linux gebruikt, gebruikt u deze opdracht: java -cp ":lib/*" Predict
  7. Controleer het voorspellingsantwoord dat geretourneerd wordt als JSON:

    {"query":"I want two large pepperoni pizzas on thin crust please","prediction":{"topIntent":"ModifyOrder","intents":{"ModifyOrder":{"score":1.0},"None":{"score":8.55E-09},"Greetings":{"score":1.82222226E-09},"CancelOrder":{"score":1.47272727E-09},"Confirmation":{"score":9.8125E-10}},"entities":{"Order":[{"FullPizzaWithModifiers":[{"PizzaType":["pepperoni pizzas"],"Size":[["Large"]],"Quantity":[2],"Crust":[["Thin"]],"$instance":{"PizzaType":[{"type":"PizzaType","text":"pepperoni pizzas","startIndex":17,"length":16,"score":0.9978157,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Size":[{"type":"SizeList","text":"large","startIndex":11,"length":5,"score":0.9984481,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Quantity":[{"type":"builtin.number","text":"two","startIndex":7,"length":3,"score":0.999770939,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Crust":[{"type":"CrustList","text":"thin crust","startIndex":37,"length":10,"score":0.933985531,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}]}}],"$instance":{"FullPizzaWithModifiers":[{"type":"FullPizzaWithModifiers","text":"two large pepperoni pizzas on thin crust","startIndex":7,"length":40,"score":0.90681237,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}]}}],"ToppingList":[["Pepperoni"]],"$instance":{"Order":[{"type":"Order","text":"two large pepperoni pizzas on thin crust","startIndex":7,"length":40,"score":0.9047088,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"ToppingList":[{"type":"ToppingList","text":"pepperoni","startIndex":17,"length":9,"modelTypeId":5,"modelType":"List Entity Extractor","recognitionSources":["model"]}]}}}}
    

    Het JSON-antwoord dat is opgemaakt voor leesbaarheid:

    {
      "query": "I want two large pepperoni pizzas on thin crust please",
      "prediction": {
        "topIntent": "ModifyOrder",
        "intents": {
          "ModifyOrder": {
            "score": 1
          },
          "None": {
            "score": 8.55e-9
          },
          "Greetings": {
            "score": 1.82222226e-9
          },
          "CancelOrder": {
            "score": 1.47272727e-9
          },
          "Confirmation": {
            "score": 9.8125e-10
          }
        },
        "entities": {
          "Order": [
            {
              "FullPizzaWithModifiers": [
                {
                  "PizzaType": [
                    "pepperoni pizzas"
                  ],
                  "Size": [
                    [
                      "Large"
                    ]
                  ],
                  "Quantity": [
                    2
                  ],
                  "Crust": [
                    [
                      "Thin"
                    ]
                  ],
                  "$instance": {
                    "PizzaType": [
                      {
                        "type": "PizzaType",
                        "text": "pepperoni pizzas",
                        "startIndex": 17,
                        "length": 16,
                        "score": 0.9978157,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Size": [
                      {
                        "type": "SizeList",
                        "text": "large",
                        "startIndex": 11,
                        "length": 5,
                        "score": 0.9984481,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Quantity": [
                      {
                        "type": "builtin.number",
                        "text": "two",
                        "startIndex": 7,
                        "length": 3,
                        "score": 0.999770939,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Crust": [
                      {
                        "type": "CrustList",
                        "text": "thin crust",
                        "startIndex": 37,
                        "length": 10,
                        "score": 0.933985531,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ]
                  }
                }
              ],
              "$instance": {
                "FullPizzaWithModifiers": [
                  {
                    "type": "FullPizzaWithModifiers",
                    "text": "two large pepperoni pizzas on thin crust",
                    "startIndex": 7,
                    "length": 40,
                    "score": 0.90681237,
                    "modelTypeId": 1,
                    "modelType": "Entity Extractor",
                    "recognitionSources": [
                      "model"
                    ]
                  }
                ]
              }
            }
          ],
          "ToppingList": [
            [
              "Pepperoni"
            ]
          ],
          "$instance": {
            "Order": [
              {
                "type": "Order",
                "text": "two large pepperoni pizzas on thin crust",
                "startIndex": 7,
                "length": 40,
                "score": 0.9047088,
                "modelTypeId": 1,
                "modelType": "Entity Extractor",
                "recognitionSources": [
                  "model"
                ]
              }
            ],
            "ToppingList": [
              {
                "type": "ToppingList",
                "text": "pepperoni",
                "startIndex": 17,
                "length": 9,
                "modelTypeId": 5,
                "modelType": "List Entity Extractor",
                "recognitionSources": [
                  "model"
                ]
              }
            ]
          }
        }
      }
    }
    

Resources opschonen

Wanneer u klaar bent met deze quickstart, verwijdert u de projectmap uit het bestandssysteem.

Volgende stappen

Referentiedocumentatie | Voorbeeld

Vereisten

Pizza-app maken

  1. Selecteer pizza-app-for-luis-v6.json om de GitHub-pagina voor het pizza-app-for-luis.json-bestand te openen.
  2. Klik met de rechtermuisknop of tik lang op de knop Onbewerkt en selecteer Koppeling opslaan als om de pizza-app-for-luis.json op uw computer op te slaan.
  3. Meld u aan bij de LUIS-portal.
  4. Selecteer Mijn apps.
  5. Selecteer op de pagina Mijn apps de optie + Nieuwe app voor conversatie.
  6. Selecteer Importeren als JSON.
  7. Selecteer in het dialoogvenster Nieuwe app importeren de knop Bestand kiezen.
  8. Selecteer het pizza-app-for-luis.json-bestand dat u hebt gedownload en selecteer Openen.
  9. Voer in het veld Naam in het dialoogvenster Nieuwe app importeren een naam in voor uw Pizza-app en selecteer vervolgens de knop Gereed.

De app wordt geïmporteerd.

Sluit het dialoogvenster Een effectieve LUIS-app maken zodra dit wordt weergegeven.

De Pizza-app trainen en publiceren

Als het goed is, wordt de pagina Intenties weergegeven, met een lijst van de intenties in de Pizza-app.

  1. Selecteer rechts bovenaan op de LUIS-website de knop Train.

    De knop Train

  2. De training is voltooid wanneer de statusindicator op de Train groen is.

Om een voorspelling van LUIS te ontvangen in een chatbot of een andere clienttoepassing, moet u de app publiceren naar het voorspellingseindpunt.

  1. Selecteer Publiceren in de navigatiebalk rechtsboven.

    Schermopname van knop om vanuit LUIS te publiceren naar eindpunt in menu rechtsboven

  2. Selecteer de Productiesite en selecteer vervolgens Gereed.

    Schermopname van publiceren naar eindpunt vanuit LUIS

  3. Selecteer Uw eindpunt-URL's openen in de melding om naar de pagina Azure-resources te gaan. U kunt de URL's alleen zien als u een voorspellingsresource hebt die aan de app is gekoppeld. U vindt de pagina Azure-resources ook door op Beheren te klikken.

    Een bericht dat de app is gepubliceerd

Uw Pizza-app is nu klaar voor gebruik.

De app-id, de voorspellingssleutel en het voorspellingseindpunt van uw Pizza-app vastleggen

Als u uw nieuwe Pizza-app wilt gebruiken, hebt u de app-id, een voorspellingssleutel en een voorspellingseindpunt van uw Pizza-app nodig.

Deze waarden zoeken:

  1. Selecteer op de pagina Intenties de optie BEHEREN.
  2. Noteer de app-id op de pagina Toepassingsinstellingen.
  3. Selecteer Azure-resources.
  4. Noteer de primaire sleutel op de pagina Azure-resources. Deze waarde is uw voorspellingssleutel.
  5. Noteer de eindpunt-URL. Deze waarde is uw voorspellingseindpunt.

Het Node.js-project maken

  1. Maak een nieuwe map voor uw Node.js-project, zoals node-predict-with-rest.

  2. Open een nieuwe opdrachtprompt, navigeer naar de map die u hebt gemaakt en voer de volgende opdracht uit:

    npm init
    

    Druk op Enter bij elke prompt om de standaardinstellingen te accepteren.

  3. Installeer de afhankelijkheden door de volgende opdrachten in te voeren:

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

De intentie programmatisch ophalen

Gebruik Node.js om een query uit te voeren op het voorspellingseindpunt en een voorspellingsresultaat op te halen.

  1. Kopieer het volgende codefragment naar een bestand met de naam predict.js:

    //
    // This quickstart shows how to predict the intent of an utterance by using the LUIS REST APIs.
    //
    
    var requestPromise = require('request-promise');
    var queryString = require('querystring');
    
    // Analyze a string utterance.
    getPrediction = async () => {
    
        //////////
        // Values to modify.
    
        // YOUR-APP-ID: The App ID GUID found on the www.luis.ai Application Settings page.
        const LUIS_appId = "PASTE_YOUR_LUIS_APP_ID_HERE";
    
        // YOUR-PREDICTION-KEY: Your LUIS authoring key, 32 character value.
        const LUIS_predictionKey = "PASTE_YOUR_LUIS_PREDICTION_SUBSCRIPTION_KEY_HERE";
    
        // YOUR-PREDICTION-ENDPOINT: Replace this with your authoring key endpoint.
        // For example, "https://westus.api.cognitive.microsoft.com/"
        const LUIS_endpoint = "PASTE_YOUR_LUIS_PREDICTION_ENDPOINT_HERE";
    
        // The utterance you want to use.
        const utterance = "I want two large pepperoni pizzas on thin crust please";
        //////////
    
        // Create query string
        const queryParams = {
            "show-all-intents": true,
            "verbose":  true,
            "query": utterance,
            "subscription-key": LUIS_predictionKey
        }
    
        // Create the URI for the REST call.
        const URI = `${LUIS_endpoint}luis/prediction/v3.0/apps/${LUIS_appId}/slots/production/predict?${queryString.stringify(queryParams)}`
    
        // Send the REST call.
        const response = await requestPromise(URI);
    
        // Display the response from the REST call.
        console.log(response);
    }
    
    // Pass an utterance to the sample LUIS app
    getPrediction().then(()=>console.log("done")).catch((err)=>console.log(err));
    
  2. Vervang de waarden die beginnen met YOUR- door uw eigen waarden.

    Informatie Doel
    YOUR-APP-ID Uw app-ID. De pagina met toepassingsinstellingen voor uw app in het LUIS-portal.
    YOUR-PREDICTION-KEY Uw voorspellingssleutel van 32 tekens. De Azure Resources-pagina voor uw app in het LUIS-portal.
    YOUR-PREDICTION-ENDPOINT Het eindpunt voor de voorspellings-URL. De Azure Resources-pagina voor uw app in het LUIS-portal.
    Bijvoorbeeld https://westus.api.cognitive.microsoft.com/.
  3. Controleer het voorspellingsantwoord dat geretourneerd wordt als JSON:

    {"query":"I want two large pepperoni pizzas on thin crust please","prediction":{"topIntent":"ModifyOrder","intents":{"ModifyOrder":{"score":1.0},"None":{"score":8.55E-09},"Greetings":{"score":1.82222226E-09},"CancelOrder":{"score":1.47272727E-09},"Confirmation":{"score":9.8125E-10}},"entities":{"Order":[{"FullPizzaWithModifiers":[{"PizzaType":["pepperoni pizzas"],"Size":[["Large"]],"Quantity":[2],"Crust":[["Thin"]],"$instance":{"PizzaType":[{"type":"PizzaType","text":"pepperoni pizzas","startIndex":17,"length":16,"score":0.9978157,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Size":[{"type":"SizeList","text":"large","startIndex":11,"length":5,"score":0.9984481,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Quantity":[{"type":"builtin.number","text":"two","startIndex":7,"length":3,"score":0.999770939,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"Crust":[{"type":"CrustList","text":"thin crust","startIndex":37,"length":10,"score":0.933985531,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}]}}],"$instance":{"FullPizzaWithModifiers":[{"type":"FullPizzaWithModifiers","text":"two large pepperoni pizzas on thin crust","startIndex":7,"length":40,"score":0.90681237,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}]}}],"ToppingList":[["Pepperoni"]],"$instance":{"Order":[{"type":"Order","text":"two large pepperoni pizzas on thin crust","startIndex":7,"length":40,"score":0.9047088,"modelTypeId":1,"modelType":"Entity Extractor","recognitionSources":["model"]}],"ToppingList":[{"type":"ToppingList","text":"pepperoni","startIndex":17,"length":9,"modelTypeId":5,"modelType":"List Entity Extractor","recognitionSources":["model"]}]}}}}
        ```
    
    The JSON response formatted for readability:
    
    ```JSON
    {
      "query": "I want two large pepperoni pizzas on thin crust please",
      "prediction": {
        "topIntent": "ModifyOrder",
        "intents": {
          "ModifyOrder": {
            "score": 1
          },
          "None": {
            "score": 8.55e-9
          },
          "Greetings": {
            "score": 1.82222226e-9
          },
          "CancelOrder": {
            "score": 1.47272727e-9
          },
          "Confirmation": {
            "score": 9.8125e-10
          }
        },
        "entities": {
          "Order": [
            {
              "FullPizzaWithModifiers": [
                {
                  "PizzaType": [
                    "pepperoni pizzas"
                  ],
                  "Size": [
                    [
                      "Large"
                    ]
                  ],
                  "Quantity": [
                    2
                  ],
                  "Crust": [
                    [
                      "Thin"
                    ]
                  ],
                  "$instance": {
                    "PizzaType": [
                      {
                        "type": "PizzaType",
                        "text": "pepperoni pizzas",
                        "startIndex": 17,
                        "length": 16,
                        "score": 0.9978157,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Size": [
                      {
                        "type": "SizeList",
                        "text": "large",
                        "startIndex": 11,
                        "length": 5,
                        "score": 0.9984481,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Quantity": [
                      {
                        "type": "builtin.number",
                        "text": "two",
                        "startIndex": 7,
                        "length": 3,
                        "score": 0.999770939,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ],
                    "Crust": [
                      {
                        "type": "CrustList",
                        "text": "thin crust",
                        "startIndex": 37,
                        "length": 10,
                        "score": 0.933985531,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                          "model"
                        ]
                      }
                    ]
                  }
                }
              ],
              "$instance": {
                "FullPizzaWithModifiers": [
                  {
                    "type": "FullPizzaWithModifiers",
                    "text": "two large pepperoni pizzas on thin crust",
                    "startIndex": 7,
                    "length": 40,
                    "score": 0.90681237,
                    "modelTypeId": 1,
                    "modelType": "Entity Extractor",
                    "recognitionSources": [
                      "model"
                    ]
                  }
                ]
              }
            }
          ],
          "ToppingList": [
            [
              "Pepperoni"
            ]
          ],
          "$instance": {
            "Order": [
              {
                "type": "Order",
                "text": "two large pepperoni pizzas on thin crust",
                "startIndex": 7,
                "length": 40,
                "score": 0.9047088,
                "modelTypeId": 1,
                "modelType": "Entity Extractor",
                "recognitionSources": [
                  "model"
                ]
              }
            ],
            "ToppingList": [
              {
                "type": "ToppingList",
                "text": "pepperoni",
                "startIndex": 17,
                "length": 9,
                "modelTypeId": 5,
                "modelType": "List Entity Extractor",
                "recognitionSources": [
                  "model"
                ]
              }
            ]
          }
        }
      }
    }
    

Resources opschonen

Wanneer u klaar bent met deze quickstart, verwijdert u de projectmap uit het bestandssysteem.

Volgende stappen

Referentiedocumentatie | Voorbeeld

Vereisten

Pizza-app maken

  1. Selecteer pizza-app-for-luis-v6.json om de GitHub-pagina voor het pizza-app-for-luis.json-bestand te openen.
  2. Klik met de rechtermuisknop of tik lang op de knop Onbewerkt en selecteer Koppeling opslaan als om de pizza-app-for-luis.json op uw computer op te slaan.
  3. Meld u aan bij de LUIS-portal.
  4. Selecteer Mijn apps.
  5. Selecteer op de pagina Mijn apps de optie + Nieuwe app voor conversatie.
  6. Selecteer Importeren als JSON.
  7. Selecteer in het dialoogvenster Nieuwe app importeren de knop Bestand kiezen.
  8. Selecteer het pizza-app-for-luis.json-bestand dat u hebt gedownload en selecteer Openen.
  9. Voer in het veld Naam in het dialoogvenster Nieuwe app importeren een naam in voor uw Pizza-app en selecteer vervolgens de knop Gereed.

De app wordt geïmporteerd.

Sluit het dialoogvenster Een effectieve LUIS-app maken zodra dit wordt weergegeven.

De Pizza-app trainen en publiceren

Als het goed is, wordt de pagina Intenties weergegeven, met een lijst van de intenties in de Pizza-app.

  1. Selecteer rechts bovenaan op de LUIS-website de knop Train.

    De knop Train

  2. De training is voltooid wanneer de statusindicator op de Train groen is.

Om een voorspelling van LUIS te ontvangen in een chatbot of een andere clienttoepassing, moet u de app publiceren naar het voorspellingseindpunt.

  1. Selecteer Publiceren in de navigatiebalk rechtsboven.

    Schermopname van knop om vanuit LUIS te publiceren naar eindpunt in menu rechtsboven

  2. Selecteer de Productiesite en selecteer vervolgens Gereed.

    Schermopname van publiceren naar eindpunt vanuit LUIS

  3. Selecteer Uw eindpunt-URL's openen in de melding om naar de pagina Azure-resources te gaan. U kunt de URL's alleen zien als u een voorspellingsresource hebt die aan de app is gekoppeld. U vindt de pagina Azure-resources ook door op Beheren te klikken.

    Een bericht dat de app is gepubliceerd

Uw Pizza-app is nu klaar voor gebruik.

De app-id, de voorspellingssleutel en het voorspellingseindpunt van uw Pizza-app vastleggen

Als u uw nieuwe Pizza-app wilt gebruiken, hebt u de app-id, een voorspellingssleutel en een voorspellingseindpunt van uw Pizza-app nodig.

Deze waarden zoeken:

  1. Selecteer op de pagina Intenties de optie BEHEREN.
  2. Noteer de app-id op de pagina Toepassingsinstellingen.
  3. Selecteer Azure-resources.
  4. Noteer de primaire sleutel op de pagina Azure-resources. Deze waarde is uw voorspellingssleutel.
  5. Noteer de eindpunt-URL. Deze waarde is uw voorspellingseindpunt.

Intent ophalen vanaf het voorspellingseindpunt

Gebruik Python om een query uit te voeren op het voorspellingseindpunt en een voorspellingsresultaat op te halen.

  1. Kopieer dit codefragment naar een bestand met de naam predict.py:

    ########### Python 3.6 #############
    
    #
    # This quickstart shows how to predict the intent of an utterance by using the LUIS REST APIs.
    #
    
    import requests
    
    try:
    
        ##########
        # Values to modify.
    
        # YOUR-APP-ID: The App ID GUID found on the www.luis.ai Application Settings page.
        appId = 'PASTE_YOUR_LUIS_APP_ID_HERE'
    
        # YOUR-PREDICTION-KEY: Your LUIS prediction key, 32 character value.
        prediction_key = 'PASTE_YOUR_LUIS_PREDICTION_SUBSCRIPTION_KEY_HERE'
    
        # YOUR-PREDICTION-ENDPOINT: Replace with your prediction endpoint.
        # For example, "https://westus.api.cognitive.microsoft.com/"
        prediction_endpoint = 'PASTE_YOUR_LUIS_PREDICTION_ENDPOINT_HERE'
    
        # The utterance you want to use.
        utterance = 'I want two large pepperoni pizzas on thin crust please'
        ##########
    
        # The headers to use in this REST call.
        headers = {
        }
    
        # The URL parameters to use in this REST call.
        params ={
            'query': utterance,
            'timezoneOffset': '0',
            'verbose': 'true',
            'show-all-intents': 'true',
            'spellCheck': 'false',
            'staging': 'false',
            'subscription-key': prediction_key
        }
    
    
        # Make the REST call.
        response = requests.get(f'{prediction_endpoint}luis/prediction/v3.0/apps/{appId}/slots/production/predict', headers=headers, params=params)
    
        # Display the results on the console.
        print(response.json())
    
    
    except Exception as e:
        # Display the error string.
        print(f'{e}')
    
  2. Vervang de waarden die beginnen met YOUR- door uw eigen waarden.

    Informatie Doel
    YOUR-APP-ID Uw app-ID. De pagina met toepassingsinstellingen voor uw app in het LUIS-portal.
    YOUR-PREDICTION-KEY Uw voorspellingssleutel van 32 tekens. De Azure Resources-pagina voor uw app in het LUIS-portal.
    YOUR-PREDICTION-ENDPOINT Het eindpunt voor de voorspellings-URL. De Azure Resources-pagina voor uw app in het LUIS-portal.
    Bijvoorbeeld https://westus.api.cognitive.microsoft.com/.
  3. Installeer de requests-afhankelijkheid. De requests-bibliotheek wordt gebruikt om HTTP-aanvragen te doen:

    pip install requests
    
  4. Voer het script uit met deze console-opdracht:

    python predict.py
    
  5. Controleer het voorspellingsantwoord dat geretourneerd wordt als JSON:

    {'query': 'I want two large pepperoni pizzas on thin crust please', 'prediction': {'topIntent': 'ModifyOrder', 'intents': {'ModifyOrder': {'score': 1.0}, 'None': {'score': 8.55e-09}, 'Greetings': {'score': 1.82222226e-09}, 'CancelOrder': {'score': 1.47272727e-09}, 'Confirmation': {'score': 9.8125e-10}}, 'entities': {'Order': [{'FullPizzaWithModifiers': [{'PizzaType': ['pepperoni pizzas'], 'Size': [['Large']], 'Quantity': [2], 'Crust': [['Thin']], '$instance': {'PizzaType': [{'type': 'PizzaType', 'text': 'pepperoni pizzas', 'startIndex': 17, 'length': 16, 'score': 0.9978157, 'modelTypeId': 1, 'modelType': 'Entity Extractor', 'recognitionSources': ['model']}], 'Size': [{'type': 'SizeList', 'text': 'large', 'startIndex': 11, 'length': 5, 'score': 0.9984481, 'modelTypeId': 1, 'modelType': 'Entity Extractor', 'recognitionSources': ['model']}], 'Quantity': [{'type': 'builtin.number', 'text': 'two', 'startIndex': 7, 'length': 3, 'score': 0.999770939, 'modelTypeId': 1, 'modelType': 'Entity Extractor', 'recognitionSources': ['model']}], 'Crust': [{'type': 'CrustList', 'text': 'thin crust', 'startIndex': 37, 'length': 10, 'score': 0.933985531, 'modelTypeId': 1, 'modelType': 'Entity Extractor', 'recognitionSources': ['model']}]}}], '$instance': {'FullPizzaWithModifiers': [{'type': 'FullPizzaWithModifiers', 'text': 'two large pepperoni pizzas on thin crust', 'startIndex': 7, 'length': 40, 'score': 0.90681237, 'modelTypeId': 1, 'modelType': 'Entity Extractor', 'recognitionSources': ['model']}]}}], 'ToppingList': [['Pepperoni']], '$instance': {'Order': [{'type': 'Order', 'text': 'two large pepperoni pizzas on thin crust', 'startIndex': 7, 'length': 40, 'score': 0.9047088, 'modelTypeId': 1, 'modelType': 'Entity Extractor', 'recognitionSources': ['model']}], 'ToppingList': [{'type': 'ToppingList', 'text': 'pepperoni', 'startIndex': 17, 'length': 9, 'modelTypeId': 5, 'modelType': 'List Entity Extractor', 'recognitionSources': ['model']}]}}}}
    

    JSON-antwoord opgemaakt voor leesbaarheid:

    {
      'query': 'I want two large pepperoni pizzas on thin crust please',
      'prediction': {
        'topIntent': 'ModifyOrder',
        'intents': {
          'ModifyOrder': {
            'score': 1.0
          },
          'None': {
            'score': 8.55e-9
          },
          'Greetings': {
            'score': 1.82222226e-9
          },
          'CancelOrder': {
            'score': 1.47272727e-9
          },
          'Confirmation': {
            'score': 9.8125e-10
          }
        },
        'entities': {
          'Order': [
            {
              'FullPizzaWithModifiers': [
                {
                  'PizzaType': [
                    'pepperoni pizzas'
                  ],
                  'Size': [
                    [
                      'Large'
                    ]
                  ],
                  'Quantity': [
                    2
                  ],
                  'Crust': [
                    [
                      'Thin'
                    ]
                  ],
                  '$instance': {
                    'PizzaType': [
                      {
                        'type': 'PizzaType',
                        'text': 'pepperoni pizzas',
                        'startIndex': 17,
                        'length': 16,
                        'score': 0.9978157,
                        'modelTypeId': 1,
                        'modelType': 'Entity Extractor',
                        'recognitionSources': [
                          'model'
                        ]
                      }
                    ],
                    'Size': [
                      {
                        'type': 'SizeList',
                        'text': 'large',
                        'startIndex': 11,
                        'length': 5,
                        'score': 0.9984481,
                        'modelTypeId': 1,
                        'modelType': 'Entity Extractor',
                        'recognitionSources': [
                          'model'
                        ]
                      }
                    ],
                    'Quantity': [
                      {
                        'type': 'builtin.number',
                        'text': 'two',
                        'startIndex': 7,
                        'length': 3,
                        'score': 0.999770939,
                        'modelTypeId': 1,
                        'modelType': 'Entity Extractor',
                        'recognitionSources': [
                          'model'
                        ]
                      }
                    ],
                    'Crust': [
                      {
                        'type': 'CrustList',
                        'text': 'thin crust',
                        'startIndex': 37,
                        'length': 10,
                        'score': 0.933985531,
                        'modelTypeId': 1,
                        'modelType': 'Entity Extractor',
                        'recognitionSources': [
                          'model'
                        ]
                      }
                    ]
                  }
                }
              ],
              '$instance': {
                'FullPizzaWithModifiers': [
                  {
                    'type': 'FullPizzaWithModifiers',
                    'text': 'two large pepperoni pizzas on thin crust',
                    'startIndex': 7,
                    'length': 40,
                    'score': 0.90681237,
                    'modelTypeId': 1,
                    'modelType': 'Entity Extractor',
                    'recognitionSources': [
                      'model'
                    ]
                  }
                ]
              }
            }
          ],
          'ToppingList': [
            [
              'Pepperoni'
            ]
          ],
          '$instance': {
            'Order': [
              {
                'type': 'Order',
                'text': 'two large pepperoni pizzas on thin crust',
                'startIndex': 7,
                'length': 40,
                'score': 0.9047088,
                'modelTypeId': 1,
                'modelType': 'Entity Extractor',
                'recognitionSources': [
                  'model'
                ]
              }
            ],
            'ToppingList': [
              {
                'type': 'ToppingList',
                'text': 'pepperoni',
                'startIndex': 17,
                'length': 9,
                'modelTypeId': 5,
                'modelType': 'List Entity Extractor',
                'recognitionSources': [
                  'model'
                ]
              }
            ]
          }
        }
      }
    }
    

Resources opschonen

Wanneer u klaar bent met deze quickstart, verwijdert u het bestand uit het bestandssysteem.

Volgende stappen