Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <QnAMakerResponse> CreateKB(CreateKBRequest body)
        {
            var uri = $"{this.qnaMakerApiEndpointUrl}/{MethodKB}/create";

            using (var httpRequest = new HttpRequestMessage(HttpMethod.Post, uri))
            {
                httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
                httpRequest.Headers.Add(Constants.OcpApimSubscriptionKey, this.subscriptionKey);

                var response = await this.httpClient.SendAsync(httpRequest);

                response.EnsureSuccessStatusCode();

                return(JsonConvert.DeserializeObject <QnAMakerResponse>(await response.Content.ReadAsStringAsync()));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates Knowledge base
        /// </summary>
        /// <param name="kbName">Knowledge base name</param>
        /// <param name="qnAMakerService">QnAMaker service</param>
        /// <returns>Returns kbId</returns>
        private async Task <string> CreateEmptyKB(string kbName, QnAMakerService qnAMakerService)
        {
            string          kbId            = string.Empty;
            CreateKBRequest createKBRequest = new CreateKBRequest()
            {
                Name = kbName,
            };

            var qnaMakerResponse = await qnAMakerService.CreateKB(createKBRequest);

            var operationResponse = await qnAMakerService.AwaitOperationCompletionResponse(qnaMakerResponse);

            if (qnAMakerService.IsOperationSuccessful(operationResponse.OperationState))
            {
                kbId = operationResponse.ResourceLocation.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1];
            }

            return(kbId);
        }
Ejemplo n.º 3
0
 public async Task <ActionResult> Create(CreateKBModel createKBModel)
 {
     try
     {
         CreateKBRequest createKBRequest = new CreateKBRequest();
         createKBRequest.name    = createKBModel.Name;
         createKBRequest.qnaList = new List <QnaList>()
         {
             new QnaList()
             {
                 id        = 0,
                 answer    = "Use this admin app to create the knowledge base",
                 source    = "Admin App",
                 questions = new List <string>()
                 {
                     "What admin app can do?"
                 },
                 metadata = new List <Metadata>()
                 {
                     new Metadata()
                     {
                         name  = "category",
                         value = "api"
                     }
                 }
             }
         };
         createKBRequest.urls = Uri.UnescapeDataString(createKBModel.Urls).Split(',').ToList <string>();
         //createKBRequest.urls = ExtractUrls(createKBModel.Urls, false);
         createKBRequest.files = new List <object>();
         string   kb           = JsonConvert.SerializeObject(createKBRequest);
         KBHelper kBHelper     = new KBHelper(_appSettings);
         var      headerValues = kBHelper.CreateKB(JsonConvert.SerializeObject(createKBRequest));
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }