You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cognitive-services/QnAMaker/Quickstarts/create-new-kb-csharp.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ Build succeeded.
55
55
56
56
At the top of Program.cs, replace the single using statement with the following lines to add necessary dependencies to the project:
57
57
58
-
[!code-csharp[Add the required dependencies](~/samples-qnamaker-csharp/documentation-samples/quickstarts/create-knowledge-base/QnaQuickstartCreateKnowledgebase/Program.cs?range=1-11"Add the required dependencies")]
@@ -66,26 +66,26 @@ Set the following values in environment variables:
66
66
*`QNA_MAKER_SUBSCRIPTION_KEY` - The **key** is a 32 character string and is available in the Azure portal, on the QnA Maker resource, on the Quickstart page. This is not the same as the prediction endpoint key.
67
67
*`QNA_MAKER_ENDPOINT` - The **endpoint** is the URL for authoring, in the format of `https://YOUR-RESOURCE-NAME.cognitiveservices.azure.com`. This is not the same URL used to query the prediction endpoint.
68
68
69
-
[!code-csharp[Add the required constants](~/samples-qnamaker-csharp/documentation-samples/quickstarts/create-knowledge-base/QnaQuickstartCreateKnowledgebase/Program.cs?range=17-26"Add the required constants")]
After the constants, add the following KB definition:
74
74
75
-
[!code-csharp[Add the required constants](~/samples-qnamaker-csharp/documentation-samples/quickstarts/create-knowledge-base/QnaQuickstartCreateKnowledgebase/Program.cs?range=28-58"Add the knowledge base definition")]
Add the following code block inside the Program class:
79
79
80
-
[!code-csharp[Add supporting functions and structures](~/samples-qnamaker-csharp/documentation-samples/quickstarts/create-knowledge-base/QnaQuickstartCreateKnowledgebase/Program.cs?range=60-99"Add supporting functions and structures")]
The following code makes an HTTPS request to the QnA Maker API to create a KB and receives the response:
85
85
86
-
[!code-csharp[Add PostCreateKB to request via POST](~/samples-qnamaker-csharp/documentation-samples/quickstarts/create-knowledge-base/QnaQuickstartCreateKnowledgebase/Program.cs?range=145-165"Add PostCreateKB to request via POST")]
[!code-csharp[Add a POST request to create KB](~/samples-qnamaker-csharp/documentation-samples/quickstarts/create-knowledge-base/QnaQuickstartCreateKnowledgebase/Program.cs?range=101-122"Add a POST request to create KB")]
This API call returns a JSON response that includes the operation ID. Use the operation ID to determine if the KB is successfully created.
91
91
@@ -103,9 +103,9 @@ This API call returns a JSON response that includes the operation ID. Use the op
103
103
104
104
Check the status of the operation.
105
105
106
-
[!code-csharp[Add GetStatus to request via GET](~/samples-qnamaker-csharp/documentation-samples/quickstarts/create-knowledge-base/QnaQuickstartCreateKnowledgebase/Program.cs?range=167-187"Add GetStatus to request via GET")]
[!code-csharp[Add GET request to determine creation status](~/samples-qnamaker-csharp/documentation-samples/quickstarts/create-knowledge-base/QnaQuickstartCreateKnowledgebase/Program.cs?range=124-143"Add GET request to determine creation status")]
This API call returns a JSON response that includes the operation status:
111
111
@@ -136,13 +136,13 @@ Repeat the call until success or failure:
136
136
137
137
The following method creates the KB and repeats checks on the status. The _create_**Operation ID** is returned in the POST response header field **Location**, then used as part of the route in the GET request. Because the KB creation may take some time, you need to repeat calls to check the status until the status is either successful or fails. When the operation succeeds, the KB ID is returned in **resourceLocation**.
Copy file name to clipboardExpand all lines: articles/cognitive-services/QnAMaker/Quickstarts/create-new-kb-go.md
+12-22Lines changed: 12 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,44 +32,34 @@ Create a file named `create-new-knowledge-base.go`.
32
32
33
33
At the top of `create-new-knowledge-base.go`, add the following lines to add necessary dependencies to the project:
34
34
35
-
[!code-go[Add the required dependencies](~/samples-qnamaker-go/documentation-samples/quickstarts/create-knowledge-base/create-new-knowledge-base.go?range=1-11"Add the required dependencies")]
36
-
37
-
## Add the required constants
38
-
After the preceding required dependencies, add the required constants to access QnA Maker.
39
-
40
-
Set the following values:
41
-
42
-
*`<your-qna-maker-subscription-key>` - The **key** is a 32 character string and is available in the Azure portal, on the QnA Maker resource, on the Quickstart page. This is not the same as the prediction endpoint key.
43
-
*`{your-resource-name}` - Your **resource name** is used to construct the authoring endpoint URL for authoring, in the format of `https://YOUR-RESOURCE-NAME.cognitiveservices.azure.com`. This is not the same URL used to query the prediction endpoint.
44
-
45
-
[!code-go[Add the required constants](~/samples-qnamaker-go/documentation-samples/quickstarts/create-knowledge-base/create-new-knowledge-base.go?range=13-20"Add the required constants")]
After the constants, add the following KB model definition. The model is converting into a string after the definition.
49
39
50
-
[!code-go[Add the KB model definition](~/samples-qnamaker-go/documentation-samples/quickstarts/create-knowledge-base/create-new-knowledge-base.go?range=22-44"Add the KB model definition")]
[!code-go[Add the structure for an HTTP request](~/samples-qnamaker-go/documentation-samples/quickstarts/create-knowledge-base/create-new-knowledge-base.go?range=46-49"Add the structure for an HTTP request")]
2. Add the following method to handle a POST to the QnA Maker APIs. For this quickstart, the POST is used to send the KB definition to QnA Maker.
50
+
1. Add the following method to handle a POST to the QnA Maker APIs. For this quickstart, the POST is used to send the KB definition to QnA Maker.
61
51
62
-
[!code-go[Add the POST method](~/samples-qnamaker-go/documentation-samples/quickstarts/create-knowledge-base/create-new-knowledge-base.go?range=51-66"Add the POST method")]
3. Add the following method to handle a GET to the QnA Maker APIs. For this quickstart, the GET is used to check the status of the creation operation.
54
+
1. Add the following method to handle a GET to the QnA Maker APIs. For this quickstart, the GET is used to check the status of the creation operation.
65
55
66
-
[!code-go[Add the GET method](~/samples-qnamaker-go/documentation-samples/quickstarts/create-knowledge-base/create-new-knowledge-base.go?range=68-83"Add the GET method")]
Add the following functions to make an HTTP POST request to create the knowledge base. The _create_**Operation ID** is returned in the POST response header field **Location**, then used as part of the route in the GET request. The `Ocp-Apim-Subscription-Key` is the QnA Maker service key, used for authentication.
71
61
72
-
[!code-go[Add the create_kb method](~/samples-qnamaker-go/documentation-samples/quickstarts/create-knowledge-base/create-new-knowledge-base.go?range=85-97"Add the create_kb method")]
This API call returns a JSON response that includes the operation ID. Use the operation ID to determine if the KB is successfully created.
75
65
@@ -87,7 +77,7 @@ This API call returns a JSON response that includes the operation ID. Use the op
87
77
88
78
Add the following function to make an HTTP GET request to check the operation status. The `Ocp-Apim-Subscription-Key` is the QnA Maker service key, used for authentication.
89
79
90
-
[!code-go[Add the check_status method](~/samples-qnamaker-go/documentation-samples/quickstarts/create-knowledge-base/create-new-knowledge-base.go?range=99-108"Add the check_status method")]
@@ -105,7 +95,7 @@ Repeat the call until success or failure:
105
95
106
96
The following function is the main function and creates the KB and repeats checks on the status. Because the KB creation may take some time, you need to repeat calls to check the status until the status is either successful or fails.
107
97
108
-
[!code-go[Add the main method](~/samples-qnamaker-go/documentation-samples/quickstarts/create-knowledge-base/create-new-knowledge-base.go?range=110-140"Add the main method")]
description: This Java REST-based quickstart walks you through creating a sample QnA Maker knowledge base, programmatically, that will appear in your Azure Dashboard of your Cognitive Services API account..
3
+
description: This Java REST-based quickstart walks you through creating a sample QnA Maker knowledge base, programmatically, that will appear in your Azure Dashboard of your Cognitive Services API account.
4
4
ms.date: 12/16/2019
5
5
ROBOTS: NOINDEX,NOFOLLOW
6
6
ms.custom: RESTCURL2020FEB27, devx-track-java
@@ -34,7 +34,7 @@ Create a file named `CreateKB.java`
34
34
35
35
At the top of `CreateKB.java`, add the following lines to add necessary dependencies to the project:
36
36
37
-
[!code-java[Add the required dependencies](~/samples-qnamaker-java/documentation-samples/quickstarts/create-knowledge-base/CreateKB.java?range=1-5"Add the required dependencies")]
After the preceding required dependencies, add the required constants to the `CreateKB` class to access QnA Maker.
@@ -43,43 +43,43 @@ You must have a [QnA Maker service](../How-To/set-up-qnamaker-service-azure.md).
43
43
44
44
Set the following values:
45
45
46
-
*`<your-qna-maker-subscription-key>` - The **key** is a 32 character string and is available in the Azure portal, on the QnA Maker resource, on the Quickstart page. This is not the same as the prediction endpoint key.
47
-
*`<your-resource-name>` - Your **resource name** is used to construct the authoring endpoint URL for authoring, in the format of `https://YOUR-RESOURCE-NAME.cognitiveservices.azure.com`. This is not the same URL used to query the prediction endpoint.
46
+
*`<your-qna-maker-subscription-key>` - The **key** is a 32 character string and is available in the Azure portal, on the QnA Maker resource, on the Quickstart page. This key is not the same as the prediction endpoint key.
47
+
*`<your-resource-name>` - Your **resource name** is used to construct the authoring endpoint URL for authoring, in the format of `https://YOUR-RESOURCE-NAME.cognitiveservices.azure.com`. This resource name is not the same as the one used to query the prediction endpoint.
48
48
49
49
You do not need to add the final curly bracket to end the class; it is in the final code snippet at the end of this quickstart.
50
50
51
-
[!code-java[Add the required constants](~/samples-qnamaker-java/documentation-samples/quickstarts/create-knowledge-base/CreateKB.java?range=26-34"Add the required constants")]
After the constants, add the following classes and functions inside the `CreateKB` class to serialize the model definition object into JSON.
56
56
57
-
[!code-java[Add the KB model definition classes](~/samples-qnamaker-java/documentation-samples/quickstarts/create-knowledge-base/CreateKB.java?range=36-80"Add the KB model definition classes")]
Next, add the following supporting functions inside the `CreateKB` class.
62
62
63
63
1. Add the following function to print out JSON in a readable format:
64
64
65
-
[!code-java[Add the PrettyPrint function](~/samples-qnamaker-java/documentation-samples/quickstarts/create-knowledge-base/CreateKB.java?range=82-87"Add the KB model definition classes")]
2. Add the following class to manage the HTTP response:
68
68
69
-
[!code-java[Add class to manage the HTTP response](~/samples-qnamaker-java/documentation-samples/quickstarts/create-knowledge-base/CreateKB.java?range=89-97"Add class to manage the HTTP response")]
3. Add the following method to make a POST request to the QnA Maker APIs. The `Ocp-Apim-Subscription-Key` is the QnA Maker service key, used for authentication.
72
72
73
-
[!code-java[Add POST method](~/samples-qnamaker-java/documentation-samples/quickstarts/create-knowledge-base/CreateKB.java?range=99-121"Add POST method")]
4. Add the following method to make a GET request to the QnA Maker APIs.
76
76
77
-
[!code-java[Add GET method](~/samples-qnamaker-java/documentation-samples/quickstarts/create-knowledge-base/CreateKB.java?range=123-137"Add GET method")]
@@ -114,17 +114,17 @@ Repeat the call until success or failure:
114
114
## Add a main method
115
115
The main method creates the KB, then polls for the status. The operation ID is returned in the POST response header field **Location**, then used as part of the route in the GET request. The `while` loop retries the status if it is not completed.
116
116
117
-
[!code-java[Add main method](~/samples-qnamaker-java/documentation-samples/quickstarts/create-knowledge-base/CreateKB.java?range=152-191"Add main method")]
1. Make sure the gson library is in the `./libs` directory. At the command-line, compile the file `CreateKB.java`:
121
+
1. Make sure the gson library is in the `./libs` directory. At the commandline, compile the file `CreateKB.java`:
122
122
123
123
```bash
124
124
javac -cp ".;libs/*" CreateKB.java
125
125
```
126
126
127
-
2. Enter the following command at a command-line to run the program. It will send the request to the QnA Maker API to create the KB, then it will poll for the results every 30 seconds. Each response is printed to the console window.
127
+
2. Enter the following command at a commandline to run the program. It will send the request to the QnA Maker API to create the KB, then it will poll for the results every 30 seconds. Each response is printed to the console window.
128
128
129
129
```bash
130
130
java -cp ",;libs/*" CreateKB
@@ -137,4 +137,4 @@ Once your knowledge base is created, you can view it in your QnA Maker Portal, [
137
137
## Next steps
138
138
139
139
> [!div class="nextstepaction"]
140
-
> [QnA Maker (V4) REST API Reference](https://go.microsoft.com/fwlink/?linkid=2092179)
140
+
> [QnA Maker (V4) REST API Reference](https://go.microsoft.com/fwlink/?linkid=2092179)
0 commit comments