public static List <ILinkInfo> GetAllNeuralNodesLinks(LinkType[] ignore = null) { List <ILinkInfo> res = new List <ILinkInfo>(); var ignoreLink = (bool)ignore?.Contains(LinkType.NeuralLink); if (!ignoreLink) { res.AddRange(DbLinkCollection.Find(x => true).ToList()?.Select(x => x as ILinkInfo).ToList()); } var ignoreAction = (bool)ignore?.Contains(LinkType.ActionLink); if (!ignoreAction) { res.AddRange(DbActionCollection.Find(x => true).ToList()?.Select(x => x as ILinkInfo).ToList()); } var ignoreResources = (bool)ignore?.Contains(LinkType.NeuralResource); if (!ignoreResources) { res.AddRange(DbResourceCollection.Find(x => true).ToList()?.Select(x => x as ILinkInfo).ToList()); } return(res); }
private async void actionMenu_Clicked(object sender, ToolStripItemClickedEventArgs e) { var clicked = e.ClickedItem.AccessibilityObject.Name; { switch (clicked) { case MenuActionNew: { var resourceModel = await DbResourceCollection.InsertNew(new NeuralResourceModel() { Name = "New resource" }); treeViewNeuralresources.SelectedNode = AddNewNode(resourceModel); } break; case MenuActionDelete: { if (treeViewNeuralresources.SelectedNode != null) { await DbResourceCollection.RemoveOneById(treeViewNeuralresources.SelectedNode.Name); treeViewNeuralresources.SelectedNode.Remove(); ReFillData(); } } break; default: break; } } }
private async void lnkLabels_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (treeViewNeuralresources.SelectedNode != null) { var node = (NeuralResourceModel)treeViewNeuralresources.SelectedNode.Tag; var editor = new ListEditor("Neural resource label editor", node.Labels); var res = editor.ShowDialog(); if (res == DialogResult.OK) { node.Labels = editor.Result; await DbResourceCollection.ReplaceOneById(node._id, node); treeViewNeuralresources.SelectedNode.Tag = node; ReFillData(); } } }
private async void btnApply_Click(object sender, EventArgs e) { if (treeViewNeuralresources.SelectedNode != null) { var node = (NeuralResourceModel)treeViewNeuralresources.SelectedNode.Tag; node.Name = tbName.Text; node.Description = tbDescription.Text; node.QuestionTitle = tbQuestionTitle.Text; node.Title = tbTitle.Text; node.Location = tbLocation.Text; node.IsLocal = chkBxIsLocal.Checked; node.Type = (ResourceType)cbResourceType.SelectedValue; await DbResourceCollection.ReplaceOneById(node._id, node); await LoadData(treeViewNeuralresources.SelectedNode.Name); } }
public static async Task <List <ILinkInfo> > GetAllLinks(this LinkType type) { List <ILinkInfo> res = null; switch (type) { case LinkType.NeuralLink: res = (await DbLinkCollection.Find(x => true).ToListAsync()).Select(x => x as ILinkInfo).ToList(); break; case LinkType.ActionLink: res = (await DbActionCollection.Find(x => true).ToListAsync()).Select(x => x as ILinkInfo).ToList(); break; case LinkType.NeuralResource: res = (await DbResourceCollection.Find(x => true).ToListAsync()).Select(x => x as ILinkInfo).ToList(); break; default: break; } return(res); }
/// <summary> /// Handles resuest flow for action resource nodes. /// </summary> /// <param name="resource"></param> /// <param name="turnContext"></param> /// <param name="requestState"></param> /// <returns></returns> public static Activity BuildActionRespose(this NeuralActionModel actionModel, ITurnContext turnContext) { Activity activity = turnContext.Activity.CreateReply(actionModel.ApplyFormat(actionModel.Title)); List <NeuralResourceModel> resources = actionModel.Resources.Select(async resId => await DbResourceCollection.FindOneById(resId)).Select(task => task.Result).ToList(); activity.Attachments = resources.Select(res => { return(res.GetResourceAttachment()); }).ToList(); return(activity); }
/// <summary> /// Call this to create and feed test database /// </summary> /// <param name="botId"></param> /// <param name="dropDatabase"></param> /// <param name="profileName"></param> /// <returns></returns> public async static Task Feed(string botId, bool dropDatabase, string profileName = BotChatProfile.DefaultProfile) { #region Load Db from Code if (dropDatabase) { await MongoDbProvider.DropDatabase(); await DbBotCollection.InsertNewOrUpdate(new BotModel { _id = BotAlphaName, Configuration = new BotConfiguration { ActiveProfile = profileName, ChatProfiles = new List <BotChatProfile> { } } }); } await DbBotCollection.AddOrUpdateChatProfileById(BotAlphaName, new BotChatProfile { Name = profileName }); await DbBotCollection.SetActiveChatProfileById(BotAlphaName, profileName); await SyncChatProfile(); var superRootNode = await DbLinkCollection.InsertNew(new NeuralLinkModel { Name = "SuperRoot", Notes = new List <string> { "Welcome to philips chatbot mobile device assistant beta version!" }, NeuralExp = new DecisionExpression { QuestionTitle = "Choose the conversation mode:", Hint = $"Simple:simple,Advanced:{BotResourceKeyConstants.CommandAdvanceChat}", ExpressionTree = ExpressionBuilder.Build().EQ("simple") } }); //configure it as bot root node await DbBotCollection.SetRootNodeById(botId, superRootNode._id, profileName); var nodeSimpleChatMode = await DbLinkCollection.InsertChildById(superRootNode._id, new NeuralLinkModel { Name = "SimpleChatNode", Title = $"[{BotResourceKeyConstants.WhatIssue}]" }); //Link super root forward action to simple chat mode await DbLinkCollection.SetNeuralExpForwardLinkById(superRootNode._id, new ActionLink { Type = LinkType.NeuralLink, LinkId = nodeSimpleChatMode._id }); var nodeSound = await DbLinkCollection.InsertChildById(nodeSimpleChatMode._id, new NeuralLinkModel { Name = "Sound/Speaker", Title = $"[{BotResourceKeyConstants.SelectedIssue}]", Notes = new List <string> { $"[{BotResourceKeyConstants.WeHelpYou}]", $"[{BotResourceKeyConstants.WhatIssue}]" } }); #region sound var resourceMute = await DbResourceCollection.InsertNew(new NeuralResourceModel { Name = "NoSound", IsLocal = false, Type = ResourceType.Video, Location = "https://www.youtube.com/watch?v=8Y8HzSBMujQ", Title = "How to fix sound problem on any android" }); var actionMute = await DbActionCollection.InsertNew(new NeuralActionModel { Name = "NoSoundAction", Title = $"[{BotResourceKeyConstants.FoundSolution}]", Resources = new List <string> { $"{resourceMute._id}" } }); var resourceUnpleasantSound = await DbResourceCollection.InsertNew(new NeuralResourceModel { Name = "UnpleasantSound0", IsLocal = false, Type = ResourceType.Video, Location = "https://www.youtube.com/watch?v=Y_hEEEt-Rb0", Title = "[Solution] Mobile speaker producing noisy (crackling) sound fixed without replacing speaker" }); var resourceUnpleasantSound1 = await DbResourceCollection.InsertNew(new NeuralResourceModel { Name = "UnpleasantSound1", IsLocal = false, Type = ResourceType.ImageJPG, Location = "https://1.bp.blogspot.com/-74qhJFnbScQ/Xme-O_OkPnI/AAAAAAAADmw/v3iLjmTSBVYoRWH6HVenl5WYrddv2rd2QCLcBGAsYHQ/s320/Samsung%2BGT-E1207T%2BEar%2BSpeaker%2BJumpur%2BSolution.jpg", Title = "[Solution] Mobile speaker producing noisy (crackling) sound fixed without replacing speaker" }); var actionUnpleasantSound = await DbActionCollection.InsertNew(new NeuralActionModel { Name = "UnpleasantSoundAction", Title = $"[{BotResourceKeyConstants.FoundSolution}]", Resources = new List <string> { resourceUnpleasantSound._id, resourceUnpleasantSound1._id } }); var resourceCustomerSupport = await DbResourceCollection.InsertNew(new NeuralResourceModel { Name = "customersupport ", IsLocal = false, Type = ResourceType.WebsiteUrl, Location = "https://www.philips.co.in/c-w/support-home/support-contact-page.html", Title = "Please reach us @support site" }); var actionCustomerSupport = await DbActionCollection.InsertNew(new NeuralActionModel { Name = "customersupportAction", Title = $"[{BotResourceKeyConstants.FoundSolution}]", Resources = new List <string> { resourceCustomerSupport._id } }); var nodeNoSound = await DbLinkCollection.InsertChildById(nodeSound._id, new NeuralLinkModel { Name = "No sound", Title = "You have selected {Name} category issues!", Notes = new List <string> { $"This might help you fixing it!" }, NeuralExp = new DecisionExpression { SkipEvaluation = true, ForwardAction = new ActionLink { Type = LinkType.ActionLink, LinkId = actionMute._id } } }); var nodeUnpleasantSound = await DbLinkCollection.InsertChildById(nodeSound._id, new NeuralLinkModel { Name = "Unpleasant sound", Title = $"[{BotResourceKeyConstants.SelectedIssue}]", NeuralExp = new DecisionExpression { Hint = "Yes:yes,No:no", QuestionTitle = "Did your device fall?", ExpressionTree = ExpressionBuilder.Build().EQ("yes"), ForwardAction = new ActionLink { Type = LinkType.ActionLink, LinkId = actionUnpleasantSound._id }, FallbackAction = new ActionLink { Type = LinkType.ActionLink, LinkId = actionCustomerSupport._id } } });; #endregion var nodeDisplay = await DbLinkCollection.InsertChildById(nodeSimpleChatMode._id, new NeuralLinkModel { Name = "Display/Broken screen", Title = $"[{BotResourceKeyConstants.SelectedIssue}]", Notes = new List <string> { $"[{BotResourceKeyConstants.WeHelpYou}]", $"[{BotResourceKeyConstants.WhatIssue}]" } }); #region display #endregion var nodeBattery = await DbLinkCollection.InsertChildById(nodeSimpleChatMode._id, new NeuralLinkModel { Name = "Battery/Charging", Title = $"[{BotResourceKeyConstants.SelectedIssue}]", Notes = new List <string> { $"[{BotResourceKeyConstants.WeHelpYou}]", $"[{BotResourceKeyConstants.WhatIssue}]" } }); //await DbLinkCollection.UnLinkParentChild(nodeSimpleChatMode._id, nodeBattery._id); #region battery #endregion #endregion #region resources var stringRes = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(BotResourceKeyConstants.ThankYou, "Thank you, Have a great day!"), new KeyValuePair <string, string>(BotResourceKeyConstants.WhatIssue, "What in the following do you need help with?"), new KeyValuePair <string, string>(BotResourceKeyConstants.SelectedIssue, "You have selected '{Name}' as your issue."), new KeyValuePair <string, string>(BotResourceKeyConstants.WeHelpYou, "Don't worry, we are here to help you."), new KeyValuePair <string, string>(BotResourceKeyConstants.CannotMoveBack, "Cannot move back, No history recorded yet."), new KeyValuePair <string, string>(BotResourceKeyConstants.Error, "Encountered an error while processing request, please contact bot administrator."), new KeyValuePair <string, string>(BotResourceKeyConstants.FoundSolution, "Here, we found few matching solutions"), new KeyValuePair <string, string>(BotResourceKeyConstants.InvalidInput, "Invalid input, please try again."), new KeyValuePair <string, string>(BotResourceKeyConstants.ThankYouFeedback, "Thanks for your feedback."), new KeyValuePair <string, string>(BotResourceKeyConstants.StartAgain, "Facing another issue?:start"), new KeyValuePair <string, string>(BotResourceKeyConstants.AdvanceChatQuery, "Tell us about your issue:"), new KeyValuePair <string, string>(BotResourceKeyConstants.NoMatchFound, "No match found, try again in different words."), new KeyValuePair <string, string>(BotResourceKeyConstants.Feedback, "Please help us improve our service, Was the solution helpful?"), new KeyValuePair <string, string>(BotResourceKeyConstants.FeedBackOptions, "Yes:yes,No:no,Exit:exit"), new KeyValuePair <string, string>(BotResourceKeyConstants.CommonActionOptions, "Back:back,Exit:exit") }; await DbBotCollection.AddStringResourceBatchById(botId, stringRes); #endregion #region ML model test data var speakerTrainModel = new NeuraTrainDataModel { _id = nodeSound._id, Dataset = new List <string> { "Speaker is not working", "Mobile sound issue", "No sound", "Unpleasant sound from speaker", "Cant hear sound", "Noisy music" } }; await DbTrainDataCollection.InsertNew(speakerTrainModel); var displayTrainModel = new NeuraTrainDataModel { _id = nodeDisplay._id, Dataset = new List <string> { "Display is not working", "Mobile display issue", "Broken screen", "Screen cracked", "Lines on display", "Issue with mobile display" } }; await DbTrainDataCollection.InsertNew(displayTrainModel); #endregion }
private async Task UpdateResourceLabelTextAsync() { lnkNeuralResources.Text = $"Neural resources ({ await DbResourceCollection.CountDocumentsAsync(new BsonDocument())})"; }
/// <summary> /// Handles resuest flow for action resource nodes. /// </summary> /// <param name="resource"></param> /// <param name="turnContext"></param> /// <param name="requestState"></param> /// <returns></returns> public static Activity BuildActionRespose(this NeuralActionModel actionModel, ITurnContext turnContext) { Activity activity = turnContext.Activity.CreateReply(actionModel.ApplyFormat(actionModel.Title)); List <NeuralResourceModel> resources = actionModel.Resources.Select(async resId => await DbResourceCollection.FindOneById(resId)).Select(task => task.Result).ToList(); activity.Attachments = resources.Select(res => { Attachment attachment = null; string curDir = Environment.CurrentDirectory; if (res.IsLocal) { res.Location = System.IO.Path.Combine(curDir, "resources", res.Location); } switch (res.Type) { case ResourceType.ImagePNG: case ResourceType.ImageJPG: case ResourceType.ImageGIF: { attachment = new HeroCard { Title = res.Title, Images = new List <CardImage> { new CardImage { Url = res.Location } } }.ToAttachment(); } break; case ResourceType.Audio: { var audioCard = new AudioCard(media: new[] { new MediaUrl(res.Location) }); audioCard.Title = res.Title; attachment = audioCard.ToAttachment(); } break; case ResourceType.Script: case ResourceType.DocumentPDF: case ResourceType.Text: case ResourceType.WebsiteUrl: case ResourceType.Json: { attachment = new HeroCard { Title = res.Title, Buttons = new List <CardAction> { new CardAction(ActionTypes.OpenUrl, title: $"Open {Enum.GetName(res.Type.GetType(), res.Type)}", value: res.Location) } }.ToAttachment(); } break; case ResourceType.Video: { var videoCard = new VideoCard(media: new[] { new MediaUrl(res.Location) }); videoCard.Title = res.Title; attachment = videoCard.ToAttachment(); } break; default: break; } return(attachment); }).ToList(); return(activity); }
private async Task <bool> EvaluateExpressionInput(ITurnContext turnContext, RequestState requestState) { var res = false; var text = turnContext.Activity.Text; var curLink = requestState.CurrentLink; ActionLink actionResult; ExpEvalResultType op = curLink.NeuralExp.Next(text, out actionResult); switch (op) { case ExpEvalResultType.Skipped: case ExpEvalResultType.False: case ExpEvalResultType.True: { if (op == ExpEvalResultType.Skipped) { await SendNotes(curLink, turnContext); } switch (actionResult.Type) { case LinkType.NeuralLink: { var link = await DbLinkCollection.FindOneById(actionResult.LinkId); if (link != null) { curLink = link; requestState.StepForward(curLink); await SendResponseForCurrentNode(turnContext, requestState); } else { //Invalid expression evaluation link id. await SendReply(turnContext, $"Invalid node information : '{actionResult.LinkId}',please report this issue to the bot administrator.", SuggestionExtension.GetCommonSuggestionActions()); } } break; case LinkType.ActionLink: { var action = await DbActionCollection.FindOneById(actionResult.LinkId); await turnContext.SendActivityAsync(action.BuildActionRespose(turnContext)); requestState.CurrentState = ChatStateType.RecordFeedback; } break; case LinkType.NeuralResource: { var resource = await DbResourceCollection.FindOneById(actionResult.LinkId); await turnContext.SendActivityAsync(resource.BuildResourceResponse(turnContext)); requestState.CurrentState = ChatStateType.RecordFeedback; } break; default: break; } if (requestState.CurrentState == ChatStateType.RecordFeedback) { await Task.Delay(1000).ContinueWith(async ct => { await SendReply(turnContext, StringsProvider.TryGet(BotResourceKeyConstants.Feedback), SuggestionExtension.GetFeedbackSuggestionActions()); }); } res = true; } break; case ExpEvalResultType.Exception: case ExpEvalResultType.Invalid: { await SendReply(turnContext, "Invalid input, please try again!", SuggestionExtension.GetCommonSuggestionActions("Exit:exit")); requestState.CurrentState = ChatStateType.InvalidInput; } break; case ExpEvalResultType.Empty: //TODO { await SendReply(turnContext, $"Evaluated empty expression of node : '{curLink._id}',please report this issue to the bot administrator.", SuggestionExtension.GetCommonSuggestionActions()); } break; default: break; } return(res); }