Fixed missed row numbers of providers

This commit is contained in:
Thorsten Sommer 2024-05-19 20:28:25 +02:00
parent b485da7aa9
commit 276a33a52e
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
5 changed files with 25 additions and 3 deletions

View File

@ -20,7 +20,7 @@
<MudTh Style="text-align: left;">Actions</MudTh> <MudTh Style="text-align: left;">Actions</MudTh>
</HeaderContent> </HeaderContent>
<RowTemplate> <RowTemplate>
<MudTd></MudTd> <MudTd>@context.Num</MudTd>
<MudTd>@context.InstanceName</MudTd> <MudTd>@context.InstanceName</MudTd>
<MudTd>@context.UsedProvider</MudTd> <MudTd>@context.UsedProvider</MudTd>
<MudTd>@context.Model</MudTd> <MudTd>@context.Model</MudTd>

View File

@ -52,6 +52,8 @@ public partial class Settings : ComponentBase
return; return;
var addedProvider = (AIStudio.Settings.Provider)dialogResult.Data; var addedProvider = (AIStudio.Settings.Provider)dialogResult.Data;
addedProvider = addedProvider with { Num = this.SettingsManager.ConfigurationData.NextProviderNum++ };
this.SettingsManager.ConfigurationData.Providers.Add(addedProvider); this.SettingsManager.ConfigurationData.Providers.Add(addedProvider);
await this.SettingsManager.StoreSettings(); await this.SettingsManager.StoreSettings();
} }
@ -60,6 +62,7 @@ public partial class Settings : ComponentBase
{ {
var dialogParameters = new DialogParameters<ProviderDialog> var dialogParameters = new DialogParameters<ProviderDialog>
{ {
{ x => x.DataNum, provider.Num },
{ x => x.DataId, provider.Id }, { x => x.DataId, provider.Id },
{ x => x.DataInstanceName, provider.InstanceName }, { x => x.DataInstanceName, provider.InstanceName },
{ x => x.DataProvider, provider.UsedProvider }, { x => x.DataProvider, provider.UsedProvider },
@ -73,6 +76,12 @@ public partial class Settings : ComponentBase
return; return;
var editedProvider = (AIStudio.Settings.Provider)dialogResult.Data; var editedProvider = (AIStudio.Settings.Provider)dialogResult.Data;
// Set the provider number if it's not set. This is important for providers
// added before we started saving the provider number.
if(editedProvider.Num == 0)
editedProvider = editedProvider with { Num = this.SettingsManager.ConfigurationData.NextProviderNum++ };
this.SettingsManager.ConfigurationData.Providers[this.SettingsManager.ConfigurationData.Providers.IndexOf(provider)] = editedProvider; this.SettingsManager.ConfigurationData.Providers[this.SettingsManager.ConfigurationData.Providers.IndexOf(provider)] = editedProvider;
await this.SettingsManager.StoreSettings(); await this.SettingsManager.StoreSettings();
} }

View File

@ -14,7 +14,12 @@ public sealed class Data
/// <summary> /// <summary>
/// List of configured providers. /// List of configured providers.
/// </summary> /// </summary>
public List<Provider> Providers { get; init; } = new(); public List<Provider> Providers { get; init; } = [];
/// <summary>
/// The next provider number to use.
/// </summary>
public uint NextProviderNum { get; set; } = 1;
/// <summary> /// <summary>
/// Should we save energy? When true, we will update content streamed /// Should we save energy? When true, we will update content streamed

View File

@ -5,11 +5,12 @@ namespace AIStudio.Settings;
/// <summary> /// <summary>
/// Data model for configured providers. /// Data model for configured providers.
/// </summary> /// </summary>
/// <param name="Num">The provider's number.</param>
/// <param name="Id">The provider's ID.</param> /// <param name="Id">The provider's ID.</param>
/// <param name="InstanceName">The provider's instance name. Useful for multiple instances of the same provider, e.g., to distinguish between different OpenAI API keys.</param> /// <param name="InstanceName">The provider's instance name. Useful for multiple instances of the same provider, e.g., to distinguish between different OpenAI API keys.</param>
/// <param name="UsedProvider">The provider used.</param> /// <param name="UsedProvider">The provider used.</param>
/// <param name="Model">The LLM model to use for chat.</param> /// <param name="Model">The LLM model to use for chat.</param>
public readonly record struct Provider(string Id, string InstanceName, Providers UsedProvider, Model Model) public readonly record struct Provider(uint Num, string Id, string InstanceName, Providers UsedProvider, Model Model)
{ {
#region Overrides of ValueType #region Overrides of ValueType

View File

@ -17,6 +17,12 @@ public partial class ProviderDialog : ComponentBase
[CascadingParameter] [CascadingParameter]
private MudDialogInstance MudDialog { get; set; } = null!; private MudDialogInstance MudDialog { get; set; } = null!;
/// <summary>
/// The provider's number in the list.
/// </summary>
[Parameter]
public uint DataNum { get; set; }
/// <summary> /// <summary>
/// The provider's ID. /// The provider's ID.
/// </summary> /// </summary>
@ -129,6 +135,7 @@ public partial class ProviderDialog : ComponentBase
// We just return this data to the parent component: // We just return this data to the parent component:
var addedProvider = new Provider var addedProvider = new Provider
{ {
Num = this.DataNum,
Id = this.DataId, Id = this.DataId,
InstanceName = this.DataInstanceName, InstanceName = this.DataInstanceName,
UsedProvider = this.DataProvider, UsedProvider = this.DataProvider,