From 5d798ac4dec37eb33e297fdcff303e3072198cee Mon Sep 17 00:00:00 2001 From: "aden.chen" Date: Mon, 9 Mar 2026 11:44:52 +0800 Subject: [PATCH 1/2] Add GetUpgradeModel method to ISettingService and implement it in SettingService. Update AgentPlugin to bind ModelUpgradeMapSettings. --- .../Models/Gpt4xModelConstants.cs | 13 +++++++++++++ .../Settings/ISettingService.cs | 2 ++ .../Settings/ModelUpgradeMapSettings.cs | 14 ++++++++++++++ .../BotSharp.Core/Agents/AgentPlugin.cs | 10 ++++++++++ .../Infrastructures/SettingService.cs | 13 +++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Settings/ModelUpgradeMapSettings.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs b/src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs new file mode 100644 index 000000000..2de7a7e68 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs @@ -0,0 +1,13 @@ +namespace BotSharp.Abstraction.Models; + +public static class Gpt4xModelConstants +{ + public const string GPT_4o = "gpt-4o"; + public const string GPT_4o_2024_11_20 = "gpt-4o-2024-11-20"; + public const string GPT_4o_Mini = "gpt-4o-mini"; + public const string GPT_4_1 = "gpt-4.1"; + public const string GPT_4_1_Mini = "gpt-4.1-mini"; + public const string GPT_4_1_Nano = "gpt-4.1-nano"; + public const string GPT_4o_Mini_Realtime_Preview = "gpt-4o-mini-realtime-preview"; + public const string GPT_4o_Realtime_Preview = "gpt-4o-realtime-preview"; +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Settings/ISettingService.cs b/src/Infrastructure/BotSharp.Abstraction/Settings/ISettingService.cs index 084f314d2..cb6ef9af0 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Settings/ISettingService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Settings/ISettingService.cs @@ -10,4 +10,6 @@ public interface ISettingService T Bind(string path) where T : new(); Task GetDetail(string settingName, bool mask = false); + + string GetUpgradeModel(string oldModelName); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Settings/ModelUpgradeMapSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Settings/ModelUpgradeMapSettings.cs new file mode 100644 index 000000000..d351f43c6 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Settings/ModelUpgradeMapSettings.cs @@ -0,0 +1,14 @@ +namespace BotSharp.Abstraction.Settings; + +public class ModelUpgradeMapSettings +{ + public static string Key => "ModelUpgradeMap"; + public List ModelUpgradeMap { get; set; } = new(); +} + +public class ModelUpgradeMapItem +{ + public string OldModel { get; set; } = string.Empty; + public string NewModel { get; set; } = string.Empty; + public bool Enable { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs b/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs index 575385455..36432d5e7 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs @@ -48,6 +48,16 @@ public void RegisterDI(IServiceCollection services, IConfiguration config) render.RegisterType(typeof(AgentSettings)); return settingService.Bind("Agent"); }); + + services.AddScoped(provider => + { + var settingService = provider.GetRequiredService(); + var config = provider.GetRequiredService(); + var settings = new ModelUpgradeMapSettings(); + config.Bind(ModelUpgradeMapSettings.Key, settings.ModelUpgradeMap); + return settings; + }); + } public bool AttachMenu(List menu) diff --git a/src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs b/src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs index 785f71bae..c4204c4b4 100644 --- a/src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs +++ b/src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs @@ -50,4 +50,17 @@ public static string Mask(string value) + string.Join("", Enumerable.Repeat("*", value.Length / 2)); return value; } + + public string GetUpgradeModel(string oldModelName) + { + var modelUpgradeMapSettings = _services.GetRequiredService(); + var mapping = modelUpgradeMapSettings.ModelUpgradeMap.FirstOrDefault(x => x.OldModel.Equals(oldModelName, StringComparison.InvariantCultureIgnoreCase)); + + if(mapping == null || !mapping.Enable) + { + return oldModelName; + } + + return mapping.NewModel; + } } From 6ed51e57c2dbb754baecc9da7ddb720f9e1d553f Mon Sep 17 00:00:00 2001 From: "aden.chen" Date: Mon, 9 Mar 2026 14:51:11 +0800 Subject: [PATCH 2/2] Refactor GetUpgradeModel method to use StringComparison.OrdinalIgnoreCase for model name comparison in SettingService. --- .../BotSharp.Core/Infrastructures/SettingService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs b/src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs index c4204c4b4..8a78b5a57 100644 --- a/src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs +++ b/src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs @@ -54,7 +54,7 @@ public static string Mask(string value) public string GetUpgradeModel(string oldModelName) { var modelUpgradeMapSettings = _services.GetRequiredService(); - var mapping = modelUpgradeMapSettings.ModelUpgradeMap.FirstOrDefault(x => x.OldModel.Equals(oldModelName, StringComparison.InvariantCultureIgnoreCase)); + var mapping = modelUpgradeMapSettings.ModelUpgradeMap.FirstOrDefault(x => x.OldModel.Equals(oldModelName, StringComparison.OrdinalIgnoreCase)); if(mapping == null || !mapping.Enable) {