mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-05 01:07:21 +00:00
Improved adding local data sources without an embedding provider (#1084)
This commit is contained in:
1 parent
bca9e7ea89
commit
92fa0d08ef
20 files changed
+590
-154
No files matched your search
@@ -8,6 +8,8 @@
|
||||
@* A drop anywhere in this dialog belongs to the dialog, not to the page behind it: *@
|
||||
<PathDropZone IsArea="@true">
|
||||
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues" FieldChanged="@this.RevalidateAfterFieldChange">
|
||||
<DataSourceMissingEmbeddingWarning IsInDataSourceDialog="@true" EmbeddingProviderAdded="@this.SelectAddedEmbeddingProvider"/>
|
||||
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
T="string"
|
||||
@@ -102,17 +104,10 @@
|
||||
@T("In order for the AI to be able to determine the appropriate data at any time, you must choose an embedding provider.")
|
||||
</MudJustifiedText>
|
||||
<MudSelect @ref="@this.embeddingSelect" @bind-Value="@this.dataEmbeddingId" Label="@T("Embedding")" Class="mb-3" OpenIcon="@Icons.Material.Filled.ExpandMore" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.dataSourceValidation.ValidateEmbeddingProviderAccess">
|
||||
@foreach (var embedding in this.AvailableEmbeddings)
|
||||
@foreach (var provider in this.SettingsManager.GetAllEmbeddingProviders())
|
||||
{
|
||||
<MudSelectItem Value="@embedding.Value">
|
||||
@if (this.GetEmbeddingProvider(embedding.Value) is { } provider)
|
||||
{
|
||||
<ProviderLabel ProviderType="@provider.UsedLLMProvider" CustomIconDataUrl="@provider.CustomIconDataUrl" Text="@embedding.Name" />
|
||||
}
|
||||
else
|
||||
{
|
||||
@embedding.Name
|
||||
}
|
||||
<MudSelectItem Value="@provider.Id">
|
||||
<ProviderLabel ProviderType="@provider.UsedLLMProvider" CustomIconDataUrl="@provider.CustomIconDataUrl" Text="@provider.Name" />
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
@@ -33,9 +33,6 @@ public partial class DataSourceLocalDirectoryDialog : MSGComponentBase
|
||||
[Parameter]
|
||||
public bool LockSource { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public IReadOnlyList<ConfigurationSelectData<string>> AvailableEmbeddings { get; set; } = [];
|
||||
|
||||
[Inject]
|
||||
private IDialogService DialogService { get; init; } = null!;
|
||||
|
||||
@@ -134,6 +131,9 @@ public partial class DataSourceLocalDirectoryDialog : MSGComponentBase
|
||||
}
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
// The embedding providers may change while the dialog is open, e.g., through a configuration plugin:
|
||||
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
@@ -155,12 +155,25 @@ public partial class DataSourceLocalDirectoryDialog : MSGComponentBase
|
||||
|
||||
#endregion
|
||||
|
||||
private EmbeddingProvider? GetEmbeddingProvider(string providerId)
|
||||
#region Overrides of MSGComponentBase
|
||||
|
||||
protected override Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
|
||||
{
|
||||
var provider = this.SettingsManager.GetEmbeddingProviderById(providerId);
|
||||
return provider == EmbeddingProvider.NONE ? null : provider;
|
||||
switch (triggeredEvent)
|
||||
{
|
||||
case Event.CONFIGURATION_CHANGED:
|
||||
case Event.PLUGINS_RELOADED:
|
||||
// The embedding providers are listed anew, and the fields checked so far get a fresh verdict once they hold the new values:
|
||||
this.revalidateAfterRender = true;
|
||||
this.StateHasChanged();
|
||||
break;
|
||||
}
|
||||
|
||||
return base.ProcessIncomingMessage(sendingComponent, triggeredEvent, data);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
private EmbeddingProvider? SelectedEmbedding => this.SettingsManager.ConfigurationData.EmbeddingProviders
|
||||
.FirstOrDefault(x => x.Id == this.dataEmbeddingId);
|
||||
|
||||
@@ -328,5 +341,22 @@ public partial class DataSourceLocalDirectoryDialog : MSGComponentBase
|
||||
this.revalidateAfterRender = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects the embedding provider the user just added from within this dialog, so that what they
|
||||
/// entered so far can be saved right away.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only when no existing provider is selected, which includes the provider of a data source that
|
||||
/// was deleted since. Like the token limit in ToggleExpertSettings, the field learns its new value
|
||||
/// only with the next render, so it is checked after that.
|
||||
/// </remarks>
|
||||
private void SelectAddedEmbeddingProvider(EmbeddingProvider provider)
|
||||
{
|
||||
if (this.SelectedEmbedding is null)
|
||||
this.dataEmbeddingId = provider.Id;
|
||||
|
||||
this.revalidateAfterRender = true;
|
||||
}
|
||||
|
||||
private string GetExpertStyles => this.showExpertSettings ? "border-2 border-dashed rounded pa-2" : string.Empty;
|
||||
}
|
||||
@@ -8,6 +8,8 @@
|
||||
@* A drop anywhere in this dialog belongs to the dialog, not to the page behind it: *@
|
||||
<PathDropZone IsArea="@true">
|
||||
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues" FieldChanged="@this.RevalidateAfterFieldChange">
|
||||
<DataSourceMissingEmbeddingWarning IsInDataSourceDialog="@true" EmbeddingProviderAdded="@this.SelectAddedEmbeddingProvider"/>
|
||||
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
T="string"
|
||||
@@ -75,17 +77,10 @@
|
||||
@T("In order for the AI to be able to determine the appropriate data at any time, you must choose an embedding provider.")
|
||||
</MudJustifiedText>
|
||||
<MudSelect @ref="@this.embeddingSelect" @bind-Value="@this.dataEmbeddingId" Label="@T("Embedding")" Class="mb-3" OpenIcon="@Icons.Material.Filled.ExpandMore" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.dataSourceValidation.ValidateEmbeddingProviderAccess">
|
||||
@foreach (var embedding in this.AvailableEmbeddings)
|
||||
@foreach (var provider in this.SettingsManager.GetAllEmbeddingProviders())
|
||||
{
|
||||
<MudSelectItem Value="@embedding.Value">
|
||||
@if (this.GetEmbeddingProvider(embedding.Value) is { } provider)
|
||||
{
|
||||
<ProviderLabel ProviderType="@provider.UsedLLMProvider" CustomIconDataUrl="@provider.CustomIconDataUrl" Text="@embedding.Name" />
|
||||
}
|
||||
else
|
||||
{
|
||||
@embedding.Name
|
||||
}
|
||||
<MudSelectItem Value="@provider.Id">
|
||||
<ProviderLabel ProviderType="@provider.UsedLLMProvider" CustomIconDataUrl="@provider.CustomIconDataUrl" Text="@provider.Name" />
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
@@ -33,9 +33,6 @@ public partial class DataSourceLocalFileDialog : MSGComponentBase
|
||||
/// </remarks>
|
||||
[Parameter]
|
||||
public bool LockSource { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public IReadOnlyList<ConfigurationSelectData<string>> AvailableEmbeddings { get; set; } = [];
|
||||
|
||||
[Inject]
|
||||
private IDialogService DialogService { get; init; } = null!;
|
||||
@@ -125,6 +122,9 @@ public partial class DataSourceLocalFileDialog : MSGComponentBase
|
||||
}
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
// The embedding providers may change while the dialog is open, e.g., through a configuration plugin:
|
||||
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
@@ -146,12 +146,25 @@ public partial class DataSourceLocalFileDialog : MSGComponentBase
|
||||
|
||||
#endregion
|
||||
|
||||
private EmbeddingProvider? GetEmbeddingProvider(string providerId)
|
||||
#region Overrides of MSGComponentBase
|
||||
|
||||
protected override Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
|
||||
{
|
||||
var provider = this.SettingsManager.GetEmbeddingProviderById(providerId);
|
||||
return provider == EmbeddingProvider.NONE ? null : provider;
|
||||
switch (triggeredEvent)
|
||||
{
|
||||
case Event.CONFIGURATION_CHANGED:
|
||||
case Event.PLUGINS_RELOADED:
|
||||
// The embedding providers are listed anew, and the fields checked so far get a fresh verdict once they hold the new values:
|
||||
this.revalidateAfterRender = true;
|
||||
this.StateHasChanged();
|
||||
break;
|
||||
}
|
||||
|
||||
return base.ProcessIncomingMessage(sendingComponent, triggeredEvent, data);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
private EmbeddingProvider? SelectedEmbedding => this.SettingsManager.ConfigurationData.EmbeddingProviders
|
||||
.FirstOrDefault(x => x.Id == this.dataEmbeddingId);
|
||||
|
||||
@@ -308,5 +321,22 @@ public partial class DataSourceLocalFileDialog : MSGComponentBase
|
||||
this.revalidateAfterRender = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects the embedding provider the user just added from within this dialog, so that what they
|
||||
/// entered so far can be saved right away.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only when no existing provider is selected, which includes the provider of a data source that
|
||||
/// was deleted since. Like the token limit in ToggleExpertSettings, the field learns its new value
|
||||
/// only with the next render, so it is checked after that.
|
||||
/// </remarks>
|
||||
private void SelectAddedEmbeddingProvider(EmbeddingProvider provider)
|
||||
{
|
||||
if (this.SelectedEmbedding is null)
|
||||
this.dataEmbeddingId = provider.Id;
|
||||
|
||||
this.revalidateAfterRender = true;
|
||||
}
|
||||
|
||||
private string GetExpertStyles => this.showExpertSettings ? "border-2 border-dashed rounded pa-2" : string.Empty;
|
||||
}
|
||||
@@ -41,6 +41,12 @@
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
@* A way out which leads nowhere is worse than none: the mailbox could not be added anyway. *@
|
||||
@if (!this.IsAddingNotAllowed)
|
||||
{
|
||||
<DataSourceMissingEmbeddingWarning IsInDataSourceDialog="@true" EmbeddingProviderAdded="@this.SelectAddedEmbeddingProvider"/>
|
||||
}
|
||||
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
T="string"
|
||||
@@ -325,17 +331,10 @@
|
||||
@T("In order for the AI to be able to determine the appropriate data at any time, you must choose an embedding provider.")
|
||||
</MudJustifiedText>
|
||||
<MudSelect @ref="@this.embeddingSelect" @bind-Value="@this.dataEmbeddingId" Label="@T("Embedding")" Class="mb-3" OpenIcon="@Icons.Material.Filled.ExpandMore" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.dataSourceValidation.ValidateEmbeddingProviderAccess">
|
||||
@foreach (var embedding in this.AvailableEmbeddings)
|
||||
@foreach (var provider in this.SettingsManager.GetAllEmbeddingProviders())
|
||||
{
|
||||
<MudSelectItem Value="@embedding.Value">
|
||||
@if (this.GetEmbeddingProvider(embedding.Value) is { } provider)
|
||||
{
|
||||
<ProviderLabel ProviderType="@provider.UsedLLMProvider" CustomIconDataUrl="@provider.CustomIconDataUrl" Text="@embedding.Name" />
|
||||
}
|
||||
else
|
||||
{
|
||||
@embedding.Name
|
||||
}
|
||||
<MudSelectItem Value="@provider.Id">
|
||||
<ProviderLabel ProviderType="@provider.UsedLLMProvider" CustomIconDataUrl="@provider.CustomIconDataUrl" Text="@provider.Name" />
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
@@ -46,9 +46,6 @@ public partial class DataSourceMailboxDialog : MSGComponentBase
|
||||
[Parameter]
|
||||
public bool LockSource { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public IReadOnlyList<ConfigurationSelectData<string>> AvailableEmbeddings { get; set; } = [];
|
||||
|
||||
[Inject]
|
||||
private IDialogService DialogService { get; init; } = null!;
|
||||
|
||||
@@ -370,12 +367,6 @@ public partial class DataSourceMailboxDialog : MSGComponentBase
|
||||
? Icons.Material.Outlined.HourglassEmpty
|
||||
: this.testFailure is null ? Icons.Material.Outlined.CheckCircle : Icons.Material.Outlined.Error;
|
||||
|
||||
private EmbeddingProvider? GetEmbeddingProvider(string providerId)
|
||||
{
|
||||
var provider = this.SettingsManager.GetEmbeddingProviderById(providerId);
|
||||
return provider == EmbeddingProvider.NONE ? null : provider;
|
||||
}
|
||||
|
||||
private EmbeddingProvider? SelectedEmbedding => this.SettingsManager.ConfigurationData.EmbeddingProviders
|
||||
.FirstOrDefault(x => x.Id == this.dataEmbeddingId);
|
||||
|
||||
@@ -745,5 +736,22 @@ public partial class DataSourceMailboxDialog : MSGComponentBase
|
||||
this.revalidateAfterRender = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects the embedding provider the user just added from within this dialog, so that what they
|
||||
/// entered so far, the password and the tested connection included, can be saved right away.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only when no existing provider is selected, which includes the provider of a mailbox that was
|
||||
/// deleted since. Like the token limit in ToggleExpertSettings, the field learns its new value only
|
||||
/// with the next render, so it is checked after that.
|
||||
/// </remarks>
|
||||
private void SelectAddedEmbeddingProvider(EmbeddingProvider provider)
|
||||
{
|
||||
if (this.SelectedEmbedding is null)
|
||||
this.dataEmbeddingId = provider.Id;
|
||||
|
||||
this.revalidateAfterRender = true;
|
||||
}
|
||||
|
||||
private string GetExpertStyles => this.showExpertSettings ? "border-2 border-dashed rounded pa-2" : string.Empty;
|
||||
}
|
||||
Reference in new issue
Block a user