mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-05 13:29:40 +00:00
Configure language & start language plugins (#400)
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, deb) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, deb) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
This commit is contained in:
1 parent
171ed37c27
commit
3fc15d9789
31 files changed
+612
-156
No files matched your search
@@ -6,6 +6,7 @@ using AIStudio.Assistants.TextSummarizer;
|
||||
using AIStudio.Assistants.EMail;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
|
||||
using WritingStylesRewrite = AIStudio.Assistants.RewriteImprove.WritingStyles;
|
||||
using WritingStylesEMail = AIStudio.Assistants.EMail.WritingStyles;
|
||||
@@ -25,6 +26,21 @@ public readonly record struct ConfigurationSelectData<T>(string Name, T Value);
|
||||
/// </summary>
|
||||
public static class ConfigurationSelectDataFactory
|
||||
{
|
||||
public static IEnumerable<ConfigurationSelectData<LangBehavior>> GetLangBehaviorData()
|
||||
{
|
||||
foreach (var behavior in Enum.GetValues<LangBehavior>())
|
||||
yield return new(behavior.Name(), behavior);
|
||||
}
|
||||
|
||||
public static IEnumerable<ConfigurationSelectData<Guid>> GetLanguagesData()
|
||||
{
|
||||
foreach (var runningPlugin in PluginFactory.RunningPlugins)
|
||||
{
|
||||
if(runningPlugin is ILanguagePlugin languagePlugin)
|
||||
yield return new(languagePlugin.LangName, runningPlugin.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<ConfigurationSelectData<LoadingChatProviderBehavior>> GetLoadingChatProviderBehavior()
|
||||
{
|
||||
yield return new("When possible, use the LLM provider which was used for each chat in the first place", LoadingChatProviderBehavior.USE_CHAT_PROVIDER_IF_AVAILABLE);
|
||||
|
||||
@@ -2,6 +2,16 @@ namespace AIStudio.Settings.DataModel;
|
||||
|
||||
public sealed class DataApp
|
||||
{
|
||||
/// <summary>
|
||||
/// The language behavior.
|
||||
/// </summary>
|
||||
public LangBehavior LanguageBehavior { get; set; } = LangBehavior.AUTO;
|
||||
|
||||
/// <summary>
|
||||
/// The language plugin ID to use.
|
||||
/// </summary>
|
||||
public Guid LanguagePluginId { get; set; } = Guid.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The preferred theme to use.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace AIStudio.Settings.DataModel;
|
||||
|
||||
public enum LangBehavior
|
||||
{
|
||||
AUTO,
|
||||
MANUAL,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace AIStudio.Settings.DataModel;
|
||||
|
||||
public static class LangBehaviorExtensions
|
||||
{
|
||||
public static string Name(this LangBehavior langBehavior) => langBehavior switch
|
||||
{
|
||||
LangBehavior.AUTO => "Choose the language automatically, based on your system language.",
|
||||
LangBehavior.MANUAL => "Choose the language manually.",
|
||||
|
||||
_ => "Unknown option"
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Text.Json.Serialization;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
// ReSharper disable NotAccessedPositionalProperty.Local
|
||||
|
||||
@@ -13,7 +14,7 @@ namespace AIStudio.Settings;
|
||||
/// <summary>
|
||||
/// The settings manager.
|
||||
/// </summary>
|
||||
public sealed class SettingsManager(ILogger<SettingsManager> logger)
|
||||
public sealed class SettingsManager(ILogger<SettingsManager> logger, RustService rustService)
|
||||
{
|
||||
private const string SETTINGS_FILENAME = "settings.json";
|
||||
|
||||
@@ -24,6 +25,7 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
|
||||
};
|
||||
|
||||
private readonly ILogger<SettingsManager> logger = logger;
|
||||
private readonly RustService rustService = rustService;
|
||||
|
||||
/// <summary>
|
||||
/// The directory where the configuration files are stored.
|
||||
@@ -143,8 +145,53 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
|
||||
return minimumLevel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the given plugin is enabled.
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin to check.</param>
|
||||
/// <returns>True, when the plugin is enabled, false otherwise.</returns>
|
||||
public bool IsPluginEnabled(IPluginMetadata plugin) => this.ConfigurationData.EnabledPlugins.Contains(plugin.Id);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the active language plugin.
|
||||
/// </summary>
|
||||
/// <returns>The active language plugin.</returns>
|
||||
public async Task<ILanguagePlugin> GetActiveLanguagePlugin()
|
||||
{
|
||||
switch (this.ConfigurationData.App.LanguageBehavior)
|
||||
{
|
||||
case LangBehavior.AUTO:
|
||||
var languageCode = await this.rustService.ReadUserLanguage();
|
||||
var languagePlugin = PluginFactory.RunningPlugins.FirstOrDefault(x => x is ILanguagePlugin langPlug && langPlug.IETFTag == languageCode);
|
||||
if (languagePlugin is null)
|
||||
return PluginFactory.BaseLanguage;
|
||||
|
||||
if (languagePlugin is ILanguagePlugin langPlugin)
|
||||
return langPlugin;
|
||||
|
||||
this.logger.LogError("The language plugin is not a language plugin.");
|
||||
return PluginFactory.BaseLanguage;
|
||||
|
||||
case LangBehavior.MANUAL:
|
||||
var pluginId = this.ConfigurationData.App.LanguagePluginId;
|
||||
var plugin = PluginFactory.RunningPlugins.FirstOrDefault(x => x.Id == pluginId);
|
||||
if (plugin is null)
|
||||
{
|
||||
this.logger.LogWarning($"The chosen language plugin (id='{pluginId}') is not available.");
|
||||
return PluginFactory.BaseLanguage;
|
||||
}
|
||||
|
||||
if (plugin is ILanguagePlugin chosenLangPlugin)
|
||||
return chosenLangPlugin;
|
||||
|
||||
this.logger.LogError("The chosen language plugin is not a language plugin.");
|
||||
return PluginFactory.BaseLanguage;
|
||||
}
|
||||
|
||||
this.logger.LogError("The language behavior is unknown.");
|
||||
return PluginFactory.BaseLanguage;
|
||||
}
|
||||
|
||||
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
|
||||
public Provider GetPreselectedProvider(Tools.Components component, string? currentProviderId = null, bool usePreselectionBeforeCurrentProvider = false)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user