/// <summary> /// Initializes a new instance of the <see cref="PersonalityChat"/> class. /// </summary> /// <param name="pipeline">The pipeline to add the component to.</param> /// <param name="configuration">The configuration parameters.</param> public PersonalityChat(Pipeline pipeline, PersonalityChatConfiguration configuration) : base(pipeline) { this.configuration = configuration; var personalityChatOptions = new PersonalityChatOptions(configuration.PersonalityChatSubscriptionID, PersonalityChatPersona.Professional); this.personalityChatService = new PersonalityChatService(personalityChatOptions); }
public async Task InitialUserQuery(IDialogContext context, IAwaitable <IMessageActivity> argument) { var response = await argument; await context.SendTypingAcitivity(); context.PrivateConversationData.SetValue(StateConstants.Topic, response.Text); var rk = LuisFetcher.GetAnswers(response.Text.ToString()).Result; await context.SendTypingAcitivity(); var selectedIntent = topOnCallTopics.FirstOrDefault(cc => cc.Equals(rk.TopScoringIntent.IntentIntent) && rk.TopScoringIntent.Score > Constants.MaxLUIScore); context.PrivateConversationData.SetValue(StateConstants.IntentQuery, response.Text); if (selectedIntent != null) { context.PrivateConversationData.SetValue(StateConstants.Intent, selectedIntent); var re = context.MakeMessage(); re.Text = "BElow are some of the related topics"; var qnAResults = QnAMaker.QnAFetchter.GetAnswers("#System get #" + selectedIntent + " bot synonyms").Result; await context.SendTypingAcitivity(); ResultCard resultCard = new ResultCard(); resultCard.CustomQnACard(re, qnAResults); await context.PostAsync(re); context.Wait(HandleBotSynonyms); } else if (selectedIntent == null && rk.TopScoringIntent.IntentIntent.Equals("greeting") && rk.TopScoringIntent.Score > Constants.MaxLUIScore) { PersonalityChatOptions personalityChatOptions = new PersonalityChatOptions(string.Empty, PersonalityChatPersona.Professional); PersonalityChatService personalityChatService = new PersonalityChatService(personalityChatOptions); var PersonalityChatResults = Task.FromResult <PersonalityChatResults>(await personalityChatService.QueryServiceAsync(rk.Query)); string botOutput = PersonalityChatResults?.Result.ScenarioList?.FirstOrDefault()?.Responses?.FirstOrDefault() ?? ""; if (!string.IsNullOrEmpty(botOutput)) { await context.PostAsync(botOutput); var reply = context.MakeMessage(); reply.Attachments = new List <Attachment>(); reply.Attachments.Add(ResultCard.ShowGreetingCard()); var k = QnAMaker.QnAFetchter.GetAnswers("Get Bot Options").Result; await context.PostAsync(reply); } else { await context.SendTypingAcitivity(); await this.HandleBotSynonyms(context, argument); } } else { response.Text = others; await this.HandleBotSynonyms(context, argument); } }
public async Task ExecutePersonalityChatTests() { string userQuery = "test query aswedff"; string expectedResponse = "test response"; PersonalityChatOptions personalityChatOptions = new PersonalityChatOptions(); PersonalityChatService personalityChatService = new PersonalityChatService(personalityChatOptions, new HttpClient()); PersonalityChatResults personalityChatResults = await personalityChatService.QueryServiceAsync(userQuery); string topResponse = personalityChatResults?.ScenarioList?.FirstOrDefault()?.Responses?.FirstOrDefault(); Assert.AreEqual(expectedResponse, topResponse); }
static void Main(string[] args) { PersonalityChatOptions personalityChatOptions = new PersonalityChatOptions(string.Empty, PersonalityChatPersona.Professional); PersonalityChatService personalityChatService = new PersonalityChatService(personalityChatOptions); while (true) { Console.Write("User: "******"quit") { break; } var personalityChatResults = personalityChatService.QueryServiceAsync(userInput).Result; string botOutput = personalityChatResults?.ScenarioList?.FirstOrDefault()?.Responses?.FirstOrDefault() ?? ""; Console.WriteLine("Bot: " + botOutput); } }