Working on it

This commit is contained in:
Peer Schütt 2025-11-17 15:44:58 +01:00
parent ce04a17145
commit 01c48e14df
3 changed files with 38 additions and 21 deletions

View File

@ -25,7 +25,7 @@ else
<MudList T="DataDocumentAnalysisPolicy" Class="mb-1" SelectedValue="@this.selectedPolicy" SelectedValueChanged="@this.SelectedPolicyChanged"> <MudList T="DataDocumentAnalysisPolicy" Class="mb-1" SelectedValue="@this.selectedPolicy" SelectedValueChanged="@this.SelectedPolicyChanged">
@foreach (var policy in this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies) @foreach (var policy in this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies)
{ {
<MudListItem T="DataDocumentAnalysisPolicy" Icon="@Icons.Material.Filled.Settings" Value="@policy"> <MudListItem T="DataDocumentAnalysisPolicy" Icon="@Icons.Material.Filled.Policy" Value="@policy">
@policy.PolicyName @policy.PolicyName
</MudListItem> </MudListItem>
} }
@ -42,7 +42,7 @@ else
</MudStack> </MudStack>
<MudExpansionPanels Class="mb-3 mt-6" MultiExpansion="@false"> <MudExpansionPanels Class="mb-3 mt-6" MultiExpansion="@false">
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Settings" HeaderText="@T("Policy definition")" IsExpanded="@(!this.selectedPolicy?.IsProtected ?? true)"> <ExpansionPanel HeaderIcon="@Icons.Material.Filled.Policy" HeaderText="@T("Policy definition")" IsExpanded="@(!this.selectedPolicy?.IsProtected ?? true)">
<MudText Typo="Typo.h4" Class="mb-1"> <MudText Typo="Typo.h4" Class="mb-1">
@T("Common settings") @T("Common settings")
</MudText> </MudText>
@ -69,7 +69,7 @@ else
@T("Preparation for enterprise distribution") @T("Preparation for enterprise distribution")
</MudText> </MudText>
<MudButton StartIcon="@Icons.Material.Filled.FileDownload" Disabled="@this.IsNoPolicySelectedOrProtected" Variant="Variant.Filled" Color="Color.Primary"> <MudButton StartIcon="@Icons.Material.Filled.FileDownload" Disabled="@this.IsNoPolicySelectedOrProtected" Variant="Variant.Filled" Color="Color.Primary" OnClick="@this.ExportPolicyAsConfiguration">
@T("Export policy as configuration section") @T("Export policy as configuration section")
</MudButton> </MudButton>
@ -90,7 +90,7 @@ else
@T("Documents for the analysis") @T("Documents for the analysis")
</MudText> </MudText>
<AttachDocuments Name="Document Analysis Files Drop" @bind-DocumentPaths="@this.loadedDocumentPaths"/> <AttachDocuments Name="Document Analysis Files Drop" @bind-DocumentPaths="@this.loadedDocumentPaths" CatchAllDocuments="true"/>
</ExpansionPanel> </ExpansionPanel>

View File

