internal bool Update(UpdateRootobject toPublish) { if (null == toPublish.add?.qnaList && null == toPublish.delete?.ids && null == toPublish.update?.qnaList) { return(false); } if (null == this.details) { this.details = GetDetails(); this.knowledgeBaseId = this.details.id; } string host = $"https://{this.azureServicName}.{baseUrl}"; string service = "/qnamaker/v4.0"; string method = "/knowledgebases/{0}"; var method_with_id = String.Format(method, this.knowledgeBaseId); var uri = host + service + method_with_id; string requestBody = JsonConvert.SerializeObject(toPublish); using (var client = new HttpClient()) using (var request = new HttpRequestMessage()) { request.Method = new HttpMethod("PATCH"); request.RequestUri = new Uri(uri); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", ocpApimSubscriptionKey); request.Content = new StringContent(requestBody, Encoding.UTF8, "application/json"); var response = client.SendAsync(request).Result; WaitForOperationToComplete(client, response); return(response.IsSuccessStatusCode); } }
private bool KnowledgeBaseExists() { KnowledgeBaseDetails details = GetDetails(); if (null != details) { this.details = details; } return(null != details); }
public void CreateIfDoesntExist() { if (!this.KnowledgeBaseExists()) { this.CreateKnowledgeBase(this.knowledgebase); this.details = this.GetDetails(); } this.knowledgeBaseId = this.details?.id; }
public virtual KnowledgeBaseExtractionDetails CreateKnowledgeBase(KnowledgeBaseDetails request) { try { var result = QnAMakerRepository.CreateKnowledgeBase(request); return(result); } catch (Exception ex) { Logger.Error("QnAMakerService.CreateKnowledgeBase failed", this, ex); } return(null); }
public virtual KnowledgeBaseExtractionDetails CreateKnowledgeBase(KnowledgeBaseDetails request) { return(PolicyService.ExecuteRetryAndCapture400Errors( "QnAMakerService.CreateKnowledgeBase", ApiKeys.QnARetryInSeconds, () => { var result = QnAMakerRepository.CreateKnowledgeBase(request); return result; }, null)); }
public KnowledgeBaseDetails GetDetails() { if (null != this.details) { return(this.details); } using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) { string RequestURI = $"https://{this.azureServicName}.{baseUrl}/qnamaker/v4.0/knowledgebases/"; client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", ocpApimSubscriptionKey); System.Net.Http.HttpResponseMessage msg = client.GetAsync(RequestURI).Result; msg.EnsureSuccessStatusCode(); var JsonDataResponse = msg.Content.ReadAsStringAsync().Result; KnowledgeBaseListAllRootObject allKBs = JsonConvert.DeserializeObject <KnowledgeBaseListAllRootObject>(JsonDataResponse); if (null == allKBs) { throw new JsonException("Could not deserialize the list of knowledgebases"); } if (!string.IsNullOrEmpty(this.knowledgeBaseId)) { this.details = allKBs.knowledgebases.FirstOrDefault(p => p.id == this.knowledgeBaseId); return(this.details); } var allDetails = allKBs.knowledgebases.Where(p => p.name == this.knowledgebase).ToArray(); if (allDetails.Length == 0) { return(null); } if (allDetails.Length > 1) { throw new KeyNotFoundException($"More than one Knowledge base found with name {this.knowledgebase}, please pass in knowledge base id to differentiate them"); } this.details = allDetails[0]; return(this.details); } }
public void DeleteKnowledgeBase() { if (null == this.details) { this.details = GetDetails(); this.knowledgeBaseId = this.details.id; } string RequestURI = $"https://{this.azureServicName}.{baseUrl}/qnamaker/v4.0/knowledgebases/{this.knowledgeBaseId}"; using (var client = new HttpClient()) using (var request = new HttpRequestMessage()) { request.Method = HttpMethod.Delete; request.RequestUri = new Uri(RequestURI); request.Headers.Add("Ocp-Apim-Subscription-Key", this.ocpApimSubscriptionKey); var response = client.SendAsync(request).Result; response.EnsureSuccessStatusCode(); } }
public string GetKnowledgebaseJson(EnvironmentType env = EnvironmentType.Test) { if (null == this.details) { this.details = GetDetails(); this.knowledgeBaseId = this.details.id; } // Make a web call to get the contents of the // .tsv file that contains the database string RequestURI = $"https://{this.azureServicName}.{baseUrl}/qnamaker/v4.0/knowledgebases/{this.knowledgeBaseId}/{env}/qna"; using (var client = new HttpClient()) using (var request = new HttpRequestMessage()) { request.Method = HttpMethod.Get; request.RequestUri = new Uri(RequestURI); request.Headers.Add("Ocp-Apim-Subscription-Key", this.ocpApimSubscriptionKey); var response = client.SendAsync(request).Result; response.EnsureSuccessStatusCode(); return(response.Content.ReadAsStringAsync().Result); } }
public virtual async Task <KnowledgeBaseExtractionDetails> CreateKnowledgeBaseAsync(KnowledgeBaseDetails request) { var response = await RepositoryClient.SendJsonPostAsync(ApiKeys.QnA, $"{ApiKeys.QnAEndpoint}create", JsonConvert.SerializeObject(request)); return(JsonConvert.DeserializeObject <KnowledgeBaseExtractionDetails>(response)); }