Generischer AiSystemPromptBuilder

-> Mehr über SystmePrompt File steuerbar
This commit is contained in:
2026-06-24 10:47:29 +02:00
parent 6e5fa50871
commit 89154c0223
11 changed files with 249 additions and 103 deletions

View File

@@ -1,10 +1,5 @@
using DevExpress.Mvvm; using DevExpress.Mvvm;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace BeWo.ViewModel.View namespace BeWo.ViewModel.View
{ {

View File

@@ -9,3 +9,18 @@ Du bist ein hilfreicher Dokumentations-Assistent, der ausschließlich auf die be
- Antworte nur basierend auf dem Kontext. Wenn die Antwort nicht im Kontext zu finden ist, sage 'Ich weiß es nicht'. - Antworte nur basierend auf dem Kontext. Wenn die Antwort nicht im Kontext zu finden ist, sage 'Ich weiß es nicht'.
- Antworte nur mit Fakten und Daten aus dem Kontext. Unterlasse Spekulationen, Meinungen oder persönliche Erfahrungen. - Antworte nur mit Fakten und Daten aus dem Kontext. Unterlasse Spekulationen, Meinungen oder persönliche Erfahrungen.
- Übersetzungen sind erlaubt. - Übersetzungen sind erlaubt.
---
### **Allgemein**
- Aktuelle Zeit: {AktuelleZeit}
### **Ansicht**
- Ich befinde mich aktuell in der "{AktuellesModule}" meiner Anwendung.
- {FilterEinstellungen}
### **Daten**
{DatenBlock}
abs

View File

@@ -7,3 +7,16 @@ WICHTIG:
- Falls die Daten nicht die benötigte Information enthalten, gib an, dass die Daten fehlen, anstatt zu raten. - Falls die Daten nicht die benötigte Information enthalten, gib an, dass die Daten fehlen, anstatt zu raten.
- KEINE Erklärungen, KEIN Fließtext, KEINE zusätzlichen Notizen! - KEINE Erklärungen, KEIN Fließtext, KEINE zusätzlichen Notizen!
- Deine Antwort soll eine direkte und verständliche Antwort für den Nutzer sein. - Deine Antwort soll eine direkte und verständliche Antwort für den Nutzer sein.
---
### **Allgemein**
- Aktuelle Zeit: {AktuelleZeit}
### **Ansicht**
- Ich befinde mich aktuell in der "{AktuellesModule}" meiner Anwendung.
- {FilterEinstellungen}
### **Daten**
{DatenBlock}

View File

@@ -125,6 +125,7 @@
<Compile Include="Prompt\SystemPrompts\AiFunctionSystemPromptBuilder.cs" /> <Compile Include="Prompt\SystemPrompts\AiFunctionSystemPromptBuilder.cs" />
<Compile Include="Prompt\SystemPrompts\AiConversationSystemPromptBuilder.cs" /> <Compile Include="Prompt\SystemPrompts\AiConversationSystemPromptBuilder.cs" />
<Compile Include="Prompt\Models\AiConversationContext.cs" /> <Compile Include="Prompt\Models\AiConversationContext.cs" />
<Compile Include="Prompt\SystemPrompts\AiGenericSystemPromptBuilder.cs" />
<Compile Include="Prompt\SystemPrompts\BaseSystemPromptBuilder.cs" /> <Compile Include="Prompt\SystemPrompts\BaseSystemPromptBuilder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>

View File

@@ -1,6 +1,7 @@
using AICore.Context.Summary; using AICore.Context.Summary;
using AICore.Prompt.SystemPrompts; using AICore.Prompt.SystemPrompts;
using BS.Shared; using BS.Shared;
using BS.Shared.DataContracts.Feature.AI;
using BS.Shared.Exceptions; using BS.Shared.Exceptions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -13,25 +14,27 @@ namespace AICore.Prompt
{ {
public class AiSystemPromptFactory public class AiSystemPromptFactory
{ {
public static string BuildContext(AiActionType actionType, string prompt_path, BaseContextSummary context, AiDataContextType context_type) public static string BuildContext(AiActionType actionType, string prompt_path, AiViewContextDC view_context, BaseContextSummary context, AiDataContextType context_type)
{ {
switch (actionType) switch (actionType)
{ {
case AiActionType.ServiceRecord: case AiActionType.ServiceRecord:
break; break;
case AiActionType.ServiceRecordConversation: case AiActionType.ServiceRecordConversation:
var factory = new AiConversationSystemPromptBuilder(prompt_path);
var prompt = factory.CreateSystemPrompt(actionType, context, context_type);
return prompt;
case AiActionType.ServiceRecordDocumentation: case AiActionType.ServiceRecordDocumentation:
var factory2 = new AiFunctionSystemPromptBuilder(prompt_path); return BuildGenericContext(actionType, prompt_path, view_context, context, context_type);
var prompt2 = factory2.CreateServiceRecordDocumentationSystemPrompt(context);
return prompt2;
default: default:
break; break;
} }
throw BeWoNotImplementedException.CreateFromEnum(actionType); throw BeWoNotImplementedException.CreateFromEnum(actionType);
} }
public static string BuildGenericContext(AiActionType actionType, string prompt_path, AiViewContextDC view_context, BaseContextSummary context, AiDataContextType context_type)
{
var factory = new AiGenericSystemPromptBuilder(prompt_path);
return factory.CreateSystemPrompt(actionType, view_context, context, context_type);
}
} }
} }

View File

@@ -2,6 +2,7 @@
using AICore.Context.SummaryParser; using AICore.Context.SummaryParser;
using BS.Shared; using BS.Shared;
using BS.Shared.Core; using BS.Shared.Core;
using BS.Shared.DataContracts.Feature.AI;
using BS.Shared.Exceptions; using BS.Shared.Exceptions;
using BS.Shared.Translation; using BS.Shared.Translation;
using System; using System;
@@ -14,66 +15,74 @@ using System.Text.Json;
namespace AICore.Prompt.SystemPrompts namespace AICore.Prompt.SystemPrompts
{ {
internal class AiConversationSystemPromptBuilder : BaseSystemPromptBuilder //internal class AiConversationSystemPromptBuilder : BaseSystemPromptBuilder
{ //{
public AiConversationSystemPromptBuilder(string prompt_path) : base(prompt_path) { // public AiConversationSystemPromptBuilder(string prompt_path) : base(prompt_path) {
} // }
public string CreateSystemPrompt(AiActionType actionType, BaseContextSummary context, AiDataContextType aiDataContextType) // public string CreateSystemPrompt(AiActionType actionType, AiViewContextDC view_context, BaseContextSummary context, AiDataContextType aiDataContextType)
{ // {
var sb = new StringBuilder(); // var currentDateTime = DateTime.Now;
// var moduleName = Translations[actionType];
// var filter = view_context.Filter is string filter_str
// ? $"Es ist folgender Filter gesetzt: {filter_str}"
// : "Es ist kein Filter gesetzt.";
sb.AppendLine(getCustomSystemPrompt()); // var context =
sb.AppendLine();
sb.AppendLine();
sb.AppendLine("---");
sb.AppendLine();
sb.AppendLine("### **Allgemein**");
sb.AppendLine($"- Aktuelle Zeit: {DateTime.Now}");
sb.AppendLine();
sb.AppendLine("### **Ansicht**");
sb.AppendLine($"- Ich befinde mich aktuell in der \"{Translations[actionType]}\" meiner Anwendung.");
sb.AppendLine($"- Es ist kein Filter gesetzt.");
sb.AppendLine();
sb.AppendLine("### **Daten**");
if (context?.Context is null) // var sb = new StringBuilder();
{
sb.AppendLine("Dir wurden keine Daten bereitgestellt.");
}
else
{
sb.AppendLine("Du erhälst folgende Daten:");
var parser = GetParser(aiDataContextType); // sb.AppendLine(getCustomSystemPrompt());
var parsed = parser.Parse(actionType, context); // sb.AppendLine();
// sb.AppendLine();
// sb.AppendLine("---");
// sb.AppendLine();
// sb.AppendLine("### **Allgemein**");
// sb.AppendLine($"- Aktuelle Zeit: {DateTime.Now}");
// sb.AppendLine();
// sb.AppendLine("### **Ansicht**");
// sb.AppendLine($"- Ich befinde mich aktuell in der \"{Translations[actionType]}\" meiner Anwendung.");
// sb.AppendLine();
// sb.AppendLine("### **Daten**");
sb.AppendLine(parsed); // if (context?.Context is null)
} // {
// sb.AppendLine("Dir wurden keine Daten bereitgestellt.");
// }
// else
// {
// sb.AppendLine("Du erhälst folgende Daten:");
return sb.ToString(); // var parser = GetParser(aiDataContextType);
} // var parsed = parser.Parse(actionType, context);
private BaseContextSummaryParser GetParser(AiDataContextType aiDataContextType) // sb.AppendLine(parsed);
{ // }
switch (aiDataContextType)
{
case AiDataContextType.json:
return new JsonContextSummaryParser();
case AiDataContextType.csv:
return new CsvContextSummaryParser();
case AiDataContextType.tsv:
return new CsvContextSummaryParser("\t");
case AiDataContextType.csv2:
return new CsvContextSummaryParser(";", true);
case AiDataContextType.tsv2:
return new CsvContextSummaryParser("\t", true);
default:
break;
}
throw BeWoNotImplementedException.CreateFromEnum(aiDataContextType); // return sb.ToString();
} // }
}
// private BaseContextSummaryParser GetParser(AiDataContextType aiDataContextType)
// {
// switch (aiDataContextType)
// {
// case AiDataContextType.json:
// return new JsonContextSummaryParser();
// case AiDataContextType.csv:
// return new CsvContextSummaryParser();
// case AiDataContextType.tsv:
// return new CsvContextSummaryParser("\t");
// case AiDataContextType.csv2:
// return new CsvContextSummaryParser(";", true);
// case AiDataContextType.tsv2:
// return new CsvContextSummaryParser("\t", true);
// default:
// break;
// }
// throw BeWoNotImplementedException.CreateFromEnum(aiDataContextType);
// }
//}
} }

View File

@@ -3,6 +3,7 @@ using AICore.Context.Summary.Function;
using AICore.Context.SummaryParser; using AICore.Context.SummaryParser;
using BS.Shared; using BS.Shared;
using BS.Shared.Core; using BS.Shared.Core;
using BS.Shared.DataContracts.Feature.AI;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -13,46 +14,53 @@ using System.Threading.Tasks;
namespace AICore.Prompt.SystemPrompts namespace AICore.Prompt.SystemPrompts
{ {
internal class AiFunctionSystemPromptBuilder : BaseSystemPromptBuilder //internal class AiFunctionSystemPromptBuilder : BaseSystemPromptBuilder
{ //{
public AiFunctionSystemPromptBuilder(string prompt_path) : base(prompt_path) // public AiFunctionSystemPromptBuilder(string prompt_path) : base(prompt_path)
{ // {
} // }
public string CreateServiceRecordDocumentationSystemPrompt(BaseContextSummary context) // public string CreateServiceRecordDocumentationSystemPrompt(AiViewContextDC view_context, BaseContextSummary context)
{ // {
var sb = new StringBuilder(); // var sb = new StringBuilder();
sb.AppendLine(getCustomSystemPrompt()); // sb.AppendLine(getCustomSystemPrompt());
sb.AppendLine(); // sb.AppendLine();
sb.AppendLine(); // sb.AppendLine();
sb.AppendLine("---"); // sb.AppendLine("---");
sb.AppendLine(); // sb.AppendLine();
sb.AppendLine("### **Allgemein**"); // sb.AppendLine("### **Allgemein**");
sb.AppendLine($"- Aktuelle Zeit: {DateTime.Now}"); // sb.AppendLine($"- Aktuelle Zeit: {DateTime.Now}");
sb.AppendLine(); // sb.AppendLine();
sb.AppendLine("### **Ansicht**"); // sb.AppendLine("### **Ansicht**");
sb.AppendLine($"- Ich befinde mich aktuell in der \"Zeiterfassung\" meiner Anwendung."); // sb.AppendLine($"- Ich befinde mich aktuell in der \"Zeiterfassung\" meiner Anwendung.");
sb.AppendLine($"- Es ist kein Filter gesetzt."); // if(view_context.Filter is string filter_str)
sb.AppendLine(); // {
sb.AppendLine("### **Daten**"); // sb.AppendLine($"- Es ist folgender Filter gesetzt: {filter_str}");
// }
// else
// {
// sb.AppendLine($"- Es ist kein Filter gesetzt.");
// }
// sb.AppendLine();
// sb.AppendLine("### **Daten**");
if (context?.Context is null) // if (context?.Context is null)
{ // {
sb.AppendLine("Dir wurden keine Daten bereitgestellt."); // sb.AppendLine("Dir wurden keine Daten bereitgestellt.");
} // }
else // else
{ // {
sb.AppendLine("Du erhälst folgende Daten:"); // sb.AppendLine("Du erhälst folgende Daten:");
var parser = new CsvContextSummaryParser(); // var parser = new CsvContextSummaryParser();
var parsed = parser.Parse(AiActionType.ServiceRecordDocumentation, context); // var parsed = parser.Parse(AiActionType.ServiceRecordDocumentation, context);
sb.AppendLine(parsed); // sb.AppendLine(parsed);
} // }
return sb.ToString(); // return sb.ToString();
} // }
} //}
} }

View File

@@ -0,0 +1,57 @@
using AICore.Context.Summary;
using AICore.Context.SummaryParser;
using BS.Shared.DataContracts.Feature.AI;
using BS.Shared.Exceptions;
using BS.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Remoting.Messaging;
namespace AICore.Prompt.SystemPrompts
{
internal class AiGenericSystemPromptBuilder : BaseSystemPromptBuilder
{
public AiGenericSystemPromptBuilder(string prompt_path) : base(prompt_path)
{
}
public string CreateSystemPrompt(AiActionType actionType, AiViewContextDC view_context, BaseContextSummary context, AiDataContextType aiDataContextType)
{
var replace_dict = new Dictionary<string, string>()
{
{"{AktuelleZeit}", DateTime.Now.ToString() },
{"{AktuellesModule}", Translations[actionType]},
{"{FilterEinstellungen}", getFilterString(view_context.Filter)},
{"{DatenBlock}", getContextBlock(actionType, context, aiDataContextType)}
};
return createSystemPrompt(replace_dict);
}
private string getFilterString(object filter)
{
if (filter is null)
return "Es ist kein Filter gesetzt.";
return $"Es ist folgender Filter gesetzt: {filter}";
}
private string getContextBlock(AiActionType actionType, BaseContextSummary context, AiDataContextType aiDataContextType)
{
if (context is null)
{
return "Dir wurden keine Daten bereitgestellt.";
}
var parser = getParser(aiDataContextType);
var parsed = parser.Parse(actionType, context);
return $"Du erhälst folgende Daten: {Environment.NewLine}"
+ parsed;
}
}
}

View File

@@ -1,4 +1,8 @@
using BS.Shared; using AICore.Context.Summary;
using AICore.Context.SummaryParser;
using BS.Shared;
using BS.Shared.DataContracts.Feature.AI;
using BS.Shared.Exceptions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -24,7 +28,45 @@ namespace AICore.Prompt.SystemPrompts
Path = path; Path = path;
} }
protected string getCustomSystemPrompt() protected string createSystemPrompt(Dictionary<string, string> replace_dict)
{
var sb = new StringBuilder();
sb.AppendLine(getCustomSystemPrompt());
foreach (var kvp in replace_dict)
{
var key = kvp.Key;
var value = kvp.Value;
sb.Replace(key, value);
}
return sb.ToString();
}
protected BaseContextSummaryParser getParser(AiDataContextType aiDataContextType)
{
switch (aiDataContextType)
{
case AiDataContextType.json:
return new JsonContextSummaryParser();
case AiDataContextType.csv:
return new CsvContextSummaryParser();
case AiDataContextType.tsv:
return new CsvContextSummaryParser("\t");
case AiDataContextType.csv2:
return new CsvContextSummaryParser(";", true);
case AiDataContextType.tsv2:
return new CsvContextSummaryParser("\t", true);
default:
break;
}
throw BeWoNotImplementedException.CreateFromEnum(aiDataContextType);
}
private string getCustomSystemPrompt()
{ {
var path = Path; var path = Path;
return File.ReadAllText(path); return File.ReadAllText(path);

View File

@@ -391,7 +391,7 @@ namespace BeWo.Service.Plugins
var context_loaded = AiContextLoader.LoadContext(actionType, view_context, prompt?.SamplesCount); var context_loaded = AiContextLoader.LoadContext(actionType, view_context, prompt?.SamplesCount);
var configPath = getPromptPath(actionType); var configPath = getPromptPath(actionType);
var system_prompt = AiSystemPromptFactory.BuildContext(actionType, configPath, context_loaded, context_Type); var system_prompt = AiSystemPromptFactory.BuildContext(actionType, configPath, view_context, context_loaded, context_Type);
var msg = new AiConversationMessage(); var msg = new AiConversationMessage();
msg.Message = system_prompt; msg.Message = system_prompt;

View File

@@ -16,6 +16,9 @@ namespace BS.Shared.DataContracts.Feature.AI
[DataMember] [DataMember]
public object Secondary { get; set; } public object Secondary { get; set; }
[DataMember]
public object Filter { get; set; }
[DataMember] [DataMember]
public Dictionary<TableID, long[]> References { get; set; } public Dictionary<TableID, long[]> References { get; set; }
} }