public System.Nullable <int> AskQuestion(string @string) { AskQuestionRequest inValue = new AskQuestionRequest(); inValue.@string = @string; AskQuestionResponse retVal = ((ISecuredService)(this)).AskQuestion(inValue); return(retVal.@int); }
private static async Task <string> ProcessQueryIntent(IDialogContext context, Activity activity, BotTask task, string query, string[] topics) { // Prepare the request to invoke a bot task within the bot brain AskQuestionRequest request = new AskQuestionRequest() { ConversationId = activity.Conversation.Id, Question = query, SessionId = DefaultSessionId, Topics = topics != null?topics.ToArray() : new string[0], UserId = string.IsNullOrEmpty(activity.From.Name) == false ? activity.From.Name : activity.From.Id }; // Invoke the bot task to process the request AskQuestionResponse askQuestionResponse = await HttpClientUtility.PostAsJsonAsync <AskQuestionResponse>(new Uri(BotBrainUrl + task.ToString()), RequestHeaders, request); // Handle the response returned from the bot task to be shown as cards depending on channel if (askQuestionResponse.Results?.Count() > 0 == true) { IMessageActivity foundMsg = context.MakeMessage(); AskQuestionResult result = askQuestionResponse.Results[0]; if (string.IsNullOrEmpty(result.Source) == false) { foundMsg.Text = string.Format("Got it. Meanwhile, from {0}:", result.Source); } else { foundMsg.Text = "Got it. Meanwhile, here's what I found:"; } await context.PostAsync(foundMsg); IMessageActivity cardMessage; string channelId = GetChannelId(activity); if (channelId == "directline" || channelId == "emulator") { cardMessage = GetAdaptiveCardMessage(context, request, result); } else { cardMessage = GetHeroCardMessage(context, request, result); } await context.PostAsync(cardMessage); } else { await PostAsync(context, activity, DoNotUnderstandPreMsg + " " + DoNotUnderstandMsg); } return("success"); }
public static async Task <AskQuestionResponse> AnswerQuestion(AskQuestionRequest request, ICollector <SessionTableEntity> sessionTable) { // Get unique identifier string id = Guid.NewGuid().ToString(); DateTime timestampUtc = DateTime.UtcNow; // Run keyphrases extraction request.Topics = await ServicesUtility.GetTopics(request.Question, request.Topics); // Run search services string queryWithTopics = request.Topics?.Count() > 0 ? string.Join(" ", request.Topics).Trim() : request.Question; // Process results AskQuestionResponse response = new AskQuestionResponse() { Id = id, Results = new AskQuestionResult[0] }; double confidenceScoreThreshold = 20; // Get results from QnA maker QnAMakerSearchResult qnaResult = await ServicesUtility.QnAMaker.GenerateAnswerAsync(queryWithTopics, SettingsUtility.QnAMakerWhoTaskKnowledgebaseId); if (qnaResult.Answers?.Where(a => a.Score >= confidenceScoreThreshold).Count() > 0) { response.Results = ServicesUtility.GetAskQuestionResults(qnaResult, confidenceScoreThreshold, true); } else { // Create Bing Search tasks BingWebSearchResult bingWebSearchResult = await ServicesUtility.BingSearch.SearchWebAsync(query : request.Question, count : SettingsUtility.MaxResultsCount); // Process Bing search results if (bingWebSearchResult.WebPagesResult?.Values?.Count() > 0) { response.Results = ServicesUtility.GetAskQuestionResults(bingWebSearchResult); } } // Write to session table sessionTable.Add(new SessionTableEntity(id, timestampUtc, "Who", request, response)); // Return response return(response); }
public static async Task <AskQuestionResponse> AnswerQuestion(AskQuestionRequest request, ICollector <SessionTableEntity> sessionTable) { // Get unique identifier string id = Guid.NewGuid().ToString(); DateTime timestampUtc = DateTime.UtcNow; // Get key phrases extraction request.Topics = await ServicesUtility.GetTopics(request.Question, request.Topics); string queryWithTopics = request.Topics?.Count() > 0 ? string.Join(" ", request.Topics).Trim() : request.Question; // Create video indexer task VideoIndexerSearchResult videoIndexerResult = await ServicesUtility.VideoIndexer.SearchAsync(query : queryWithTopics); // Process results AskQuestionResponse response = new AskQuestionResponse() { Id = id, Results = new AskQuestionResult[0] }; if (videoIndexerResult.Results?.Count() > 0) { response.Results = ServicesUtility.GetAskQuestionResults(videoIndexerResult); } else { // Create Bing Search tasks BingWebSearchResult bingWebSearchResult = await ServicesUtility.BingSearch.SearchWebAsync(query : request.Question, count : SettingsUtility.MaxResultsCount); // Process Bing search results if (bingWebSearchResult.WebPagesResult?.Values?.Count() > 0) { response.Results = ServicesUtility.GetAskQuestionResults(bingWebSearchResult); } } // Write to session table sessionTable.Add(new SessionTableEntity(id, timestampUtc, "LearnMore", request, response)); // Return response return(response); }
public static async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "AskWho")] HttpRequestMessage request, [Table("Session", Connection = "AzureWebJobsStorage")] ICollector <SessionTableEntity> sessionTable, TraceWriter log) { // Get content type MediaTypeHeaderValue contentType = request.Content.Headers.ContentType; // Check if content type is empty if (contentType == null) { return(request.CreateResponse(HttpStatusCode.BadRequest, "Missing content-type from header.")); } else if (contentType.MediaType.Contains("application/json") == false) { return(request.CreateErrorResponse(HttpStatusCode.UnsupportedMediaType, string.Format("Request's content type ({0}) is not supported.", string.Join(", ", contentType.MediaType)))); } // Read content from request AskQuestionRequest requestBody = await request.Content.ReadAsAsync <AskQuestionRequest>(); // Verify content contains valid values if (string.IsNullOrEmpty(requestBody.Question) == true) { return(request.CreateResponse(HttpStatusCode.BadRequest, "Question is missing from the request content.")); } else if (string.IsNullOrEmpty(requestBody.SessionId) == true) { return(request.CreateResponse(HttpStatusCode.BadRequest, "Session id is missing from the request content.")); } // Answer the question AskQuestionResponse response = await AnswerQuestion(requestBody, sessionTable); // Return request response with result and 200 OK return(request.CreateResponse(HttpStatusCode.OK, response)); }
public static async Task <AskQuestionResponse> AnswerQuestion(AskQuestionRequest request, ICollector <SessionTableEntity> sessionTable) { // Get unique identifier string id = Guid.NewGuid().ToString(); DateTime timestampUtc = DateTime.UtcNow; // Run keyphrases extraction request.Topics = await ServicesUtility.GetTopics(request.Question, request.Topics); // Run search services string queryWithTopics = request.Topics?.Count() > 0 ? string.Join(" ", request.Topics).Trim() : request.Question; // Create Bing Search task BingWebSearchResult bingWebSearchResult = await ServicesUtility.BingSearch.SearchWebAsync(query : request.Question, count : SettingsUtility.MaxResultsCount); // Process results AskQuestionResponse response = new AskQuestionResponse() { Id = id, Results = new AskQuestionResult[0] }; // Process Bing search results if (bingWebSearchResult.WebPagesResult?.Values?.Count() > 0) { response.Results = ServicesUtility.GetAskQuestionResults(bingWebSearchResult); } // Upload search document to dashboard await ServicesUtility.UploadDocumentToSearchService(SettingsUtility.AzureSearchIndexName, new SessionSearchDocument(id, timestampUtc, "AskQuestion", request, response)); // Write to session table sessionTable.Add(new SessionTableEntity(id, timestampUtc, "Question", request, response)); // Return response return(response); }
public SessionSearchDocument(string id, DateTime timestampUtc, string task, AskQuestionRequest request, AskQuestionResponse response) : base(id) { this.SessionId = request.SessionId; this.ConversationId = request.ConversationId; this.UserId = request.UserId; this.Question = request.Question; this.Task = task; this.Topics = request.Topics; this.TimestampUtc = timestampUtc; if (response.Results?.Count() > 0) { this.AnswerTitle = response.Results[0].Title; this.AnswerContent = response.Results[0].Answer; this.AnswerImageUrl = response.Results[0].ImageUrl; this.AnswerSource = response.Results[0].Source; this.AnswerUrl = response.Results[0].Url; this.AnswerUrlDisplayName = response.Results[0].UrlDisplayName; } this.IsAnswered = false; }
public SessionTableEntity(string id, DateTime timestampUtc, string questionType, AskQuestionRequest request, AskQuestionResponse response) { this.PartitionKey = request.SessionId; this.RowKey = id; this.ConversationId = request.ConversationId; this.UserId = request.UserId; this.Question = request.Question; this.QuestionType = questionType; this.Topics = request.Topics?.Count() > 0 ? string.Join(";", request.Topics) : string.Empty; this.Timestamp = timestampUtc; this.ResponseJson = JsonConvert.SerializeObject(response); }