示例#1
0
        private async Task <DialogTurnResult> CallTrain(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var trainResponses = stepContext.Values[QnAData] as List <QueryResult>;
            var currentQuery   = stepContext.Values[CurrentQuery] as string;

            if (trainResponses.Count > 1)
            {
                var reply     = stepContext.Context.Activity.Text;
                var qnaResult = trainResponses.Where(kvp => kvp.Questions[0] == reply).FirstOrDefault();

                if (qnaResult != null)
                {
                    stepContext.Values[QnAData] = new List <QueryResult>()
                    {
                        qnaResult
                    };

                    var records = new FeedbackRecord[]
                    {
                        new FeedbackRecord
                        {
                            UserId       = stepContext.Context.Activity.Id,
                            UserQuestion = currentQuery,
                            QnaId        = qnaResult.Id,
                        }
                    };

                    var feedbackRecords = new FeedbackRecords {
                        Records = records
                    };

                    // Call Active Learning Train API
                    ActiveLearningHelper.CallTrain(_services.QnaEndpoint.Host, feedbackRecords, _services.QnaEndpoint.KnowledgeBaseId, _services.QnaEndpoint.EndpointKey, cancellationToken);

                    return(await stepContext.NextAsync(new List <QueryResult>(){ qnaResult }, cancellationToken));
                }
                else
                {
                    return(await stepContext.EndDialogAsync());
                }
            }

            return(await stepContext.NextAsync(stepContext.Result, cancellationToken));
        }
示例#2
0
        /// <summary>
        /// Method to call QnAMaker Train API for Active Learning
        /// TODO: Move it to the SDK code
        /// </summary>
        /// <param name="host">Endpoint host of the runtime</param>
        /// <param name="body">Body of the train API</param>
        /// <param name="kbId">Knowledgebase Id</param>
        /// <param name="key">Endpoint key</param>
        /// <param name="cancellationToken"> Cancellation token</param>
        public async static void CallTrain(string host, FeedbackRecords feedbackRecords, string kbId, string key, CancellationToken cancellationToken)
        {
            var uri = host + "/knowledgebases/" + kbId + "/train/";

            using (var client = new HttpClient())
            {
                using (var request = new HttpRequestMessage())
                {
                    request.Method     = HttpMethod.Post;
                    request.RequestUri = new Uri(uri);
                    request.Content    = new StringContent(JsonConvert.SerializeObject(feedbackRecords), Encoding.UTF8, "application/json");
                    request.Headers.Add("Authorization", "EndpointKey " + key);

                    var response = await client.SendAsync(request, cancellationToken);

                    await response.Content.ReadAsStringAsync();
                }
            }
        }