mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-20 16:52:57 +00:00
Add dryRun checks to provider and chat template configuration logic
This commit is contained in:
parent
f221119d71
commit
3963da1366
@ -90,24 +90,27 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
|
|||||||
// Apply the configured providers to the system settings:
|
// Apply the configured providers to the system settings:
|
||||||
//
|
//
|
||||||
#pragma warning disable MWAIS0001
|
#pragma warning disable MWAIS0001
|
||||||
foreach (var configuredProvider in configuredProviders)
|
if (!dryRun)
|
||||||
{
|
{
|
||||||
// The iterating variable is immutable, so we need to create a local copy:
|
foreach (var configuredProvider in configuredProviders)
|
||||||
var provider = configuredProvider;
|
{
|
||||||
|
// The iterating variable is immutable, so we need to create a local copy:
|
||||||
|
var provider = configuredProvider;
|
||||||
|
|
||||||
var providerIndex = SETTINGS_MANAGER.ConfigurationData.Providers.FindIndex(p => p.Id == provider.Id);
|
var providerIndex = SETTINGS_MANAGER.ConfigurationData.Providers.FindIndex(p => p.Id == provider.Id);
|
||||||
if (providerIndex > -1)
|
if (providerIndex > -1)
|
||||||
{
|
{
|
||||||
// Case: The provider already exists, we update it:
|
// Case: The provider already exists, we update it:
|
||||||
var existingProvider = SETTINGS_MANAGER.ConfigurationData.Providers[providerIndex];
|
var existingProvider = SETTINGS_MANAGER.ConfigurationData.Providers[providerIndex];
|
||||||
provider = provider with { Num = existingProvider.Num }; // Keep the original number
|
provider = provider with { Num = existingProvider.Num }; // Keep the original number
|
||||||
SETTINGS_MANAGER.ConfigurationData.Providers[providerIndex] = provider;
|
SETTINGS_MANAGER.ConfigurationData.Providers[providerIndex] = provider;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Case: The provider does not exist, we add it:
|
// Case: The provider does not exist, we add it:
|
||||||
provider = provider with { Num = SETTINGS_MANAGER.ConfigurationData.NextProviderNum++ };
|
provider = provider with { Num = SETTINGS_MANAGER.ConfigurationData.NextProviderNum++ };
|
||||||
SETTINGS_MANAGER.ConfigurationData.Providers.Add(provider);
|
SETTINGS_MANAGER.ConfigurationData.Providers.Add(provider);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma warning restore MWAIS0001
|
#pragma warning restore MWAIS0001
|
||||||
@ -135,20 +138,26 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply configured chat templates to the system settings:
|
// Apply configured chat templates to the system settings:
|
||||||
foreach (var configuredTemplate in configuredTemplates)
|
if (!dryRun)
|
||||||
{
|
{
|
||||||
var template = configuredTemplate;
|
foreach (var configuredTemplate in configuredTemplates)
|
||||||
var tplIndex = SETTINGS_MANAGER.ConfigurationData.ChatTemplates.FindIndex(t => t.Id == template.Id);
|
|
||||||
if (tplIndex > -1)
|
|
||||||
{
|
{
|
||||||
var existingTemplate = SETTINGS_MANAGER.ConfigurationData.ChatTemplates[tplIndex];
|
// The iterating variable is immutable, so we need to create a local copy:
|
||||||
template = template with { Num = existingTemplate.Num };
|
var template = configuredTemplate;
|
||||||
SETTINGS_MANAGER.ConfigurationData.ChatTemplates[tplIndex] = template;
|
var tplIndex = SETTINGS_MANAGER.ConfigurationData.ChatTemplates.FindIndex(t => t.Id == template.Id);
|
||||||
}
|
if (tplIndex > -1)
|
||||||
else
|
{
|
||||||
{
|
// Case: The template already exists, we update it:
|
||||||
template = template with { Num = SETTINGS_MANAGER.ConfigurationData.NextChatTemplateNum++ };
|
var existingTemplate = SETTINGS_MANAGER.ConfigurationData.ChatTemplates[tplIndex];
|
||||||
SETTINGS_MANAGER.ConfigurationData.ChatTemplates.Add(template);
|
template = template with { Num = existingTemplate.Num };
|
||||||
|
SETTINGS_MANAGER.ConfigurationData.ChatTemplates[tplIndex] = template;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Case: The template does not exist, we add it:
|
||||||
|
template = template with { Num = SETTINGS_MANAGER.ConfigurationData.NextChatTemplateNum++ };
|
||||||
|
SETTINGS_MANAGER.ConfigurationData.ChatTemplates.Add(template);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user