@ -29,21 +29,21 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.Append("# Task description"); sb.Append("# Task description");
sb.Append(Environment.NewLine); sb.AppendLine();
if (this.loadedDocumentPaths.Count > 1) if (this.loadedDocumentPaths.Count > 1)
{ {
sb.Append($"Your task is to analyse {this.loadedDocumentPaths.Count} documents."); 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("Different Documents are divided by a horizontal rule in markdown formatting followed by the name of the document.");
sb.Append(Environment.NewLine); sb.AppendLine();
} }
else else
{ {
sb.Append("Your task is to analyse a single document."); sb.Append("Your task is to analyse a single document.");
sb.Append(Environment.NewLine); sb.AppendLine();
} }
var taskDescription = $""" var taskDescription = """
The analysis should be done using the policy analysis rules. The analysis should be done using the policy analysis rules.
The output should be formatted according to the policy output rules. The output should be formatted according to the policy output rules.
The rule sets should be followed strictly. The rule sets should be followed strictly.
@ -55,10 +55,9 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
"""; """;
sb.Append(taskDescription); sb.Append(taskDescription);
sb.Append(Environment.NewLine); sb.AppendLine();
sb.Append(this.PromptGetActivePolicy()); sb.Append(this.PromptGetActivePolicy());
sb.Append(Environment.NewLine);
return sb.ToString(); return sb.ToString();
} }
@ -304,20 +303,18 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
private async Task<string> PromptLoadDocumentsContent() private async Task<string> PromptLoadDocumentsContent()
{ {
if (this.loadedDocumentPaths.Count == 0) if (this.loadedDocumentPaths.Count == 0)
{
return string.Empty; return string.Empty;
}
var sb = new StringBuilder(); var sb = new StringBuilder();
var count = 1; var count = 1;
foreach(var documentPath in this.loadedDocumentPaths) foreach(var documentPath in this.loadedDocumentPaths)
{ {
sb.Append("---"); sb.Append("---");
sb.Append(Environment.NewLine); sb.AppendLine();
sb.Append($"Document {count} file path: {documentPath}"); sb.Append($"Document {count} file path: {documentPath}");
sb.Append(Environment.NewLine); sb.AppendLine();
sb.Append($"Document {count} content:"); sb.Append($"Document {count} content:");
sb.Append(Environment.NewLine); sb.AppendLine();
var fileContent = await this.RustService.ReadArbitraryFileData(documentPath, int.MaxValue); var fileContent = await this.RustService.ReadArbitraryFileData(documentPath, int.MaxValue);
sb.Append($""" sb.Append($"""
@ -325,8 +322,8 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
{fileContent} {fileContent}
``` ```
"""); """);
sb.Append(Environment.NewLine); sb.AppendLine();
sb.Append(Environment.NewLine); sb.AppendLine();
count += 1; count += 1;
} }
@ -335,8 +332,8 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
private async Task Analyze() private async Task Analyze()
{ {
if (this.IsNoPolicySelectedOrProtected) // if (this.IsNoPolicySelectedOrProtected)
return; // return;
await this.AutoSave(); await this.AutoSave();
await this.form!.Validate(); await this.form!.Validate();
@ -352,4 +349,18 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
await this.AddAIResponseAsync(userRequest); await this.AddAIResponseAsync(userRequest);
} }
private async Task ExportPolicyAsConfiguration()
{
return;
# warning Implement the export function
// do not allow the export of a protected policy
if (this.IsNoPolicySelectedOrProtected)
return;
await this.AutoSave();
await this.form!.Validate();
}
} }

View File

@ -19,6 +19,12 @@ public partial class AttachDocuments : MSGComponentBase
[Parameter] [Parameter]
public Func<HashSet<string>, Task> OnChange { get; set; } = _ => Task.CompletedTask; public Func<HashSet<string>, Task> OnChange { get; set; } = _ => Task.CompletedTask;
/// <summary>
/// Catch all documents that are hovered over the AI Studio window and not only over the drop zone.
/// </summary>
[Parameter]
public bool CatchAllDocuments { get; set; }
[Inject] [Inject]
private ILogger<AttachDocuments> Logger { get; set; } = null!; private ILogger<AttachDocuments> Logger { get; set; } = null!;
@ -38,7 +44,7 @@ public partial class AttachDocuments : MSGComponentBase
switch (triggeredEvent) switch (triggeredEvent)
{ {
case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.FILE_DROP_HOVERED }: case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.FILE_DROP_HOVERED }:
if(!this.isComponentHovered) if(!this.isComponentHovered && !this.CatchAllDocuments)
{ {
this.Logger.LogDebug("Attach documents component '{Name}' is not hovered, ignoring file drop hovered event.", this.Name); this.Logger.LogDebug("Attach documents component '{Name}' is not hovered, ignoring file drop hovered event.", this.Name);
return; return;
@ -49,7 +55,7 @@ public partial class AttachDocuments : MSGComponentBase
break; break;
case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.FILE_DROP_DROPPED, Payload: var paths }: case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.FILE_DROP_DROPPED, Payload: var paths }:
if(!this.isComponentHovered) if(!this.isComponentHovered && !this.CatchAllDocuments)
{ {
this.Logger.LogDebug("Attach documents component '{Name}' is not hovered, ignoring file drop dropped event.", this.Name); this.Logger.LogDebug("Attach documents component '{Name}' is not hovered, ignoring file drop dropped event.", this.Name);
return; return;