diff --git a/Data/Entities/AiPromptbausteinPrompt.cs b/Data/Entities/AiPromptbausteinPrompt.cs index fb7394a0d..c80786489 100644 --- a/Data/Entities/AiPromptbausteinPrompt.cs +++ b/Data/Entities/AiPromptbausteinPrompt.cs @@ -39,6 +39,8 @@ namespace BeWo.Data.Entities public virtual string PromptId { get; set; } + public virtual int SamplesCount { get; set; } + public virtual AiActionType ActionType { get; set; } public virtual IList UserFavorites { get; set;} = new List(); @@ -69,12 +71,13 @@ namespace BeWo.Data.Entities x.Description == ent.Description && x.OwnsoftRefLink == ent.OwnsoftRefLink && x.Prompt == ent.Prompt && - x.ActionType == ent.ActionType; + x.ActionType == ent.ActionType && + x.SamplesCount == ent.SamplesCount; } public int GetHashCode(AiPromptbausteinPrompt obj) { - return (obj.PromptId, obj.ActionType, obj.Title, obj.Description, obj.OwnsoftRefLink, obj.Prompt).GetHashCode(); + return (obj.PromptId, obj.ActionType, obj.Title, obj.Description, obj.OwnsoftRefLink, obj.Prompt, obj.SamplesCount).GetHashCode(); } } } diff --git a/Model/Changes_2026-02-10 AI Promptbausteinfolder finale.txt b/Model/Changes_2026-02-10 AI Promptbausteinfolder finale.txt index 563049374..5a989a4d8 100644 --- a/Model/Changes_2026-02-10 AI Promptbausteinfolder finale.txt +++ b/Model/Changes_2026-02-10 AI Promptbausteinfolder finale.txt @@ -96,4 +96,7 @@ CREATE TABLE `aipromptbausteinfolder2empshare` ( PRIMARY KEY (`AiPromptbausteinFolderOid`,`EmployeeOid`), CONSTRAINT `FK_AIPROMPTBAUSTEIN2EMPSHARE_AIFOLDER` FOREIGN KEY (`AiPromptbausteinFolderOid`) REFERENCES `aipromptbausteinfolder` (`Oid`), CONSTRAINT `FK_AIPROMPTBAUSTEIN2EMPSHARE_APPUSER` FOREIGN KEY (`EmployeeOid`) REFERENCES `employee` (`Oid`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +ALTER TABLE `aipromptbausteinprompt` +ADD COLUMN `SamplesCount` INT NOT NULL DEFAULT 0 AFTER `ActionType`; diff --git a/Service/Core/BeWoServerPathHelper.cs b/Service/Core/BeWoServerPathHelper.cs index abc256ef1..2acaca363 100644 --- a/Service/Core/BeWoServerPathHelper.cs +++ b/Service/Core/BeWoServerPathHelper.cs @@ -15,8 +15,6 @@ namespace BeWo.Service.Core /// public static string GetAiSystemPromptPath() => Path.Combine(getRoot(), "AI", "systemPrompts"); - public static string GetAiOwnsoftPromptPath() - => Path.Combine(getRoot(), "AI", "ownsoftPrompts"); public static string GetUniqueRequestLogFile() diff --git a/Service/Plugins/AiFunctionService.cs b/Service/Plugins/AiFunctionService.cs index 3d55c670c..f2459b4a9 100644 --- a/Service/Plugins/AiFunctionService.cs +++ b/Service/Plugins/AiFunctionService.cs @@ -36,27 +36,23 @@ namespace BeWo.Service.Plugins // DB Daten holen // DB Daten prüfen // Anfrage zusammensetzen - var context = AiFunctionContextLoader.LoadServiceRecordDocumentationContext(request); - - var systemPromptFolderPath = BeWoServerPathHelper.GetAiSystemPromptPath(); - var factory = new AiFunctionSystemPromptBuilder(systemPromptFolderPath); - var system_prompt = factory.CreateServiceRecordDocumentationSystemPrompt(context); var prompt_baustein_ref = request.AiPromptbausteinPrompt; var prompt_baustein_ref_oid = prompt_baustein_ref.Oid; var prompt_baustein_ref_ver = prompt_baustein_ref.Version; - IAiPromptbausteinPrompt prompt_baustein = null; - if(prompt_baustein_ref_oid > 0) - { - prompt_baustein = DAOFactory.GenericDAO.LoadByID(prompt_baustein_ref_oid); - ServiceLogic.ConcurrencyCheck(prompt_baustein_ref_ver, (AiPromptbausteinPrompt)prompt_baustein); - } - else - { - prompt_baustein = findOwnsoftPrompt(AiActionType.ServiceRecordDocumentation, prompt_baustein_ref.Oid); - } + if (prompt_baustein_ref_oid <= 0) + throw new BeWoNotImplementedException(); + var prompt_baustein = DAOFactory.GenericDAO.LoadByID(prompt_baustein_ref_oid); + ServiceLogic.ConcurrencyCheck(prompt_baustein_ref_ver, prompt_baustein); + + var context = AiFunctionContextLoader.LoadServiceRecordDocumentationContext(request, prompt_baustein.SamplesCount); + + var systemPromptFolderPath = BeWoServerPathHelper.GetAiSystemPromptPath(); + var factory = new AiFunctionSystemPromptBuilder(systemPromptFolderPath); + var system_prompt = factory.CreateServiceRecordDocumentationSystemPrompt(context); + // Anfrage abschicken var result = getResult(system_prompt, prompt_baustein.Prompt); @@ -121,48 +117,5 @@ namespace BeWo.Service.Plugins { //throw new NotImplementedException(); } - - - private AiPromptbausteinPromptDC findOwnsoftPrompt(AiActionType aiAction, long prompt_oid) - { - var root = getOwnsoftFolder(aiAction); - - return findOwnsoftPrompt_rec(root, prompt_oid); - } - - private AiPromptbausteinPromptDC findOwnsoftPrompt_rec(AiPromptbausteinFolderDC dc, long prompt_oid) - { - foreach (var subprompts in dc.SubPrompts) - { - if (subprompts.Oid == prompt_oid) - return subprompts; - } - - foreach (var subfolder in dc.SubFolders) - { - var search = findOwnsoftPrompt_rec(subfolder, prompt_oid); - - if (search != null) - return search; - } - - return null; - } - - private AiPromptbausteinFolderDC getOwnsoftFolder(AiActionType aiActionType) - { - var folder_path = BeWoServerPathHelper.GetAiOwnsoftPromptPath(); - var file_name = $"{aiActionType.ToString().ToLower()}.json"; - var file_path = Path.Combine(folder_path, file_name); - - if (!File.Exists(file_path)) - return null; - - var json = File.ReadAllText(file_path, Encoding.UTF8); - - var ownsoft_folder = JsonSerializer.Deserialize(json); - - return ownsoft_folder; - } } } diff --git a/Service/ServiceUtils/AiFunctionContextLoader.cs b/Service/ServiceUtils/AiFunctionContextLoader.cs index ea96198a3..f9a66cdbb 100644 --- a/Service/ServiceUtils/AiFunctionContextLoader.cs +++ b/Service/ServiceUtils/AiFunctionContextLoader.cs @@ -9,15 +9,23 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using AICore.Context.Core; +using BS.Shared.DataContracts; namespace BeWo.Service.ServiceUtils { public class AiFunctionContextLoader { - public static BaseContextSummary LoadServiceRecordDocumentationContext(AiFunctionDocRequest request) + public static BaseContextSummary LoadServiceRecordDocumentationContext(AiFunctionDocRequest request, int samplesCount) { - var srs = request.ServiceRecords; - var srs_loaded = DataContractLoader.LoadServiceRecordDCs(srs); + IEnumerable srs_loaded = null; + + if(samplesCount > 0) + { + var srs = request.ServiceRecords; + srs_loaded = DataContractLoader.LoadServiceRecordDCs(srs) + .OrderByDescending(x => x.Start) + .Take(samplesCount); + } var sc_ref = request.SupportConcept; var sc_loaded = DataContractLoader.LoadSupportConceptDC(sc_ref);