Add support for context materials in SWOT Analysis

This commit is contained in:
hart_s3 2026-09-03 14:25:02 +02:00
parent 4b04a3b2c8
commit f74f4030be
3 changed files with 53 additions and 17 deletions

View File

@ -2470,17 +2470,20 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T101
-- Create a SWOT analysis of my content
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T1113304215"] = "Create a SWOT analysis of my content"
-- Source material
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T1697755825"] = "Source material"
-- SWOT Analysis
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T1864542518"] = "SWOT Analysis"
-- Please describe the goal the SWOT analysis should support.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T2136978542"] = "Please describe the goal the SWOT analysis should support."
-- Target language
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T237828418"] = "Target language"
-- Describe the decision or question the SWOT analysis should support.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T2901719160"] = "Describe the decision or question the SWOT analysis should support."
-- Input
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T2677268763"] = "Input"
-- Analysis goal
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T2718020690"] = "Analysis goal"
-- Create SWOT analysis
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T3549988380"] = "Create SWOT analysis"
@ -2494,8 +2497,8 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T384
-- Specify topics the SWOT analysis should pay particular attention to.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T3857591121"] = "Specify topics the SWOT analysis should pay particular attention to."
-- (Optional) Analysis goal
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T4150922727"] = "(Optional) Analysis goal"
-- Analysis Goal
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T573440114"] = "Analysis Goal"
-- (Optional) Analysis focus
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T578386116"] = "(Optional) Analysis focus"
@ -2503,6 +2506,12 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T578
-- Please provide a custom language.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T656744944"] = "Please provide a custom language."
-- Subject of analysis
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T871926658"] = "Subject of analysis"
-- Background Knowledge
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SWOTANALYSIS::ASSISTANTSWOTANALYSIS::T986091845"] = "Background Knowledge"
-- Find synonyms for the following word or phrase:
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SYNONYM::ASSISTANTSYNONYMS::T1793532807"] = "Find synonyms for the following word or phrase:"

View File

@ -5,10 +5,25 @@
{
<ReadWebContent @bind-Content="@this.inputText" ProviderSettings="@this.ProviderSettings" @bind-AgentIsRunning="@this.isAgentRunning" @bind-Preselect="@this.showWebContentReader" @bind-PreselectContentCleanerAgent="@this.useContentCleanerAgent"/>
}
<MudText Typo="Typo.h5" Class="mb-3">
@T("Input")
</MudText>
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="@T("Subject of analysis")" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
<ReadFileContent @bind-FileContent="@this.inputText" EnableDragDrop="true" Layer="@DropLayers.ASSISTANTS" CatchAllDocuments="true"/>
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="@T("Source material")" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.analysisGoal" AdornmentIcon="@Icons.Material.Filled.TrackChanges" Adornment="Adornment.Start" Label="@T("(Optional) Analysis goal")" HelperText="@T("Describe the decision or question the SWOT analysis should support.")" Variant="Variant.Outlined" Lines="2" AutoGrow="@true" Class="mb-3"/>
<MudText Typo="Typo.h5" Class="mb-3 mt-6">
@T("Analysis Goal")
</MudText>
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.analysisGoal" Validation="@this.ValidatingAnalysisGoal" AdornmentIcon="@Icons.Material.Filled.TrackChanges" Adornment="Adornment.Start" Label="@T("Analysis goal")" Variant="Variant.Outlined" Lines="4" AutoGrow="@true" Class="mb-3"/>
<ReadFileContent @bind-FileContent="@this.analysisGoal" EnableDragDrop="true" Layer="@DropLayers.ASSISTANTS" CatchAllDocuments="true"/>
<MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.importantAspects" AdornmentIcon="@Icons.Material.Filled.List" Adornment="Adornment.Start" Label="@T("(Optional) Analysis focus")" HelperText="@T("Specify topics the SWOT analysis should pay particular attention to.")" Variant="Variant.Outlined" Lines="2" AutoGrow="@true" Class="mb-3"/>
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.Name())" @bind-Value="@this.selectedTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="@T("Target language")" AllowOther="@true" @bind-OtherInput="@this.customTargetLanguage" OtherValue="CommonLanguages.OTHER" LabelOther="@T("Custom target language")" ValidateOther="@this.ValidateCustomLanguage" />
<ProviderSelection @bind-ProviderSettings="@this.ProviderSettings" ValidateProvider="@this.ValidatingProvider"/>
<MudText Typo="Typo.h5" Class="mb-3 mt-6">
@T("Background Knowledge")
</MudText>
<AttachDocuments Name="SWOT Analysis Context Material" Layer="@DropLayers.ASSISTANTS" @bind-DocumentPaths="@this.contextMaterials" CatchAllDocuments="true" UseSmallForm="false" Provider="@this.ProviderSettings"/>
<div style="margin-top: 20px;">
<EnumSelection T="CommonLanguages" NameFunc="@(language => language.Name())" @bind-Value="@this.selectedTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="@T("Target language")" AllowOther="@true" @bind-OtherInput="@this.customTargetLanguage" OtherValue="CommonLanguages.OTHER" LabelOther="@T("Custom target language")" ValidateOther="@this.ValidateCustomLanguage" />
<ProviderSelection @bind-ProviderSettings="@this.ProviderSettings" ValidateProvider="@this.ValidatingProvider"/>
</div>

View File

