Skip to content

Adding Providers can now be disabled in the plugin #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions app/MindWork AI Studio/Assistants/AssistantBase.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2 mr-3" StretchItems="StretchItems.Start">
<MudText Typo="Typo.h3">
@(this.Title)
@this.Title
</MudText>

<MudIconButton Variant="Variant.Text" Icon="@Icons.Material.Filled.Settings" OnClick="() => this.OpenSettingsDialog()"/>
<MudIconButton Variant="Variant.Text" Icon="@Icons.Material.Filled.Settings" OnClick="@(async () => await this.OpenSettingsDialog())"/>
</MudStack>

<InnerScrolling>
Expand All @@ -26,13 +26,13 @@
</CascadingValue>

<MudStack Row="true" AlignItems="AlignItems.Center" StretchItems="StretchItems.Start" Class="mb-3">
<MudButton Disabled="@this.SubmitDisabled" Variant="Variant.Filled" OnClick="async () => await this.Start()" Style="@this.SubmitButtonStyle">
<MudButton Disabled="@this.SubmitDisabled" Variant="Variant.Filled" OnClick="@(async () => await this.Start())" Style="@this.SubmitButtonStyle">
@this.SubmitText
</MudButton>
@if (this.isProcessing && this.cancellationTokenSource is not null)
{
<MudTooltip Text="@TB("Stop generation")">
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Filled.Stop" Color="Color.Error" OnClick="() => this.CancelStreaming()"/>
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Filled.Stop" Color="Color.Error" OnClick="@(async () => await this.CancelStreaming())"/>
</MudTooltip>
}
</MudStack>
Expand Down Expand Up @@ -80,7 +80,7 @@
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="@TB("Send to ...")" Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
@foreach (var assistant in Enum.GetValues<Components>().Where(n => n.AllowSendTo()).OrderBy(n => n.Name().Length))
{
<MudMenuItem OnClick="() => this.SendToAssistant(assistant, new())">
<MudMenuItem OnClick="@(async () => await this.SendToAssistant(assistant, new()))">
@assistant.Name()
</MudMenuItem>
}
Expand All @@ -94,14 +94,14 @@
{
case ButtonData buttonData when !string.IsNullOrWhiteSpace(buttonData.Tooltip):
<MudTooltip Text="@buttonData.Tooltip">
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" Disabled="@buttonData.DisabledAction()" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="async () => await buttonData.AsyncAction()">
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" Disabled="@buttonData.DisabledAction()" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="@(async () => await buttonData.AsyncAction())">
@buttonData.Text
</MudButton>
</MudTooltip>
break;

case ButtonData buttonData:
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" Disabled="@buttonData.DisabledAction()" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="async () => await buttonData.AsyncAction()">
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" Disabled="@buttonData.DisabledAction()" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="@(async () => await buttonData.AsyncAction())">
@buttonData.Text
</MudButton>
break;
Expand All @@ -110,7 +110,7 @@
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="@TB("Send to ...")" Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
@foreach (var assistant in Enum.GetValues<Components>().Where(n => n.AllowSendTo()).OrderBy(n => n.Name().Length))
{
<MudMenuItem OnClick="() => this.SendToAssistant(assistant, sendToButton)">
<MudMenuItem OnClick="@(async () => await this.SendToAssistant(assistant, sendToButton))">
@assistant.Name()
</MudMenuItem>
}
Expand All @@ -121,14 +121,14 @@

@if (this.ShowCopyResult)
{
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.ContentCopy" OnClick="() => this.CopyToClipboard()">
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.ContentCopy" OnClick="@(async () => await this.CopyToClipboard())">
@TB("Copy result")
</MudButton>
}

@if (this.ShowReset)
{
<MudButton Variant="Variant.Filled" Style="@this.GetResetColor()" StartIcon="@Icons.Material.Filled.Refresh" OnClick="() => this.InnerResetForm()">
<MudButton Variant="Variant.Filled" Style="@this.GetResetColor()" StartIcon="@Icons.Material.Filled.Refresh" OnClick="@(async () => await this.InnerResetForm())">
@TB("Reset")
</MudButton>
}
Expand Down
3 changes: 3 additions & 0 deletions app/MindWork AI Studio/Assistants/I18N/allTexts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIDENCEINFO::T3243388657"] = "Confiden
-- Shows and hides the confidence card with information about the selected LLM provider.
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIDENCEINFO::T847071819"] = "Shows and hides the confidence card with information about the selected LLM provider."

-- This feature is managed by your organization and has therefore been disabled.
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIGURATIONBASE::T1416426626"] = "This feature is managed by your organization and has therefore been disabled."

-- Choose the minimum confidence level that all LLM providers must meet. This way, you can ensure that only trustworthy providers are used. You cannot use any provider that falls below this level.
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIGURATIONMINCONFIDENCESELECTION::T2526727283"] = "Choose the minimum confidence level that all LLM providers must meet. This way, you can ensure that only trustworthy providers are used. You cannot use any provider that falls below this level."

Expand Down
24 changes: 23 additions & 1 deletion app/MindWork AI Studio/Components/ConfigurationBase.razor
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
@inherits MSGComponentBase
@inherits MSGComponentBase

@if (this.Body is not null)
{
@if (!this.Disabled() && this.IsLocked())
{
<MudField Label="@this.Label" Variant="@this.Variant" Underline="false" HelperText="@this.OptionHelp" Class="@this.Classes" InnerPadding="false">
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.FlexStart" Wrap="Wrap.NoWrap" StretchItems="this.StretchItems">
@* MudTooltip.RootStyle is set as a workaround for issue -> https://github.com/MudBlazor/MudBlazor/issues/10882 *@
<MudTooltip Text="@TB("This feature is managed by your organization and has therefore been disabled.")" Arrow="true" Placement="Placement.Right" RootStyle="display:inline-flex;">
<MudIcon Icon="@Icons.Material.Filled.Lock" Color="Color.Error" Size="Size.Small" Class="mr-1"/>
</MudTooltip>
@this.Body
</MudStack>
</MudField>
}
else
{
<MudField Label="@this.Label" Variant="@this.Variant" Underline="false" HelperText="@this.OptionHelp" Class="@this.Classes" InnerPadding="false">
@this.Body
</MudField>
}
}
43 changes: 40 additions & 3 deletions app/MindWork AI Studio/Components/ConfigurationBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace AIStudio.Components;
/// <summary>
/// A base class for configuration options.
/// </summary>
public partial class ConfigurationBase : MSGComponentBase
public abstract partial class ConfigurationBase : MSGComponentBase
{
/// <summary>
/// The description of the option, i.e., the name. Should be
Expand All @@ -26,7 +26,42 @@ public partial class ConfigurationBase : MSGComponentBase
[Parameter]
public Func<bool> Disabled { get; set; } = () => false;

protected const string MARGIN_CLASS = "mb-6";
/// <summary>
/// Is the option locked by a configuration plugin?
/// </summary>
[Parameter]
public Func<bool> IsLocked { get; set; } = () => false;

/// <summary>
/// Should the option be stretched to fill the available space?
/// </summary>
protected abstract bool Stretch { get; }

/// <summary>
/// The CSS class to apply to the component.
/// </summary>
protected virtual string GetClassForBase => string.Empty;

/// <summary>
/// The visual variant of the option.
/// </summary>
protected virtual Variant Variant => Variant.Text;

/// <summary>
/// The label to display for the option.
/// </summary>
protected virtual string Label => string.Empty;

private StretchItems StretchItems => this.Stretch ? StretchItems.End : StretchItems.None;

protected bool IsDisabled => this.Disabled() || this.IsLocked();

private string Classes => $"{this.GetClassForBase} {MARGIN_CLASS}";

private protected virtual RenderFragment? Body => null;

private const string MARGIN_CLASS = "mb-6";

protected static readonly Dictionary<string, object?> SPELLCHECK_ATTRIBUTES = new();

#region Overrides of ComponentBase
Expand All @@ -39,7 +74,9 @@ protected override async Task OnInitializedAsync()
}

#endregion


private string TB(string fallbackEN) => this.T(fallbackEN, typeof(ConfigurationBase).Namespace, nameof(ConfigurationBase));

protected async Task InformAboutChange() => await this.MessageBus.SendMessage<bool>(this, Event.CONFIGURATION_CHANGED);

#region Overrides of MSGComponentBase
Expand Down
15 changes: 15 additions & 0 deletions app/MindWork AI Studio/Components/ConfigurationBaseCore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace AIStudio.Components;

public abstract class ConfigurationBaseCore : ConfigurationBase
{
private protected sealed override RenderFragment Body => this.BuildRenderTree;

// Allow content to be provided by a .razor file but without
// overriding the content of the base class
protected new virtual void BuildRenderTree(RenderTreeBuilder builder)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@using AIStudio.Settings
@inherits MSGComponentBase
<ConfigurationSelect Disabled="@this.Disabled" OptionDescription="@T("Select a minimum confidence level")" SelectedValue="@this.FilteredSelectedValue" Data="@ConfigurationSelectDataFactory.GetConfidenceLevelsData(this.SettingsManager, this.RestrictToGlobalMinimumConfidence)" SelectionUpdate="@this.SelectionUpdate" OptionHelp="@T("Choose the minimum confidence level that all LLM providers must meet. This way, you can ensure that only trustworthy providers are used. You cannot use any provider that falls below this level.")"/>
<ConfigurationSelect IsLocked="this.IsLocked" Disabled="this.Disabled" OptionDescription="@T("Select a minimum confidence level")" SelectedValue="@this.FilteredSelectedValue" Data="@ConfigurationSelectDataFactory.GetConfidenceLevelsData(this.SettingsManager, this.RestrictToGlobalMinimumConfidence)" SelectionUpdate="@this.SelectionUpdate" OptionHelp="@T("Choose the minimum confidence level that all LLM providers must meet. This way, you can ensure that only trustworthy providers are used. You cannot use any provider that falls below this level.")"/>
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ public partial class ConfigurationMinConfidenceSelection : MSGComponentBase
[Parameter]
public Action<ConfidenceLevel> SelectionUpdate { get; set; } = _ => { };

/// <summary>
/// Is the selection component disabled?
/// </summary>
[Parameter]
public Func<bool> Disabled { get; set; } = () => false;

/// <summary>
/// Boolean value indicating whether the selection is restricted to a global minimum confidence level.
/// </summary>
[Parameter]
public bool RestrictToGlobalMinimumConfidence { get; set; }

[Parameter]
public Func<bool> Disabled { get; set; } = () => false;

[Parameter]
public Func<bool> IsLocked { get; set; } = () => false;

private ConfidenceLevel FilteredSelectedValue()
{
Expand Down
10 changes: 4 additions & 6 deletions app/MindWork AI Studio/Components/ConfigurationMultiSelect.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inherits ConfigurationBase
@inherits ConfigurationBaseCore
@typeparam TData

<MudSelectExtended
Expand All @@ -7,12 +7,10 @@
MultiSelectionTextFunc="@this.GetMultiSelectionText"
SelectedValues="@this.SelectedValues()"
Strict="@true"
Disabled="@this.Disabled()"
Disabled="@this.IsDisabled"
Margin="Margin.Dense"
Label="@this.OptionDescription"
Class="@GetClass"
Variant="Variant.Outlined"
HelperText="@this.OptionHelp"
Class="rounded-lg"
Underline="false"
SelectedValuesChanged="@this.OptionChanged">
@foreach (var data in this.Data)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AIStudio.Components;
/// Configuration component for selecting many values from a list.
/// </summary>
/// <typeparam name="TData">The type of the value to select.</typeparam>
public partial class ConfigurationMultiSelect<TData> : ConfigurationBase
public partial class ConfigurationMultiSelect<TData> : ConfigurationBaseCore
{
/// <summary>
/// The data to select from.
Expand All @@ -28,6 +28,17 @@ public partial class ConfigurationMultiSelect<TData> : ConfigurationBase
[Parameter]
public Action<HashSet<TData>> SelectionUpdate { get; set; } = _ => { };

#region Overrides of ConfigurationBase

/// <inheritdoc />
protected override bool Stretch => true;

protected override Variant Variant => Variant.Outlined;

protected override string Label => this.OptionDescription;

#endregion

private async Task OptionChanged(IEnumerable<TData?>? updatedValues)
{
if(updatedValues is null)
Expand All @@ -39,8 +50,6 @@ private async Task OptionChanged(IEnumerable<TData?>? updatedValues)
await this.InformAboutChange();
}

private static string GetClass => $"{MARGIN_CLASS} rounded-lg";

private string GetMultiSelectionText(List<TData?>? selectedValues)
{
if(selectedValues is null || selectedValues.Count == 0)
Expand Down
10 changes: 4 additions & 6 deletions app/MindWork AI Studio/Components/ConfigurationOption.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
@inherits ConfigurationBase
@inherits ConfigurationBaseCore

<MudField Disabled="@this.Disabled()" Label="@this.OptionDescription" Variant="Variant.Outlined" HelperText="@this.OptionHelp" Class="@MARGIN_CLASS">
<MudSwitch T="bool" Disabled="@this.Disabled()" Value="@this.State()" ValueChanged="@this.OptionChanged" Color="Color.Primary">
@(this.State() ? this.LabelOn : this.LabelOff)
</MudSwitch>
</MudField>
<MudSwitch T="bool" Disabled="@this.IsDisabled" Value="@this.State()" ValueChanged="@this.OptionChanged" Color="Color.Primary">
@(this.State() ? this.LabelOn : this.LabelOff)
</MudSwitch>
15 changes: 14 additions & 1 deletion app/MindWork AI Studio/Components/ConfigurationOption.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace AIStudio.Components;
/// <summary>
/// Configuration component for any boolean option.
/// </summary>
public partial class ConfigurationOption : ConfigurationBase
public partial class ConfigurationOption : ConfigurationBaseCore
{
/// <summary>
/// Text to display when the option is true.
Expand All @@ -31,6 +31,19 @@ public partial class ConfigurationOption : ConfigurationBase
[Parameter]
public Action<bool> StateUpdate { get; set; } = _ => { };

#region Overrides of ConfigurationBase

/// <inheritdoc />
protected override bool Stretch => true;

/// <inheritdoc />
protected override Variant Variant => Variant.Outlined;

/// <inheritdoc />
protected override string Label => this.OptionDescription;

#endregion

private async Task OptionChanged(bool updatedState)
{
this.StateUpdate(updatedState);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@inherits MSGComponentBase
<ConfigurationSelect OptionDescription="@T("Preselected provider")" Disabled="@this.Disabled" OptionHelp="@this.HelpText()" Data="@this.FilteredData()" SelectedValue="@this.SelectedValue" SelectionUpdate="@this.SelectionUpdate"/>
<ConfigurationSelect IsLocked="@this.IsLocked" OptionDescription="@T("Preselected provider")" Disabled="@(() => this.Disabled())" OptionHelp="@this.HelpText()" Data="@this.FilteredData()" SelectedValue="@this.SelectedValue" SelectionUpdate="@this.SelectionUpdate"/>
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,17 @@ public partial class ConfigurationProviderSelection : MSGComponentBase
[Parameter]
public IEnumerable<ConfigurationSelectData<string>> Data { get; set; } = new List<ConfigurationSelectData<string>>();

/// <summary>
/// Is the selection component disabled?
/// </summary>
[Parameter]
public Func<bool> Disabled { get; set; } = () => false;

[Parameter]
public Func<string> HelpText { get; set; } = () => TB("Select a provider that is preselected.");

[Parameter]
public Tools.Components Component { get; set; } = Tools.Components.NONE;

#region Overrides of ComponentBase

protected override async Task OnParametersSetAsync()
{
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
await base.OnParametersSetAsync();
}

#endregion

[Parameter]
public Func<bool> Disabled { get; set; } = () => false;

[Parameter]
public Func<bool> IsLocked { get; set; } = () => false;

[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
private IEnumerable<ConfigurationSelectData<string>> FilteredData()
Expand Down
6 changes: 3 additions & 3 deletions app/MindWork AI Studio/Components/ConfigurationSelect.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@inherits ConfigurationBase
@typeparam T
@inherits ConfigurationBaseCore
@typeparam TConfig

<MudSelect T="T" Value="@this.SelectedValue()" Strict="@true" ShrinkLabel="@true" Disabled="@this.Disabled()" Margin="Margin.Dense" Label="@this.OptionDescription" Class="@GetClass" Variant="Variant.Outlined" HelperText="@this.OptionHelp" ValueChanged="@this.OptionChanged">
<MudSelect T="TConfig" Value="@this.SelectedValue()" Strict="@true" ShrinkLabel="@true" Disabled="@this.IsDisabled" Margin="Margin.Dense" Class="rounded-lg mb-0" Underline="false" ValueChanged="@this.OptionChanged">
@foreach (var data in this.Data)
{
<MudSelectItem Value="@data.Value">
Expand Down
Loading