Uri IQnAService.BuildFeedbackRequest(string userId, string userQuery, string kbQuestion, string kbAnswer, out QnAMakerTrainingRequestBody postBody, out string subscriptionKey, out string knowledgebaseId)
        {
            knowledgebaseId = this.qnaInfo.KnowledgebaseId;
            subscriptionKey = this.qnaInfo.SubscriptionKey;
            var builder        = new UriBuilder($"{UriBase}/{knowledgebaseId}/train");
            var feedbackRecord = new FeedbackRecord {
                UserId = userId, UserQuestion = userQuery, KbQuestion = kbQuestion, KbAnswer = kbAnswer
            };
            var feedbackRecords = new List <FeedbackRecord>();

            feedbackRecords.Add(feedbackRecord);
            postBody = new QnAMakerTrainingRequestBody {
                KnowledgeBaseId = knowledgebaseId, FeedbackRecords = feedbackRecords
            };
            return(builder.Uri);
        }
        async Task <bool> IQnAService.ActiveLearnAsync(Uri uri, QnAMakerTrainingRequestBody postBody, string subscriptionKey)
        {
            try
            {
                string json = string.Empty;

                using (HttpClient client = new HttpClient())
                {
                    var request = new HttpRequestMessage(new HttpMethod("PATCH"), uri)
                    {
                        Content =
                            new StringContent(
                                JsonConvert
                                .SerializeObject(
                                    postBody),
                                Encoding.UTF8,
                                "application/json")
                    };

                    //Add the subscription key header
                    client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

                    var response = await client.SendAsync(request);

                    if (response != null && response.Content != null)
                    {
                        json = await response.Content.ReadAsStringAsync();
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        async Task <bool> IQnAService.ActiveLearnAsync(Uri uri, QnAMakerTrainingRequestBody postBody, string subscriptionKey)
        {
            try
            {
                string json;
                using (WebClient client = new WebClient())
                {
                    //Set the encoding to UTF8
                    client.Encoding = Encoding.UTF8;

                    //Add the subscription key header
                    client.Headers.Add("Authorization", subscriptionKey);
                    client.Headers.Add("Content-Type", "application/json");

                    json = client.UploadString(uri, "PATCH", JsonConvert.SerializeObject(postBody));
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }