Ejemplo 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);
        }
Ejemplo n.º 2
0
        private async Task <bool> SendUpdateKbRequest(QnAMakerUpdateKBInput inputObject)
        {
            var url      = $"{qnamakerManagementUriBase}/knowledgebases/{knowledgebaseId}";
            var response = await SendQnAMakerManagementRequest(inputObject, new HttpMethod("PATCH"), url);

            if (response.IsSuccessStatusCode)
            {
                var status = JsonConvert.DeserializeObject <OperationStatus>(await response.Content.ReadAsStringAsync());

                while (status.operationState != "Succeeded")
                {
                    Thread.Sleep(500);
                    var statusResponse = await SendQnAMakerManagementRequest(HttpMethod.Get, $"{qnamakerManagementUriBase}/operations/{status.operationId}");

                    if (statusResponse.IsSuccessStatusCode)
                    {
                        var content = JsonConvert.DeserializeObject <OperationStatus>(await statusResponse.Content.ReadAsStringAsync());
                        status = content;
                    }
                    else
                    {
                        return(false);
                    }
                }

                var publishResponse = await SendQnAMakerManagementRequest(string.Empty, HttpMethod.Post, url);

                return(publishResponse.IsSuccessStatusCode);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public async Task <bool> StoreNewAnswer(string question, string answer)
        {
            var inputObject = new QnAMakerUpdateKBInput();

            inputObject.Add.QnaPairs.Add(new QnAMakerUpdateKBInput.QnaDto()
            {
                questions = new List <string>()
                {
                    question
                },
                answer = answer
            });
            return(await SendUpdateKbRequest(inputObject));
        }