Skip to content

Commit c182642

Browse files
Refactored configuration objects (#538)
1 parent be11efe commit c182642

31 files changed

+718
-467
lines changed

app/MindWork AI Studio/Agents/AgentBase.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public abstract class AgentBase(ILogger<AgentBase> logger, SettingsManager setti
5454

5555
#region Implementation of IAgent
5656

57-
public abstract AIStudio.Settings.Provider? ProviderSettings { get; set; }
57+
public abstract AIStudio.Settings.Provider ProviderSettings { get; set; }
5858

5959
public abstract Task<ChatThread> ProcessContext(ChatThread chatThread, IDictionary<string, string> additionalData);
6060

@@ -103,10 +103,9 @@ protected UserRequest AddUserRequest(ChatThread thread, string request)
103103

104104
protected async Task AddAIResponseAsync(ChatThread thread, IContent lastUserPrompt, DateTimeOffset time)
105105
{
106-
if(this.ProviderSettings is null)
106+
if(this.ProviderSettings == Settings.Provider.NONE)
107107
return;
108108

109-
var providerSettings = this.ProviderSettings.Value;
110109
var aiText = new ContentText
111110
{
112111
// We have to wait for the remote
@@ -127,6 +126,6 @@ protected async Task AddAIResponseAsync(ChatThread thread, IContent lastUserProm
127126
// Use the selected provider to get the AI response.
128127
// By awaiting this line, we wait for the entire
129128
// content to be streamed.
130-
await aiText.CreateFromProviderAsync(providerSettings.CreateProvider(this.Logger), providerSettings.Model, lastUserPrompt, thread);
129+
await aiText.CreateFromProviderAsync(this.ProviderSettings.CreateProvider(this.Logger), this.ProviderSettings.Model, lastUserPrompt, thread);
131130
}
132131
}

app/MindWork AI Studio/Agents/AgentDataSourceSelection.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected override string SystemPrompt(string availableDataSources) => $"""
8686
""";
8787

8888
/// <inheritdoc />
89-
public override Settings.Provider? ProviderSettings { get; set; }
89+
public override Settings.Provider ProviderSettings { get; set; } = Settings.Provider.NONE;
9090

9191
/// <summary>
9292
/// The data source selection agent does not work with context. Use
@@ -141,6 +141,11 @@ public async Task<List<SelectedDataSource>> PerformSelectionAsync(IProvider prov
141141

142142
// We start with the provider currently selected by the user:
143143
var agentProvider = this.SettingsManager.GetPreselectedProvider(Tools.Components.AGENT_DATA_SOURCE_SELECTION, provider.Id, true);
144+
if (agentProvider == Settings.Provider.NONE)
145+
{
146+
logger.LogWarning("No provider is selected for the agent. The agent cannot select data sources.");
147+
return [];
148+
}
144149

145150
// Assign the provider settings to the agent:
146151
logger.LogInformation($"The agent for the data source selection uses the provider '{agentProvider.InstanceName}' ({agentProvider.UsedLLMProvider.ToName()}, confidence={agentProvider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level.GetName()}).");

app/MindWork AI Studio/Agents/AgentRetrievalContextValidation.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override string SystemPrompt(string retrievalContext) => $"""
7171
""";
7272

7373
/// <inheritdoc />
74-
public override Settings.Provider? ProviderSettings { get; set; }
74+
public override Settings.Provider ProviderSettings { get; set; } = Settings.Provider.NONE;
7575

7676
/// <summary>
7777
/// The retrieval context validation agent does not work with context. Use
@@ -133,6 +133,11 @@ public void SetLLMProvider(IProvider provider)
133133
{
134134
// We start with the provider currently selected by the user:
135135
var agentProvider = this.SettingsManager.GetPreselectedProvider(Tools.Components.AGENT_RETRIEVAL_CONTEXT_VALIDATION, provider.Id, true);
136+
if (agentProvider == Settings.Provider.NONE)
137+
{
138+
logger.LogWarning("No provider is selected for the agent.");
139+
return;
140+
}
136141

137142
// Assign the provider settings to the agent:
138143
logger.LogInformation($"The agent for the retrieval context validation uses the provider '{agentProvider.InstanceName}' ({agentProvider.UsedLLMProvider.ToName()}, confidence={agentProvider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level.GetName()}).");

app/MindWork AI Studio/Agents/AgentTextContentCleaner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public sealed class AgentTextContentCleaner(ILogger<AgentBase> logger, SettingsM
1111

1212
#region Overrides of AgentBase
1313

14-
public override AIStudio.Settings.Provider? ProviderSettings { get; set; }
14+
public override AIStudio.Settings.Provider ProviderSettings { get; set; } = AIStudio.Settings.Provider.NONE;
1515

1616
protected override Type Type => Type.SYSTEM;
1717

app/MindWork AI Studio/Agents/IAgent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IAgent
1212
/// <summary>
1313
/// The provider to use for this agent.
1414
/// </summary>
15-
public AIStudio.Settings.Provider? ProviderSettings { get; set; }
15+
public Settings.Provider ProviderSettings { get; set; }
1616

1717
/// <summary>
1818
/// Processes a chat thread (i.e., context) and returns the updated thread.

app/MindWork AI Studio/Assistants/AssistantBase.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
8585

8686
protected virtual IReadOnlyList<IButtonData> FooterButtons => [];
8787

88-
protected AIStudio.Settings.Provider providerSettings;
88+
protected AIStudio.Settings.Provider providerSettings = Settings.Provider.NONE;
8989
protected MudForm? form;
9090
protected bool inputIsValid;
9191
protected Profile currentProfile = Profile.NO_PROFILE;
@@ -352,7 +352,7 @@ protected Task SendToAssistant(Tools.Components destination, SendToButton sendTo
352352
private async Task InnerResetForm()
353353
{
354354
this.resultingContentBlock = null;
355-
this.providerSettings = default;
355+
this.providerSettings = Settings.Provider.NONE;
356356

357357
await this.JsRuntime.ClearDiv(RESULT_DIV_ID);
358358
await this.JsRuntime.ClearDiv(AFTER_RESULT_DIV_ID);

app/MindWork AI Studio/Assistants/I18N/allTexts.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,11 +5440,14 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::PLUGINSYSTEM::PLUGINCATEGORYEXTENSIONS::T91464
54405440
-- The SETTINGS table does not exist or is not a valid table.
54415441
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PLUGINSYSTEM::PLUGINCONFIGURATION::T1148682011"] = "The SETTINGS table does not exist or is not a valid table."
54425442

5443+
-- At least one configured LLM provider is not valid or could not be parsed, or the LLM_PROVIDERS table does not exist.
5444+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PLUGINSYSTEM::PLUGINCONFIGURATION::T3262676428"] = "At least one configured LLM provider is not valid or could not be parsed, or the LLM_PROVIDERS table does not exist."
5445+
54435446
-- The CONFIG table does not exist or is not a valid table.
54445447
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PLUGINSYSTEM::PLUGINCONFIGURATION::T3331620576"] = "The CONFIG table does not exist or is not a valid table."
54455448

5446-
-- The LLM_PROVIDERS table does not exist or is not a valid table.
5447-
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PLUGINSYSTEM::PLUGINCONFIGURATION::T806592324"] = "The LLM_PROVIDERS table does not exist or is not a valid table."
5449+
-- At least one configured chat template is not valid or could not be parsed, or the CHAT_TEMPLATES table does not exist.
5450+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PLUGINSYSTEM::PLUGINCONFIGURATION::T445358428"] = "At least one configured chat template is not valid or could not be parsed, or the CHAT_TEMPLATES table does not exist."
54485451

54495452
-- The field IETF_TAG does not exist or is not a valid string.
54505453
UI_TEXT_CONTENT["AISTUDIO::TOOLS::PLUGINSYSTEM::PLUGINLANGUAGE::T1796010240"] = "The field IETF_TAG does not exist or is not a valid string."

app/MindWork AI Studio/Components/ChatComponent.razor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
1818

1919
[Parameter]
2020
public EventCallback<ChatThread?> ChatThreadChanged { get; set; }
21-
21+
2222
[Parameter]
23-
public AIStudio.Settings.Provider Provider { get; set; }
23+
public AIStudio.Settings.Provider Provider { get; set; } = AIStudio.Settings.Provider.NONE;
2424

2525
[Parameter]
2626
public EventCallback<AIStudio.Settings.Provider> ProviderChanged { get; set; }
@@ -634,7 +634,7 @@ private async Task StartNewChat(bool useSameWorkspace = false, bool deletePrevio
634634

635635
default:
636636
case AddChatProviderBehavior.ADDED_CHATS_USE_LATEST_PROVIDER:
637-
if(this.Provider == default)
637+
if(this.Provider == AIStudio.Settings.Provider.NONE)
638638
{
639639
this.Provider = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
640640
await this.ProviderChanged.InvokeAsync(this.Provider);
@@ -797,7 +797,7 @@ private async Task SelectProviderWhenLoadingChat()
797797
break;
798798

799799
case LoadingChatProviderBehavior.ALWAYS_USE_LATEST_CHAT_PROVIDER:
800-
if(this.Provider == default)
800+
if(this.Provider == AIStudio.Settings.Provider.NONE)
801801
this.Provider = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
802802
break;
803803
}

app/MindWork AI Studio/Components/ConfigurationProviderSelection.razor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ private IEnumerable<ConfigurationSelectData<string>> FilteredData()
4242
foreach (var providerId in this.Data)
4343
{
4444
var provider = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == providerId.Value);
45+
if (provider is null)
46+
continue;
47+
4548
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
4649
yield return providerId;
4750
}

app/MindWork AI Studio/Components/ProviderSelection.razor.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public partial class ProviderSelection : MSGComponentBase
1111
{
1212
[CascadingParameter]
1313
public AssistantBase<NoComponent>? AssistantBase { get; set; }
14-
14+
1515
[Parameter]
16-
public AIStudio.Settings.Provider ProviderSettings { get; set; }
16+
public AIStudio.Settings.Provider ProviderSettings { get; set; } = AIStudio.Settings.Provider.NONE;
1717

1818
[Parameter]
1919
public EventCallback<AIStudio.Settings.Provider> ProviderSettingsChanged { get; set; }
@@ -32,7 +32,8 @@ private async Task SelectionChanged(AIStudio.Settings.Provider provider)
3232
{
3333
var minimumLevel = this.SettingsManager.GetMinimumConfidenceLevel(this.AssistantBase?.Component ?? Tools.Components.NONE);
3434
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
35-
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
36-
yield return provider;
35+
if (provider.UsedLLMProvider != LLMProviders.NONE)
36+
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
37+
yield return provider;
3738
}
3839
}

0 commit comments

Comments
 (0)