コード例 #1
0
        private async Task <DialogTurnResult> FilterLowVariationScoreList(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var response = stepContext.Values[QnAData] as List <QueryResult>;

            var filteredResponse = ActiveLearningHelper.GetLowScoreVariation(response);

            stepContext.Values[QnAData] = filteredResponse;

            if (filteredResponse.Count > 1)
            {
                var suggestedQuestions = new List <string>();
                foreach (var qna in filteredResponse)
                {
                    suggestedQuestions.Add(qna.Questions[0]);
                }

                // Get hero card activity
                var message = CardHelper.GetHeroCard(suggestedQuestions);

                await stepContext.Context.SendActivityAsync(message);

                return(new DialogTurnResult(DialogTurnStatus.Waiting));
            }
            else
            {
                return(await stepContext.NextAsync(new List <QueryResult>(response), cancellationToken));
            }
        }
コード例 #2
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));
        }