@ -1,4 +1,5 @@
using AIStudio.Dialogs.Settings;
using AIStudio.Chat;
using AIStudio.Dialogs.Settings;
using AIStudio.Tools.AssistantSessions;
namespace AIStudio.Assistants.SWOTAnalysis;
@ -50,6 +51,7 @@ public partial class AssistantSWOTAnalysis : AssistantBaseCore<SettingsDialogSWO
{
this.inputText = string.Empty;
this.analysisGoal = string.Empty;
this.contextMaterials.Clear();
if (!this.MightPreselectValues())
{
this.showWebContentReader = false;
@ -80,6 +82,7 @@ public partial class AssistantSWOTAnalysis : AssistantBaseCore<SettingsDialogSWO
private string inputText = string.Empty;
private string analysisGoal = string.Empty;
private string importantAspects = string.Empty;
private HashSet<FileAttachment> contextMaterials = [];
private bool isAgentRunning;
private CommonLanguages selectedTargetLanguage = CommonLanguages.AS_IS;
private string customTargetLanguage = string.Empty;
@ -88,6 +91,7 @@ public partial class AssistantSWOTAnalysis : AssistantBaseCore<SettingsDialogSWO
private static readonly AssistantSessionStateKey<string> INPUT_TEXT_STATE_KEY = new(nameof(inputText));
private static readonly AssistantSessionStateKey<string> ANALYSIS_GOAL_STATE_KEY = new(nameof(analysisGoal));
private static readonly AssistantSessionStateKey<string> IMPORTANT_ASPECTS_STATE_KEY = new(nameof(importantAspects));
private static readonly AssistantSessionStateKey<HashSet<FileAttachment>> CONTEXT_MATERIALS_STATE_KEY = new(nameof(contextMaterials));
private static readonly AssistantSessionStateKey<bool> IS_AGENT_RUNNING_STATE_KEY = new(nameof(isAgentRunning));
private static readonly AssistantSessionStateKey<CommonLanguages> SELECTED_TARGET_LANGUAGE_STATE_KEY = new(nameof(selectedTargetLanguage));
private static readonly AssistantSessionStateKey<string> CUSTOM_TARGET_LANGUAGE_STATE_KEY = new(nameof(customTargetLanguage));
@ -100,6 +104,7 @@ public partial class AssistantSWOTAnalysis : AssistantBaseCore<SettingsDialogSWO
state.Set(INPUT_TEXT_STATE_KEY, this.inputText);
state.Set(ANALYSIS_GOAL_STATE_KEY, this.analysisGoal);
state.Set(IMPORTANT_ASPECTS_STATE_KEY, this.importantAspects);
state.SetHashSet(CONTEXT_MATERIALS_STATE_KEY, this.contextMaterials);
state.Set(IS_AGENT_RUNNING_STATE_KEY, this.isAgentRunning);
state.Set(SELECTED_TARGET_LANGUAGE_STATE_KEY, this.selectedTargetLanguage);
state.Set(CUSTOM_TARGET_LANGUAGE_STATE_KEY, this.customTargetLanguage);
@ -113,6 +118,7 @@ public partial class AssistantSWOTAnalysis : AssistantBaseCore<SettingsDialogSWO
state.Restore(INPUT_TEXT_STATE_KEY, value => this.inputText = value);
state.Restore(ANALYSIS_GOAL_STATE_KEY, value => this.analysisGoal = value);
state.Restore(IMPORTANT_ASPECTS_STATE_KEY, value => this.importantAspects = value);
state.RestoreHashSet(CONTEXT_MATERIALS_STATE_KEY, this.contextMaterials);
state.Restore(IS_AGENT_RUNNING_STATE_KEY, value => this.isAgentRunning = value);
state.Restore(SELECTED_TARGET_LANGUAGE_STATE_KEY, value => this.selectedTargetLanguage = value);
state.Restore(CUSTOM_TARGET_LANGUAGE_STATE_KEY, value => this.customTargetLanguage = value);
@ -139,6 +145,14 @@ public partial class AssistantSWOTAnalysis : AssistantBaseCore<SettingsDialogSWO
return null;
}
private string? ValidatingAnalysisGoal(string text)
{
if (string.IsNullOrWhiteSpace(text))
return T("Please describe the goal the SWOT analysis should support.");
return null;
}
private string? ValidateCustomLanguage(string language)
{
if (this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
@ -149,9 +163,7 @@ public partial class AssistantSWOTAnalysis : AssistantBaseCore<SettingsDialogSWO
private string BuildUserRequest()
{
var analysisGoal = string.IsNullOrWhiteSpace(this.analysisGoal)
? "No specific analysis goal was provided."
: $"Analysis goal: {this.analysisGoal}";
var analysisGoal = $"Analysis goal: {this.analysisGoal}";
var analysisFocus = string.IsNullOrWhiteSpace(this.importantAspects)
? "No additional analysis focus was provided."
: $"Analysis focus: {this.importantAspects}";
@ -175,7 +187,7 @@ public partial class AssistantSWOTAnalysis : AssistantBaseCore<SettingsDialogSWO
return;
this.CreateChatThread();
var time = this.AddUserRequest(this.BuildUserRequest(), hideContentFromUser: true);
var time = this.AddUserRequest(this.BuildUserRequest(), hideContentFromUser: true, this.contextMaterials.ToList());
await this.AddAIResponseAsync(time);
}