private async Task QueryTrainAsync(FeedbackRecords feedbackRecords)
        {
            var requestUrl  = $"{_endpoint.Host}/knowledgebases/{_endpoint.KnowledgeBaseId}/train";
            var jsonRequest = JsonConvert.SerializeObject(feedbackRecords, Formatting.None);

            var httpRequestHelper = new HttpRequestUtils(httpClient);
            var response          = await httpRequestHelper.ExecuteHttpRequestAsync(requestUrl, jsonRequest, _endpoint).ConfigureAwait(false);
        }
        /// <summary>
        /// Train API to provide feedback.
        /// </summary>
        /// <param name="feedbackRecords">Feedback record list.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task CallTrainAsync(FeedbackRecords feedbackRecords)
        {
            if (feedbackRecords == null)
            {
                throw new ArgumentNullException(nameof(feedbackRecords), "Feedback records cannot be null.");
            }

            if (feedbackRecords.Records == null || feedbackRecords.Records.Length == 0)
            {
                return;
            }

            // Call train
            await this.QueryTrainAsync(feedbackRecords).ConfigureAwait(false);
        }
Exemple #3
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;

            var reply = stepContext.Context.Activity.Text;

            var dialogOptions            = GetDialogOptionsValue(stepContext);
            var qnaDialogResponseOptions = dialogOptions[QnADialogResponseOptions] as QnADialogResponseOptions;

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

                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
                    await _qnaMakerClient.CallTrainAsync(feedbackRecords).ConfigureAwait(false);

                    return(await stepContext.NextAsync(new List <QueryResult>() { qnaResult }, cancellationToken).ConfigureAwait(false));
                }
                else if (reply.Equals(qnaDialogResponseOptions.CardNoMatchText, StringComparison.OrdinalIgnoreCase))
                {
                    var activity = await qnaDialogResponseOptions.CardNoMatchResponse.BindToData(stepContext.Context, stepContext.State).ConfigureAwait(false);

                    if (activity == null)
                    {
                        await stepContext.Context.SendActivityAsync(DefaultCardNoMatchResponse, cancellationToken : cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        await stepContext.Context.SendActivityAsync(activity, cancellationToken : cancellationToken).ConfigureAwait(false);
                    }

                    return(await stepContext.EndDialogAsync().ConfigureAwait(false));
                }
                else
                {
                    return(await stepContext.ReplaceDialogAsync(QnAMakerDialogName, stepContext.ActiveDialog.State["options"], cancellationToken).ConfigureAwait(false));
                }
            }

            return(await stepContext.NextAsync(stepContext.Result, cancellationToken).ConfigureAwait(false));
        }
Exemple #4
0
 /// <summary>
 /// Send feedback to the knowledge base.
 /// </summary>
 /// <param name="feedbackRecords">Feedback records.</param>
 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
 public async Task CallTrainAsync(FeedbackRecords feedbackRecords)
 {
     await this.activeLearningTrainHelper.CallTrainAsync(feedbackRecords).ConfigureAwait(false);
 }
Exemple #5
0
 /// <summary>
 /// Send feedback to the knowledge base.
 /// </summary>
 /// <param name="feedbackRecords">An object containing an array of <see cref="FeedbackRecord"/>.</param>
 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
 public async Task CallTrainAsync(FeedbackRecords feedbackRecords)
 {
     await _languageServiceHelper.UpdateActiveLearningFeedbackAsync(feedbackRecords).ConfigureAwait(false);
 }
Exemple #6
0
 public Task CallTrainAsync(FeedbackRecords feedbackRecords)
 {
     return(Task.FromResult <object>(null));
 }