mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 19:39:46 +00:00
Fixed configuration issues due to enum renaming by providing data migration
This commit is contained in:
parent
1cac1a7913
commit
838d3e2d4d
@ -9,7 +9,7 @@ public sealed class Data
|
||||
/// The version of the settings file. Allows us to upgrade the settings
|
||||
/// when a new version is available.
|
||||
/// </summary>
|
||||
public Version Version { get; init; } = Version.V4;
|
||||
public Version Version { get; init; } = Version.V5;
|
||||
|
||||
/// <summary>
|
||||
/// List of configured providers.
|
||||
|
@ -0,0 +1,65 @@
|
||||
namespace AIStudio.Settings.DataModel.PreviousModels;
|
||||
|
||||
public sealed class DataV4
|
||||
{
|
||||
/// <summary>
|
||||
/// The version of the settings file. Allows us to upgrade the settings
|
||||
/// when a new version is available.
|
||||
/// </summary>
|
||||
public Version Version { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// List of configured providers.
|
||||
/// </summary>
|
||||
public List<Provider> Providers { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Settings concerning the LLM providers.
|
||||
/// </summary>
|
||||
public DataLLMProviders LLMProviders { get; init; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// List of configured profiles.
|
||||
/// </summary>
|
||||
public List<Profile> Profiles { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The next provider number to use.
|
||||
/// </summary>
|
||||
public uint NextProviderNum { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The next profile number to use.
|
||||
/// </summary>
|
||||
public uint NextProfileNum { get; set; } = 1;
|
||||
|
||||
public DataApp App { get; init; } = new();
|
||||
|
||||
public DataChat Chat { get; init; } = new();
|
||||
|
||||
public DataWorkspace Workspace { get; init; } = new();
|
||||
|
||||
public DataIconFinder IconFinder { get; init; } = new();
|
||||
|
||||
public DataTranslation Translation { get; init; } = new();
|
||||
|
||||
public DataCoding Coding { get; init; } = new();
|
||||
|
||||
public DataTextSummarizer TextSummarizer { get; init; } = new();
|
||||
|
||||
public DataTextContentCleaner TextContentCleaner { get; init; } = new();
|
||||
|
||||
public DataAgenda Agenda { get; init; } = new();
|
||||
|
||||
public DataGrammarSpelling GrammarSpelling { get; init; } = new();
|
||||
|
||||
public DataRewriteImprove RewriteImprove { get; init; } = new();
|
||||
|
||||
public DataEMail EMail { get; set; } = new();
|
||||
|
||||
public DataLegalCheck LegalCheck { get; set; } = new();
|
||||
|
||||
public DataSynonyms Synonyms { get; set; } = new();
|
||||
|
||||
public DataMyTasks MyTasks { get; set; } = new();
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
using Host = AIStudio.Provider.SelfHosted.Host;
|
||||
|
||||
namespace AIStudio.Settings.DataModel.PreviousModels;
|
||||
|
||||
public readonly record struct Provider(
|
||||
uint Num,
|
||||
string Id,
|
||||
string InstanceName,
|
||||
LLMProviders UsedProvider,
|
||||
Model Model,
|
||||
bool IsSelfHosted = false,
|
||||
string Hostname = "http://localhost:1234",
|
||||
Host Host = Host.NONE);
|
@ -0,0 +1,21 @@
|
||||
namespace AIStudio.Settings.DataModel.PreviousModels;
|
||||
|
||||
public static class ProviderV4Extensions
|
||||
{
|
||||
public static List<Settings.Provider> MigrateFromV4ToV5(this IEnumerable<Provider> providers)
|
||||
{
|
||||
return providers.Select(provider => provider.MigrateFromV4ToV5()).ToList();
|
||||
}
|
||||
|
||||
public static Settings.Provider MigrateFromV4ToV5(this Provider provider) => new()
|
||||
{
|
||||
Num = provider.Num,
|
||||
Id = provider.Id,
|
||||
InstanceName = provider.InstanceName,
|
||||
UsedLLMProvider = provider.UsedProvider,
|
||||
Model = provider.Model,
|
||||
IsSelfHosted = provider.IsSelfHosted,
|
||||
Hostname = provider.Hostname,
|
||||
Host = provider.Host,
|
||||
};
|
||||
}
|
@ -23,7 +23,8 @@ public static class SettingsMigrations
|
||||
|
||||
configV1 = MigrateV1ToV2(logger, configV1);
|
||||
configV1 = MigrateV2ToV3(logger, configV1);
|
||||
return MigrateV3ToV4(logger, configV1);
|
||||
var configV14 = MigrateV3ToV4(logger, configV1);
|
||||
return MigrateV4ToV5(logger, configV14);
|
||||
|
||||
case Version.V2:
|
||||
var configV2 = JsonSerializer.Deserialize<DataV1V3>(configData, jsonOptions);
|
||||
@ -34,7 +35,8 @@ public static class SettingsMigrations
|
||||
}
|
||||
|
||||
configV2 = MigrateV2ToV3(logger, configV2);
|
||||
return MigrateV3ToV4(logger, configV2);
|
||||
var configV24 = MigrateV3ToV4(logger, configV2);
|
||||
return MigrateV4ToV5(logger, configV24);
|
||||
|
||||
case Version.V3:
|
||||
var configV3 = JsonSerializer.Deserialize<DataV1V3>(configData, jsonOptions);
|
||||
@ -44,18 +46,29 @@ public static class SettingsMigrations
|
||||
return new();
|
||||
}
|
||||
|
||||
return MigrateV3ToV4(logger, configV3);
|
||||
|
||||
default:
|
||||
logger.LogInformation("No configuration migration is needed.");
|
||||
var configV4 = JsonSerializer.Deserialize<Data>(configData, jsonOptions);
|
||||
var configV34 = MigrateV3ToV4(logger, configV3);
|
||||
return MigrateV4ToV5(logger, configV34);
|
||||
|
||||
case Version.V4:
|
||||
var configV4 = JsonSerializer.Deserialize<DataV4>(configData, jsonOptions);
|
||||
if (configV4 is null)
|
||||
{
|
||||
logger.LogError("Failed to parse the v4 configuration. Using default values.");
|
||||
return new();
|
||||
}
|
||||
|
||||
return configV4;
|
||||
return MigrateV4ToV5(logger, configV4);
|
||||
|
||||
default:
|
||||
logger.LogInformation("No configuration migration is needed.");
|
||||
var configV5 = JsonSerializer.Deserialize<Data>(configData, jsonOptions);
|
||||
if (configV5 is null)
|
||||
{
|
||||
logger.LogError("Failed to parse the v4 configuration. Using default values.");
|
||||
return new();
|
||||
}
|
||||
|
||||
return configV5;
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +123,7 @@ public static class SettingsMigrations
|
||||
};
|
||||
}
|
||||
|
||||
private static Data MigrateV3ToV4(ILogger<SettingsManager> logger, DataV1V3 previousConfig)
|
||||
private static DataV4 MigrateV3ToV4(ILogger<SettingsManager> logger, DataV1V3 previousConfig)
|
||||
{
|
||||
//
|
||||
// Summary:
|
||||
@ -194,4 +207,38 @@ public static class SettingsMigrations
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static Data MigrateV4ToV5(ILogger<SettingsManager> logger, DataV4 previousConfig)
|
||||
{
|
||||
//
|
||||
// Summary:
|
||||
// We renamed the LLM provider enum.
|
||||
//
|
||||
|
||||
logger.LogInformation("Migrating from v4 to v5...");
|
||||
return new()
|
||||
{
|
||||
Version = Version.V5,
|
||||
Providers = previousConfig.Providers.MigrateFromV4ToV5(),
|
||||
LLMProviders = previousConfig.LLMProviders,
|
||||
Profiles = previousConfig.Profiles,
|
||||
NextProviderNum = previousConfig.NextProviderNum,
|
||||
NextProfileNum = previousConfig.NextProfileNum,
|
||||
App = previousConfig.App,
|
||||
Chat = previousConfig.Chat,
|
||||
Workspace = previousConfig.Workspace,
|
||||
IconFinder = previousConfig.IconFinder,
|
||||
Translation = previousConfig.Translation,
|
||||
Coding = previousConfig.Coding,
|
||||
TextSummarizer = previousConfig.TextSummarizer,
|
||||
TextContentCleaner = previousConfig.TextContentCleaner,
|
||||
Agenda = previousConfig.Agenda,
|
||||
GrammarSpelling = previousConfig.GrammarSpelling,
|
||||
RewriteImprove = previousConfig.RewriteImprove,
|
||||
EMail = previousConfig.EMail,
|
||||
LegalCheck = previousConfig.LegalCheck,
|
||||
Synonyms = previousConfig.Synonyms,
|
||||
MyTasks = previousConfig.MyTasks,
|
||||
};
|
||||
}
|
||||
}
|
@ -12,4 +12,5 @@ public enum Version
|
||||
V2,
|
||||
V3,
|
||||
V4,
|
||||
V5,
|
||||
}
|
Loading…
Reference in New Issue
Block a user