diff --git a/BeWo/ViewModel/ListViewModel/AiPromptbausteinTreeListVM.cs b/BeWo/ViewModel/ListViewModel/AiPromptbausteinTreeListVM.cs index f61f0b632..698b1f8a7 100644 --- a/BeWo/ViewModel/ListViewModel/AiPromptbausteinTreeListVM.cs +++ b/BeWo/ViewModel/ListViewModel/AiPromptbausteinTreeListVM.cs @@ -39,9 +39,12 @@ namespace BeWo.ViewModel.ListViewModel #region Designer private void InitDesigner() { - var prompts = new PredefinedAiPromptbausteine(); + var prompts = PredefinedAiPromptbausteine.GenerateDesignerInstance(); - VMList.Add(new AiPromptbausteinTreeVM(prompts.Zeiterfassung)); + foreach (var vm in prompts) + { + VMList.Add(new AiPromptbausteinTreeVM(vm)); + } } #endregion } diff --git a/Service/Core/AiPromptbausteinTreeBuilder.cs b/Service/Core/AiPromptbausteinTreeBuilder.cs new file mode 100644 index 000000000..b98e9669f --- /dev/null +++ b/Service/Core/AiPromptbausteinTreeBuilder.cs @@ -0,0 +1,54 @@ +using BS.Shared; +using BS.Shared.DataContracts.Feature.AI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service.Core +{ + public static class AiPromptbausteinTreeBuilder + { + public static IEnumerable GenerateTree(IEnumerable sub_roots) + { + var zeiterfassung = GetNodeByActionType(AiActionType.ServiceRecord); + zeiterfassung.Children.Add(GenerateSubtree(AiActionType.ServiceRecordConversation, sub_roots)); + zeiterfassung.Children.Add(GenerateSubtree(AiActionType.ServiceRecordDocumentation, sub_roots)); + + return new AiPromptbausteinTreeDC[] { zeiterfassung }; + } + + private static AiPromptbausteinTreeDC GenerateSubtree(AiActionType actionType, IEnumerable sub_roots) + { + var node = GetNodeByActionType(actionType); + + foreach (var sub_root in sub_roots) + { + if(sub_root.AiActionType == actionType) + { + node.Children.Add(sub_root); + } + } + + return node; + } + + private static AiPromptbausteinTreeDC GetNodeByActionType(AiActionType aiActionType) + { + switch (aiActionType) + { + case AiActionType.ServiceRecord: + return PredefinedAiPromptbausteine.CreateZeiterfassungRoot(); + case AiActionType.ServiceRecordConversation: + return PredefinedAiPromptbausteine.CreateZeiterfassungConversationNode(); + case AiActionType.ServiceRecordDocumentation: + return PredefinedAiPromptbausteine.CreateZeiterfassungDokuNode(); + default: + break; + } + + throw new NotImplementedException(); + } + } +} diff --git a/Service/DCEntityMapper/AiPromptbausteinTreeDC_AiPromptbausteinTree.cs b/Service/DCEntityMapper/AiPromptbausteinTreeDC_AiPromptbausteinTree.cs index 9ea88c3a1..bd6d43ef3 100644 --- a/Service/DCEntityMapper/AiPromptbausteinTreeDC_AiPromptbausteinTree.cs +++ b/Service/DCEntityMapper/AiPromptbausteinTreeDC_AiPromptbausteinTree.cs @@ -54,7 +54,8 @@ namespace BeWo.Service.DCEntityMapper pEntity.ShowUserPromptByTenant = pDataContract.ShowUserPromptByTenant; pEntity.Position = pDataContract.Position; //pEntity.IsExpanded = pDataContract.IsExpanded; - pEntity.ParentOid = pDataContract.ParentOid; + if(pDataContract.ParentOid >= 0) + pEntity.ParentOid = pDataContract.ParentOid; MapperFactory.AiPromptbausteinTreeTree.MergeWithEntitys(pDataContract.Children, pEntity.Children); diff --git a/Service/Plugins/AiFunctionService.cs b/Service/Plugins/AiFunctionService.cs index edaa6900d..42f32a8d5 100644 --- a/Service/Plugins/AiFunctionService.cs +++ b/Service/Plugins/AiFunctionService.cs @@ -16,6 +16,7 @@ using System.Text; using System.Threading.Tasks; using AICore.Prompt.SystemPrompts; using BeWo.Service.Core; +using BS.Shared.Extensions.CustomInterfaces; namespace BeWo.Service.Plugins { @@ -36,16 +37,24 @@ namespace BeWo.Service.Plugins var factory = new AiFunctionSystemPromptBuilder(systemPromptFolderPath); var system_prompt = factory.CreateServiceRecordDocumentationSystemPrompt(context); - var user_prompt = request.AiPromptbaustein; - var user_prompt_oid = user_prompt.Oid; - var user_prompt_ver = user_prompt.Version; + var prompt_baustein_ref = request.AiPromptbaustein; + var prompt_baustein_ref_oid = prompt_baustein_ref.Oid; + var prompt_baustein_ref_ver = prompt_baustein_ref.Version; - var predefined = new PredefinedAiPromptbausteine(); - var prompts = predefined.GetAllPromptbausteine(); - var prompt = prompts.First(x => x.Oid == user_prompt_oid).Content; + var prompt_baustein = DAOFactory.GenericDAO.LoadByID(prompt_baustein_ref_oid); + ServiceLogic.ConcurrencyCheck(prompt_baustein_ref_ver, prompt_baustein); + + if (prompt_baustein.IsOrdner()) + throw new Exception("prompt is folder"); + + if (prompt_baustein.IsKette()) + throw new NotImplementedException(); + + if (prompt_baustein.Oid < 0) + throw new NotImplementedException(); // Anfrage abschicken - var result = getResult(system_prompt, prompt); + var result = getResult(system_prompt, prompt_baustein.Content); // Response auswerten diff --git a/Service/Plugins/AiPromptbausteineService.cs b/Service/Plugins/AiPromptbausteineService.cs index 0ca19dc96..ba16e30cf 100644 --- a/Service/Plugins/AiPromptbausteineService.cs +++ b/Service/Plugins/AiPromptbausteineService.cs @@ -23,12 +23,11 @@ namespace BeWo.Service.Plugins public IEnumerable GetAiPromptbausteineTree() { - var roots = DAOFactory.SearchDAO.GetActiveRootAiPromptbausteine(); - var dcs = MapperFactory.AiPromptbausteinTreeTree.MapToNewDCs(roots); - return dcs; + var sub_roots = DAOFactory.SearchDAO.GetActiveRootAiPromptbausteine(); + var sub_roots_dcs = MapperFactory.AiPromptbausteinTreeTree.MapToNewDCs(sub_roots); + var roots = AiPromptbausteinTreeBuilder.GenerateTree(sub_roots_dcs); - var predefined = new PredefinedAiPromptbausteine(); - return predefined.GetFullPromptbausteineTree(); + return roots; } public IEnumerable CreateAiPromptbausteineTree(IEnumerable aiPromptbausteinDCs) diff --git a/Service/Service.csproj b/Service/Service.csproj index 3b2ff555b..351ee8333 100644 --- a/Service/Service.csproj +++ b/Service/Service.csproj @@ -224,6 +224,7 @@ + diff --git a/Shared/DataContracts/Feature/AI/AiPromptbausteinTreeDC.cs b/Shared/DataContracts/Feature/AI/AiPromptbausteinTreeDC.cs index c77117c13..a07647b76 100644 --- a/Shared/DataContracts/Feature/AI/AiPromptbausteinTreeDC.cs +++ b/Shared/DataContracts/Feature/AI/AiPromptbausteinTreeDC.cs @@ -27,111 +27,57 @@ namespace BS.Shared.DataContracts.Feature.AI } - public class PredefinedAiPromptbausteine + public static class PredefinedAiPromptbausteine { - public AiPromptbausteinTreeDC Zeiterfassung { get; set; } - public AiPromptbausteinTreeDC Zeiterfassung_Doku { get; set; } - public AiPromptbausteinTreeDC Zeiterfassung_Doku_1 { get; set; } - public AiPromptbausteinTreeDC Zeiterfassung_Doku_2 { get; set; } - public AiPromptbausteinTreeDC Zeiterfassung_Conversation { get; set; } - public AiPromptbausteinTreeDC Zeiterfassung_Conversation_1 { get; set; } - public AiPromptbausteinTreeDC Zeiterfassung_Conversation_2 { get; set; } - - public PredefinedAiPromptbausteine() + public static IEnumerable GenerateDesignerInstance() { - Zeiterfassung_Conversation_1 = new AiPromptbausteinTreeDC() - { - Oid = 7, - Version = 1, - Displayname = "Problemzusammenfassung", - AiActionType = AiActionType.ServiceRecordConversation, - Content = "Nenne mir die 3 größten Probleme des Klienten" - }; + var zeiterfassung = CreateZeiterfassungRoot(); + zeiterfassung.Children.Add(CreateZeiterfassungDokuNode()); + zeiterfassung.Children.Add(CreateZeiterfassungConversationNode()); + return new AiPromptbausteinTreeDC[] { zeiterfassung }; + } - Zeiterfassung_Conversation_2 = new AiPromptbausteinTreeDC() + public static AiPromptbausteinTreeDC CreateZeiterfassungRoot() + { + return new AiPromptbausteinTreeDC() { - Oid = 6, - Version = 1, - Displayname = "Zielezusammenfassung", - AiActionType = AiActionType.ServiceRecordConversation, - Content = "Fasse mir alle erreichten Ziele des Klienten zusammen" - }; - - Zeiterfassung_Doku_1 = new AiPromptbausteinTreeDC() - { - Oid = 5, - Version = 1, - Displayname = "Vollständiger Text", - AiActionType = AiActionType.ServiceRecordDocumentation, - Content = "Erstelle aus dem vorliegenden Text einen fließenden Text." - }; - - Zeiterfassung_Doku_2 = new AiPromptbausteinTreeDC() - { - Oid = 4, - Version = 1, - Displayname = "Stichpunkte", - AiActionType = AiActionType.ServiceRecordDocumentation, - Content = "Übersetze den vorliegenden Text in Stichpunkte" - }; - - Zeiterfassung_Conversation = new AiPromptbausteinTreeDC() - { - Oid = 3, - Version = 1, - Displayname = "Konversation", - Content = "Kategorie der Zeiterfassung->Konversation", - AiActionType = AiActionType.ServiceRecordConversation, - PromptbausteinType = AiPromptbausteinType.Ordner, - Children = new List - { - Zeiterfassung_Conversation_1, - Zeiterfassung_Conversation_2 - } - }; - - Zeiterfassung_Doku = new AiPromptbausteinTreeDC() - { - Oid = 2, - Version = 1, - Displayname = "Dokumentation", - Content = "Kategorie der Zeiterfassung->Dokumentation", - AiActionType = AiActionType.ServiceRecordDocumentation, - PromptbausteinType = AiPromptbausteinType.Ordner, - Children = new List - { - Zeiterfassung_Doku_1, - Zeiterfassung_Doku_2 - } - }; - - Zeiterfassung = new AiPromptbausteinTreeDC() - { - Oid = 1, + Oid = -1, Version = 1, Displayname = "Zeiterfassung", - Content = "Kategorie der Zeiterfassung", + Content = "Zeiterfassung", AiActionType = AiActionType.ServiceRecord, PromptbausteinType = AiPromptbausteinType.Ordner, + Children = new List() + }; + } + + public static AiPromptbausteinTreeDC CreateZeiterfassungDokuNode() + { + return new AiPromptbausteinTreeDC() + { + Oid = -3, + Version = 1, + Displayname = "Dokumentation", + Content = "Zeiterfassung->Dokumentation", + AiActionType = AiActionType.ServiceRecordDocumentation, + PromptbausteinType = AiPromptbausteinType.Ordner, Children = new List { - Zeiterfassung_Doku, - Zeiterfassung_Conversation, } }; } - public IEnumerable GetFullPromptbausteineTree() + public static AiPromptbausteinTreeDC CreateZeiterfassungConversationNode() { - return new List { Zeiterfassung }; - } - - public IEnumerable GetAllPromptbausteine() - { - return new List() + return new AiPromptbausteinTreeDC() { - Zeiterfassung, Zeiterfassung_Conversation, Zeiterfassung_Conversation_1, Zeiterfassung_Conversation_2, - Zeiterfassung_Doku, Zeiterfassung_Doku_1, Zeiterfassung_Doku_2 + Oid = -2, + Version = 1, + Displayname = "Konversation", + Content = "Zeiterfassung->Konversation", + AiActionType = AiActionType.ServiceRecordConversation, + PromptbausteinType = AiPromptbausteinType.Ordner, + Children = new List() }; } }