Erste Version der Prompts

This commit is contained in:
Peer Schütt 2025-11-14 13:43:03 +01:00
parent d1cdb47d81
commit 2f124b1c5e
3 changed files with 112 additions and 8 deletions

View File

@ -41,24 +41,28 @@ else
</MudButton>
</MudStack>
<hr style="width: 100%; border-width: 0.25ch;" class="mt-6"/>
<MudExpansionPanels Class="mb-3 mt-6" MultiExpansion="@false">
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Settings" HeaderText="@T("Definition")" IsExpanded="@(!this.selectedPolicy?.IsProtected ?? true)">
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Settings" HeaderText="@T("Policy definition")" IsExpanded="@(!this.selectedPolicy?.IsProtected ?? true)">
<MudText Typo="Typo.h4" Class="mb-1">
@T("Common settings")
</MudText>
<MudTextField T="string" Disabled="@this.IsNoPolicySelectedOrProtected" @bind-Text="@this.policyName" Validation="@this.ValidatePolicyName" Immediate="@true" Label="@T("Policy name")" HelperText="@T("Please give your policy a name that provides information about the intended purpose. The name will be displayed to users in AI Studio.")" Counter="60" MaxLength="60" Variant="Variant.Outlined" Margin="Margin.Normal" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3" OnKeyUp="() => this.PolicyNameWasChanged()"/>
<MudTextField T="string" Disabled="@this.IsNoPolicySelectedOrProtected" @bind-Text="@this.policyDescription" Validation="@this.ValidatePolicyDescription" Immediate="@true" Label="@T("Policy description")" HelperText="@T("Please provide a brief description of your policy. Describe or explain what your policy does. This description will be shown to users in AI Studio.")" Counter="512" MaxLength="512" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="3" AutoGrow="@true" MaxLines="6" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
<MudTextSwitch Disabled="@(this.IsNoPolicySelected || (this.selectedPolicy?.IsManaged ?? true))" Label="@T("Would you like to protect this policy so that you cannot accidentally edit or delete it?")" Value="@this.policyIsProtected" ValueChanged="async state => await this.PolicyProtectionWasChanged(state)" LabelOn="@T("Yes, protect this policy")" LabelOff="@T("No, the policy can be edited")" />
<MudText Typo="Typo.h4" Class="mt-6 mb-1">
@T("Input and output rules")
</MudText>
<MudTextField T="string" Disabled="@this.IsNoPolicySelectedOrProtected" @bind-Text="@this.policyAnalysisRules" Validation="@this.ValidateAnalysisRules" Immediate="@true" Label="@T("Analysis rules")" HelperText="@T("Please provide a description of your analysis rules. This rules will be used to instruct the AI on how to analyze the documents.")" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="5" AutoGrow="@true" MaxLines="26" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
<ReadFileContent Text="@T("Load analysis rules from document")" @bind-FileContent="@this.policyAnalysisRules"/>
<MudTextField T="string" Disabled="@this.IsNoPolicySelectedOrProtected" @bind-Text="@this.policyOutputRules" Validation="@this.ValidateOutputRules" Immediate="@true" Label="@T("Output rules")" HelperText="@T("Please provide a description of your output rules. This rules will be used to instruct the AI on how to format the output of the analysis.")" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="5" AutoGrow="@true" MaxLines="26" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
<ReadFileContent Text="@T("Load output rules from document")" @bind-FileContent="@this.policyOutputRules"/>
<MudText Typo="Typo.h4" Class="mt-6 mb-1">
@ -68,12 +72,16 @@ else
<MudButton StartIcon="@Icons.Material.Filled.FileDownload" Disabled="@this.IsNoPolicySelectedOrProtected" Variant="Variant.Filled" Color="Color.Primary">
@T("Export policy as configuration section")
</MudButton>
</ExpansionPanel>
<hr style="width: 100%; border-width: 0.25ch;" class="mt-6"/>
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.DocumentScanner" HeaderText="@(T("Document analysis") + $": {this.selectedPolicy?.PolicyName}")" IsExpanded="@(this.selectedPolicy?.IsProtected ?? false)">
<MudText Typo="Typo.h4" Class="mb-1">
@T("Description")
</MudText>
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
@this.selectedPolicy?.PolicyDescription
</MudJustifiedText>
@ -81,6 +89,11 @@ else
<MudText Typo="Typo.h4" Class="mb-1 mt-6">
@T("Documents for the analysis")
</MudText>
<AttachDocuments Name="Document Analysis Files Drop" @bind-DocumentPaths="@this.loadedDocumentPaths"/>
</ExpansionPanel>
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
</MudExpansionPanels>

