forked from Azure-Samples/cognitive-services-qnamaker-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete-knowledge-base.cs
68 lines (59 loc) · 1.77 KB
/
delete-knowledge-base.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
// NOTE: Install the Newtonsoft.Json NuGet package.
using Newtonsoft.Json;
namespace QnAMaker
{
class Program
{
static string host = "https://westus.api.cognitive.microsoft.com";
static string service = "/qnamaker/v4.0";
static string method = "/knowledgebases/";
// NOTE: Replace this with a valid subscription key from the Azure portal.
static string key = "ADD KEY HERE";
// NOTE: Replace this with a valid knowledge base ID, the one you want to delete, from qnamaker.ai.
static string kb = "ADD KNOWLEDGE BASE ID HERE";
static string PrettyPrint(string s)
{
return JsonConvert.SerializeObject(JsonConvert.DeserializeObject(s), Formatting.Indented);
}
async static Task<string> Delete(string uri)
{
using (var client = new HttpClient())
using (var request = new HttpRequestMessage())
{
request.Method = HttpMethod.Delete;
request.RequestUri = new Uri(uri);
request.Headers.Add("Ocp-Apim-Subscription-Key", key);
var response = await client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
return "{'result' : 'Success.'}";
}
else
{
return await response.Content.ReadAsStringAsync();
}
}
}
async static void DeleteKB()
{
var uri = host + service + method + kb;
Console.WriteLine("Calling " + uri + ".");
var response = await Delete(uri);
Console.WriteLine(PrettyPrint(response));
Console.WriteLine("Press any key to continue.");
}
static void Main(string[] args)
{
DeleteKB();
Console.ReadLine();
}
}
}