|
1 | 1 | ---
|
2 |
| -title: Quickstart learning how to call a Language Understanding (LUIS) app using Go | Microsoft Docs |
3 |
| -description: In this quickstart, you learn to call a LUIS app using Go. |
| 2 | +title: Analyze natural language text in Language Understanding (LUIS) using GO - Azure Cognitive Services | Microsoft Docs |
| 3 | +description: In this quickstart, use an available public LUIS app to determine a user's intention from conversational text. Using GO, send the user's intention as text to the public app's HTTP prediction endpoint. At the endpoint, LUIS applies the public app's model to analyze the natural language text for meaning, determining overall intent and extracting data relevant to the app's subject domain. |
4 | 4 | services: cognitive-services
|
5 | 5 | author: diberry
|
6 | 6 | manager: cjgronlund
|
7 | 7 | ms.service: cognitive-services
|
8 | 8 | ms.component: language-understanding
|
9 | 9 | ms.topic: quickstart
|
10 |
| -ms.date: 06/27/2018 |
| 10 | +ms.date: 08/23/2018 |
11 | 11 | ms.author: diberry
|
12 |
| -#Customer intent: As a developer new to LUIS, I want to query the endpoint of a published model using Go. |
| 12 | +#Customer intent: As an API or REST developer new to the LUIS service, I want to query the LUIS endpoint of a published model using GO so that I can see the JSON prediction response. |
13 | 13 | ---
|
14 | 14 |
|
15 | 15 | # Quickstart: Call a LUIS endpoint using Go
|
16 |
| -In this quickstart, pass utterances to a LUIS endpoint and get intent and entities back. |
17 | 16 |
|
18 |
| -<!-- green checkmark --> |
19 |
| -<!-- |
20 |
| -> [!div class="checklist"] |
21 |
| -> * Create LUIS subscription and copy key value for later use |
22 |
| -> * View LUIS endpoint results from browser to public sample IoT app |
23 |
| -> * Create Visual Studio Go console app to make HTTPS call to LUIS endpoint |
24 |
| ---> |
25 |
| - |
26 |
| -<!-- link to free account --> |
27 |
| -For this article, you need a free [LUIS](luis-reference-regions.md#luis-website) account in order to author your LUIS application. |
| 17 | +[!include[Quickstart introduction for endpoint](../../../includes/cognitive-services-luis-qs-endpoint-intro-para.md)] |
28 | 18 |
|
29 | 19 | ## Prerequisites
|
30 | 20 |
|
31 |
| -* [Go](https://golang.org/) installed. |
32 |
| -* Your existing LUIS [**application ID**](./luis-get-started-create-app.md). The application ID is shown in the application dashboard. |
33 |
| - |
34 |
| -> [!NOTE] |
35 |
| -> The complete Go solution is available from the [**LUIS-Samples** Github repository](https://github.com/Microsoft/LUIS-Samples/blob/master/documentation-samples/endpoint-api-samples/go). |
36 |
| -
|
37 |
| -## Create LUIS endpoint key |
38 |
| - |
39 |
| -1. You first need to create a [Language Understanding API account](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account) in the Azure portal. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
40 |
| - |
41 |
| -2. Log in to the Azure portal at https://portal.azure.com. |
42 |
| - |
43 |
| -3. Follow the steps in [Creating Endpoint Keys using Azure](./luis-how-to-azure-subscription.md) to get a key. |
44 |
| - |
45 |
| -4. Go back to the [LUIS](luis-reference-regions.md) website. Log in using your Azure account. |
46 |
| - |
47 |
| - [](media/luis-get-started-cs-get-intent/app-list.png) |
| 21 | +* [Go](https://golang.org/) programming language |
| 22 | +* [Visual Studio Code](https://code.visualstudio.com/) |
| 23 | +* Public app ID: df67dcdb-c37d-46af-88e1-8b97951ca1c2 |
48 | 24 |
|
49 |
| -## Understand what LUIS returns |
| 25 | +[!include[Use authoring key for endpoint](../../../includes/cognitive-services-luis-qs-endpoint-luis-repo-note.md)] |
50 | 26 |
|
51 |
| -To understand what a LUIS app returns, you can paste the URL of a sample LUIS app into a browser window. The sample app is an [IoT app](https://azure.microsoft.com/services/cognitive-services/language-understanding-intelligent-service/) that detects whether the user wants to turn on or turn off lights. |
| 27 | +## Get LUIS key |
52 | 28 |
|
53 |
| -1. The endpoint of the sample app is in this format: `https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/df67dcdb-c37d-46af-88e1-8b97951ca1c2?subscription-key=<YOUR_API_KEY>&verbose=false&q=turn%20on%20the%20bedroom%20light` Copy the URL and substitute your endpoint key for the value of the `subscription-key` field. |
| 29 | +[!include[Use authoring key for endpoint](../../../includes/cognitive-services-luis-qs-endpoint-get-key-para.md)] |
54 | 30 |
|
55 |
| -2. Paste the URL into a browser window and press Enter. The browser displays a JSON result that indicates that LUIS detects the `HomeAutomation.TurnOn` intent and the `HomeAutomation.Room` entity with the value `bedroom`. |
| 31 | +## Analyze text with browser |
56 | 32 |
|
57 |
| -  |
| 33 | +[!include[Use authoring key for endpoint](../../../includes/cognitive-services-luis-qs-endpoint-browser-para.md)] |
58 | 34 |
|
59 |
| -3. Change the value of the `q=` parameter in the URL to `turn off the living room light`, and press Enter. The result now indicates that the LUIS detected the `HomeAutomation.TurnOff` intent and the `HomeAutomation.Room` entity with value `living room`. |
60 |
| - |
61 |
| -  |
62 |
| - |
63 |
| -## Consume a LUIS result using the Endpoint API with Go |
| 35 | +## Analyze text with Go |
64 | 36 |
|
65 | 37 | You can use Go to access the same results you saw in the browser window in the previous step.
|
66 | 38 |
|
67 | 39 | 1. Create a new file named `endpoint.go`. Add the following code:
|
68 | 40 |
|
69 |
| - [!code-go[Go code that calls a LUIS endpoint](~/samples-luis/documentation-samples/endpoint-api-samples/go/endpoint.go?range=29-81)] |
| 41 | + [!code-go[Go code that calls a LUIS endpoint](~/samples-luis/documentation-samples/quickstarts/analyze-text/go/endpoint.go?range=36-98)] |
70 | 42 |
|
71 | 43 | 2. With a command prompt in the same directory as where you created the file, enter `go build endpoint.go` to compile the Go file. The command prompt does not return any information for a successful build.
|
72 | 44 |
|
73 |
| -3. Run the Go application from the command line by entering the following in the command prompt: |
74 |
| - |
75 |
| -```CMD |
76 |
| -endpoint -appID df67dcdb-c37d-46af-88e1-8b97951ca1c2 -endpointKey <add-your-endpoint-key> -version 0.1 -region westus |
77 |
| -``` |
78 |
| - |
79 |
| -Replace `<add-your-endpoint-key>` with the value of your endpoint key. |
80 |
| - |
81 |
| -The command prompt response is: |
82 |
| - |
83 |
| -```CMD |
84 |
| -appID has value df67dcdb-c37d-46af-88e1-8b97951ca1c2 |
85 |
| -endpointKey has value xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
86 |
| -region has value westus |
87 |
| -utterance has value turn on the bedroom light |
88 |
| -response |
89 |
| -{ |
90 |
| - "query": "turn on the bedroom light", |
91 |
| - "topScoringIntent": { |
92 |
| - "intent": "HomeAutomation.TurnOn", |
93 |
| - "score": 0.809439957 |
94 |
| - }, |
95 |
| - "entities": [ |
96 |
| - { |
97 |
| - "entity": "bedroom", |
98 |
| - "type": "HomeAutomation.Room", |
99 |
| - "startIndex": 12, |
100 |
| - "endIndex": 18, |
101 |
| - "score": 0.8065475 |
102 |
| - } |
103 |
| - ] |
104 |
| -} |
105 |
| -``` |
| 45 | +3. Run the Go application from the command line by entering the following text in the command prompt: |
| 46 | + |
| 47 | + ```CMD |
| 48 | + go run endpoint.go -appID df67dcdb-c37d-46af-88e1-8b97951ca1c2 -endpointKey <add-your-key> -region westus |
| 49 | + ``` |
| 50 | + |
| 51 | + Replace `<add-your-key>` with the value of your key. |
| 52 | + |
| 53 | + The command prompt response is: |
| 54 | + |
| 55 | + ```CMD |
| 56 | + appID has value df67dcdb-c37d-46af-88e1-8b97951ca1c2 |
| 57 | + endpointKey has value xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 58 | + region has value westus |
| 59 | + utterance has value turn on the bedroom light |
| 60 | + response |
| 61 | + { |
| 62 | + "query": "turn on the bedroom light", |
| 63 | + "topScoringIntent": { |
| 64 | + "intent": "HomeAutomation.TurnOn", |
| 65 | + "score": 0.809439957 |
| 66 | + }, |
| 67 | + "entities": [ |
| 68 | + { |
| 69 | + "entity": "bedroom", |
| 70 | + "type": "HomeAutomation.Room", |
| 71 | + "startIndex": 12, |
| 72 | + "endIndex": 18, |
| 73 | + "score": 0.8065475 |
| 74 | + } |
| 75 | + ] |
| 76 | + } |
| 77 | + ``` |
| 78 | + |
| 79 | +## LUIS keys |
| 80 | +
|
| 81 | +[!include[Use authoring key for endpoint](../../../includes/cognitive-services-luis-qs-endpoint-key-usage-para.md)] |
106 | 82 |
|
107 | 83 | ## Clean up resources
|
108 |
| -The two resources created in this quickstart are the LUIS endpoint key and the Go project. Delete the LUIS endpoint key from the Azure portal. Close the Go file and remove it from the file system. |
| 84 | +Close the Go file and remove it from the file system. |
109 | 85 |
|
110 | 86 | ## Next steps
|
111 | 87 | > [!div class="nextstepaction"]
|
|
0 commit comments