View File

@ -27,7 +27,39 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
get
{
var sb = new StringBuilder();
#warning Add system prompt for document analysis
sb.Append("# Task description");
sb.Append(Environment.NewLine);
if (this.loadedDocumentPaths.Count > 1)
{
sb.Append($"Your task is to analyse {this.loadedDocumentPaths.Count} documents.");
sb.Append("Different Documents are divided by a horizontal rule in markdown formatting followed by the name of the document.");
sb.Append(Environment.NewLine);
}
else
{
sb.Append("Your task is to analyse a single document.");
sb.Append(Environment.NewLine);
}
var taskDescription = $"""
The analysis should be done using the policy analysis rules.
The output should be formatted according to the policy output rules.
The rule sets should be followed strictly.
Only use information given in the documents or in the policy.
Never add any information of your own to it.
Keep your answers precise, professional and factual.
Only answer with the correctly formatted analysis result and do not add any opening or closing remarks.
Answer in the language that is used by the policy or is stated in the output rules.
""";
sb.Append(taskDescription);
sb.Append(Environment.NewLine);
sb.Append(this.PromptGetActivePolicy());
sb.Append(Environment.NewLine);
return sb.ToString();
}
}
@ -249,6 +281,58 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
return null;
}
private string PromptGetActivePolicy()
{
return $"""
# Policy
The policy is defined as follows:
## Policy name
{this.policyName}
## Policy description
{this.policyDescription}
## Policy analysis rules
{this.policyAnalysisRules}
## Policy output rules
{this.policyOutputRules}
""";
}
private async Task<string> PromptLoadDocumentsContent()
{
if (this.loadedDocumentPaths.Count == 0)
{
return string.Empty;
}
var sb = new StringBuilder();
var count = 1;
foreach(var documentPath in this.loadedDocumentPaths)
{
sb.Append("---");
sb.Append(Environment.NewLine);
sb.Append($"Document {count} file path: {documentPath}");
sb.Append(Environment.NewLine);
sb.Append($"Document {count} content:");
sb.Append(Environment.NewLine);
var fileContent = await this.RustService.ReadArbitraryFileData(documentPath, int.MaxValue);
sb.Append($"""
```
{fileContent}
```
""");
sb.Append(Environment.NewLine);
sb.Append(Environment.NewLine);
count += 1;
}
return sb.ToString();
}
private async Task Analyze()
{
if (this.IsNoPolicySelectedOrProtected)
@ -259,6 +343,13 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
if (!this.inputIsValid)
return;
#warning Implement document analysis logic
this.CreateChatThread();
var userRequest = this.AddUserRequest(
$"""
{await this.PromptLoadDocumentsContent()}
""", hideContentFromUser:true);
await this.AddAIResponseAsync(userRequest);
}
}

View File

@ -418,12 +418,12 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::DOCUMENTANALYSIS::DOCUMENTANALYSISASSISTA
-- Load output rules from document
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::DOCUMENTANALYSIS::DOCUMENTANALYSISASSISTANT::T2168201568"] = "Load output rules from document"
-- Definition
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::DOCUMENTANALYSIS::DOCUMENTANALYSISASSISTANT::T222998208"] = "Definition"
-- The name of your policy must be between 6 and 60 characters long.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::DOCUMENTANALYSIS::DOCUMENTANALYSISASSISTANT::T2435013256"] = "The name of your policy must be between 6 and 60 characters long."
-- Policy definition
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::DOCUMENTANALYSIS::DOCUMENTANALYSISASSISTANT::T2491168104"] = "Policy definition"
-- Export policy as configuration section
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::DOCUMENTANALYSIS::DOCUMENTANALYSISASSISTANT::T2556564432"] = "Export policy as configuration section"