Example #1
0
        private async Task EmitTraceInfoAsync(ITurnContext turnContext, Activity messageActivity, QueryResult[] result, QnAMakerOptions options)
        {
            AnswerSpanRequest answerSpanRequest = null;

            if (options.EnablePreciseAnswer)
            {
                answerSpanRequest        = new AnswerSpanRequest();
                answerSpanRequest.Enable = options.EnablePreciseAnswer;
            }

            var traceInfo = new QnAMakerTraceInfo
            {
                Message           = messageActivity,
                QueryResults      = result,
                KnowledgeBaseId   = _endpoint.KnowledgeBaseId,
                ScoreThreshold    = options.ScoreThreshold,
                Top               = options.Top,
                StrictFilters     = options.StrictFilters,
                Context           = options.Context,
                QnAId             = options.QnAId,
                IsTest            = options.IsTest,
                RankerType        = options.RankerType,
                AnswerSpanRequest = answerSpanRequest
            };
            var traceActivity = Activity.CreateTraceActivity(QnAMaker.QnAMakerName, QnAMaker.QnAMakerTraceType, traceInfo, QnAMaker.QnAMakerTraceLabel);
            await turnContext.SendActivityAsync(traceActivity).ConfigureAwait(false);
        }
Example #2
0
        private async Task <QueryResults> QueryQnaServiceAsync(Activity messageActivity, QnAMakerOptions options)
        {
            var requestUrl = $"{_endpoint.Host}/knowledgebases/{_endpoint.KnowledgeBaseId}/generateanswer";
            AnswerSpanRequest answerSpanRequest = null;

            if (options.EnablePreciseAnswer)
            {
                answerSpanRequest        = new AnswerSpanRequest();
                answerSpanRequest.Enable = options.EnablePreciseAnswer;
            }

            var jsonRequest = JsonConvert.SerializeObject(
                new
            {
                question       = messageActivity.Text,
                top            = options.Top,
                strictFilters  = options.StrictFilters,
                scoreThreshold = options.ScoreThreshold,
                context        = options.Context,
                qnaId          = options.QnAId,
                isTest         = options.IsTest,
                rankerType     = options.RankerType,
                StrictFiltersCompoundOperationType = options.StrictFiltersJoinOperator,
                answerSpanRequest = answerSpanRequest
            }, Formatting.None);

            var httpRequestHelper = new HttpRequestUtils(_httpClient);
            var response          = await httpRequestHelper.ExecuteHttpRequestAsync(requestUrl, jsonRequest, _endpoint).ConfigureAwait(false);

            var result = await FormatQnaResultAsync(response, options).ConfigureAwait(false);

            return(result);
        }