private async Task <string> CreateSampleKb(string language) { Console.WriteLine($"\nCreating SampleKB to create default azure search 'testkb' index for language: {language}"); var qna1 = new QnADTO { Answer = "a1", Questions = new List <string> { "q1" } }; var createKbDto = new CreateKbDTO { Name = "Sample KB to create TestKbIndex In Azure Search", QnaList = new List <QnADTO> { qna1 }, Language = language }; var createOp = await this.client.Knowledgebase.CreateAsync(createKbDto); createOp = await this.MonitorOperation(createOp); return(createOp.ResourceLocation.Replace("/knowledgebases/", string.Empty)); }
private static async Task <string> CreateSampleKb(IQnAMakerClient client) { var qna = new QnADTO { Answer = "You can use our REST APIs to manage your knowledge base.", Questions = new List <string> { "How do I manage my knowledgebase?" }, Metadata = new List <MetadataDTO> { new MetadataDTO { Name = "Category", Value = "api" } } }; var urls = new List <string> { "https://docs.microsoft.com/en-in/azure/cognitive-services/qnamaker/faqs" }; var createKbDto = new CreateKbDTO { Name = "QnA Maker FAQ from quickstart", QnaList = new List <QnADTO> { qna }, Urls = urls }; var createOp = await client.Knowledgebase.CreateAsync(createKbDto); createOp = await MonitorOperation(client, createOp); return(createOp.ResourceLocation.Replace("/knowledgebases/", string.Empty)); }
// </UpdateKBMethod> // <CreateKBMethod> private static async Task <string> CreateSampleKb(IQnAMakerClient client) { var qna1 = new QnADTO { Answer = "Yes, You can use our [REST APIs](https://docs.microsoft.com/rest/api/cognitiveservices/qnamaker/knowledgebase) to manage your knowledge base.", Questions = new List <string> { "How do I manage my knowledgebase?" }, Metadata = new List <MetadataDTO> { new MetadataDTO { Name = "Category", Value = "api" }, new MetadataDTO { Name = "Language", Value = "REST" } }, }; var qna2 = new QnADTO { Answer = "Yes, You can use our [.NET SDK](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker) with the [.NET Reference Docs](https://docs.microsoft.com/dotnet/api/microsoft.azure.cognitiveservices.knowledge.qnamaker?view=azure-dotnet) to manage your knowledge base.", Questions = new List <string> { "Can I program with C#?" }, Metadata = new List <MetadataDTO> { new MetadataDTO { Name = "Category", Value = "api" }, new MetadataDTO { Name = "Language", Value = ".NET" } } }; var file1 = new FileDTO { FileName = "myfile.tsv", FileUri = "https://mydomain/myfile.tsv" }; var createKbDto = new CreateKbDTO { Name = "QnA Maker .NET SDK Quickstart", QnaList = new List <QnADTO> { qna1, qna2 }, //Files = new List<FileDTO> { file1 } }; var createOp = await client.Knowledgebase.CreateAsync(createKbDto); createOp = await MonitorOperation(client, createOp); return(createOp.ResourceLocation.Replace("/knowledgebases/", string.Empty)); }
// </UpdateKBMethod> // <CreateKBMethod> private static async Task <string> CreateSampleKb(IQnAMakerClient client) { var qna1 = new QnADTO { Answer = "You can use our REST APIs to manage your knowledge base.", Questions = new List <string> { "How do I manage my knowledgebase?" }, Metadata = new List <MetadataDTO> { new MetadataDTO { Name = "Category", Value = "api" } }, }; var qna2 = new QnADTO { Answer = "You, can use our .NET SDK to manage your knowledge base.", Questions = new List <string> { "Can I use a .NET NuGet package to create the KB?" }, Metadata = new List <MetadataDTO> { new MetadataDTO { Name = "Category", Value = "api" } } }; var file1 = new FileDTO { FileName = "myFileName", FileUri = "https://mydomain/myfile.md" }; var createKbDto = new CreateKbDTO { Name = "QnA Maker .NET SDK Quickstart", QnaList = new List <QnADTO> { qna1, qna2 }, //Files = new List<FileDTO> { file1 } }; var createOp = await client.Knowledgebase.CreateAsync(createKbDto); createOp = await MonitorOperation(client, createOp); return(createOp.ResourceLocation.Replace("/knowledgebases/", string.Empty)); }
private static void LoadQnaDocuments(QnADocumentsDTO qnaDocumentsDTO, List <QnADTO> qnaDTOs) { foreach (var document in qnaDocumentsDTO.QnaDTO) { QnADTO qnaDTO = new QnADTO { Answer = document.Answer, Context = document.Context, Id = document.Id, Metadata = document.Metadata, Questions = document.Questions, Source = document.Source }; qnaDTOs.Add(qnaDTO); } }
private static void LoadAddQnADTOs( IEnumerable <PortalDbRecordDTO> portalDbRecords, QnADocumentsDTO qnaDocumentsDTO, List <QnADTO> qnADTOs) { foreach (PortalDbRecordDTO portalDbRecord in portalDbRecords) { bool flag = false; string str = ""; List <string> source = new List <string>(); foreach (QnADTO qnAdto in qnaDocumentsDTO.QnaDTO) { foreach (MetadataDTO metadataDto in qnAdto.Metadata) { if (metadataDto.Name == "faqid") { str = metadataDto.Value; } } if (str == portalDbRecord.FaqId.ToString()) { flag = true; } } if (!flag) { List <MetadataDTO> metadataDtoList = LoadMetadata(portalDbRecord); source.Add(portalDbRecord.FaqQuestion); QnADTO qnAdto = new QnADTO() { Answer = portalDbRecord.FaqAnswer, Metadata = metadataDtoList, Questions = source.ToList <string>(), Source = "FAQ" }; qnADTOs.Add(qnAdto); } } }
// </UpdateKBMethod> // <CreateKBMethod> private static async Task <string> CreateSampleKb(IQnAMakerClient client) { var qna1 = new QnADTO { Answer = "You can use our REST APIs to manage your knowledge base.", Questions = new List <string> { "How do I manage my knowledgebase?" }, Metadata = new List <MetadataDTO> { new MetadataDTO { Name = "Category", Value = "api" } } }; var file1 = new FileDTO { FileName = "myFileName", FileUri = "https://mydomain/myfile.md" }; var urls = new List <string> { "https://docs.microsoft.com/en-in/azure/cognitive-services/QnAMaker/troubleshooting" }; var createKbDto = new CreateKbDTO { Name = "QnA Maker .NET SDK Quickstart", QnaList = new List <QnADTO> { qna1 }, //Files = new List<FileDTO> { file1 }, Urls = urls }; var createOp = await client.Knowledgebase.CreateAsync(createKbDto); createOp = await MonitorOperation(client, createOp); return(createOp.ResourceLocation.Replace("/knowledgebases/", string.Empty)); }
/// <inheritdoc/> public async Task <string> PostQnAPairAsync(Question question, Answer answer, string logicalKnowledgeBaseId) { var qnADTO = new QnADTO() { Questions = new List <string>() { question.GetSanitizedMessage() }, Answer = answer.GetSanitizedMessage(), Metadata = this.GetMetaData(logicalKnowledgeBaseId), }; var operation = new UpdateKbOperationDTO() { Add = new UpdateKbOperationDTOAdd() { QnaList = new List <QnADTO>() { qnADTO }, }, }; try { var response = await this.qnAClient.Knowledgebase.UpdateAsync(this.settings.KnowledgeBaseId, operation); return(response.OperationId); // Note: We do not check operation status. } catch (ErrorResponseException exception) { var message = $"Failed to post QnA Pair to QnA Service. Question Id: {question.Id}. Answer Id: {answer.Id}"; this.logger.LogWarning(exception, message); throw new QBotException(HttpStatusCode.InternalServerError, ErrorCode.Unknown, message, exception); } }
private UpdateKbOperationDTO GenerateKbUpdatesFromNewInsults(QnADocumentsDTO kbData, List <InsultResponse> newInsultResponses) { List <QnADTO> newQnAs = new List <QnADTO>(); Dictionary <QnADTO, List <string> > updatesMatrix = new Dictionary <QnADTO, List <string> >(); // Enumerate insult responses, as we want to check each new response exists or not as an Answer foreach (var newInsultResponse in newInsultResponses) { // Do any of the new insult answers exist in another qna answer-list already? QnADTO answerExistingDoc = null; foreach (var qnaDoc in kbData.QnaDocuments) { if (qnaDoc.Answer.ToLower() == newInsultResponse.Text.ToLower()) { // Add insult (question) to existing insult-resoponse (answer) answerExistingDoc = qnaDoc; break; } } if (answerExistingDoc != null) { // Insult response exists. Check each original insult for this response foreach (var responseInsult in newInsultResponse.InsultTriggers) { if (!answerExistingDoc.Questions.Contains(responseInsult.Text)) { var answer = answerExistingDoc.Answer; // Add updates to dictionary by answer, so we can compile all updates together at the end if (!updatesMatrix.ContainsKey(answerExistingDoc)) { updatesMatrix.Add(answerExistingDoc, new List <string>()); } // Add new insult for existing response updatesMatrix[answerExistingDoc].Add(responseInsult.Text); } } } else { // Never seen the insult before, or the response. Add new both. newQnAs.Add(new QnADTO() { Answer = newInsultResponse.Text, Questions = newInsultResponse.InsultTriggers.Select(i => i.Text).ToList() }); } } // Build API structure for all updates var qnasToUpdate = new List <UpdateQnaDTO>(); foreach (var update in updatesMatrix.Keys) { qnasToUpdate.Add(new UpdateQnaDTO { Id = update.Id, Source = update.Source, Answer = update.Answer, Questions = new UpdateQnaDTOQuestions { Add = updatesMatrix[update] } }); } var changes = new UpdateKbOperationDTO(); changes.Add = new UpdateKbOperationDTOAdd() { QnaList = newQnAs }; changes.Update = new UpdateKbOperationDTOUpdate { QnaList = qnasToUpdate }; return(changes); }