Esempio n. 1
0
        public async Task <bool> ReplaceAnswer(string question, string answer, IQnaResponse qnaResponse)
        {
            var url      = $"{qnamakerManagementUriBase}/knowledgebases/{knowledgebaseId}/Prod/qna ";
            var response = await SendQnAMakerManagementRequest(HttpMethod.Get, url);

            QnaDbResponse kb = null;

            if (response.IsSuccessStatusCode)
            {
                kb = JsonConvert.DeserializeObject <QnaDbResponse>(await response.Content.ReadAsStringAsync());
            }

            if (kb != null)
            {
                var qnaPair = kb.qnaDocuments.FirstOrDefault(x => x.answer == qnaResponse.Answer && x.questions.Contains(question));

                if (qnaPair != null)
                {
                    var inputObject = new QnAMakerUpdateKBInput();
                    inputObject.Update.qnaList = new List <QnAMakerUpdateKBInput.QnaUpdateDto>()
                    {
                        new QnAMakerUpdateKBInput.QnaUpdateDto()
                        {
                            id     = qnaPair.id,
                            answer = answer,
                        }
                    };
                    return(await SendUpdateKbRequest(inputObject));
                }
            }
            return(false);
        }
Esempio n. 2
0
        private IKnowledgeBase ParseKnowledgeBase(QnaDbResponse qandAResponse)
        {
            var knowledgeBase = new Dictionary <string, string>();

            foreach (var answer in qandAResponse.qnaDocuments)
            {
                foreach (var question in answer.questions)
                {
                    if (!knowledgeBase.ContainsKey(question))
                    {
                        knowledgeBase.Add(question, answer.answer);
                    }
                }
            }

            return(new KnowledgeBaseEntity()
            {
                KnowledgeBase = knowledgeBase
            });
        }