Skip to content

Commit c06dd1b

Browse files
authored
Merge pull request SciSharp#1303 from adenchen123/master
Infrastructure for GPT 4.x model upgrading
2 parents 2ba6ecc + e390529 commit c06dd1b

5 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace BotSharp.Abstraction.Models;
2+
3+
public static class Gpt4xModelConstants
4+
{
5+
public const string GPT_4o = "gpt-4o";
6+
public const string GPT_4o_2024_11_20 = "gpt-4o-2024-11-20";
7+
public const string GPT_4o_Mini = "gpt-4o-mini";
8+
public const string GPT_4_1 = "gpt-4.1";
9+
public const string GPT_4_1_Mini = "gpt-4.1-mini";
10+
public const string GPT_4_1_Nano = "gpt-4.1-nano";
11+
public const string GPT_4o_Mini_Realtime_Preview = "gpt-4o-mini-realtime-preview";
12+
public const string GPT_4o_Realtime_Preview = "gpt-4o-realtime-preview";
13+
}

src/Infrastructure/BotSharp.Abstraction/Settings/ISettingService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ public interface ISettingService
1010
T Bind<T>(string path) where T : new();
1111

1212
Task<object> GetDetail(string settingName, bool mask = false);
13+
14+
string GetUpgradeModel(string oldModelName);
1315
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace BotSharp.Abstraction.Settings;
2+
3+
public class ModelUpgradeMapSettings
4+
{
5+
public static string Key => "ModelUpgradeMap";
6+
public List<ModelUpgradeMapItem> ModelUpgradeMap { get; set; } = new();
7+
}
8+
9+
public class ModelUpgradeMapItem
10+
{
11+
public string OldModel { get; set; } = string.Empty;
12+
public string NewModel { get; set; } = string.Empty;
13+
public bool Enable { get; set; }
14+
}

src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
4848
render.RegisterType(typeof(AgentSettings));
4949
return settingService.Bind<AgentSettings>("Agent");
5050
});
51+
52+
services.AddScoped(provider =>
53+
{
54+
var settingService = provider.GetRequiredService<ISettingService>();
55+
var config = provider.GetRequiredService<IConfiguration>();
56+
var settings = new ModelUpgradeMapSettings();
57+
config.Bind(ModelUpgradeMapSettings.Key, settings.ModelUpgradeMap);
58+
return settings;
59+
});
60+
5161
}
5262

5363
public bool AttachMenu(List<PluginMenuDef> menu)

src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,17 @@ public static string Mask(string value)
5050
+ string.Join("", Enumerable.Repeat("*", value.Length / 2));
5151
return value;
5252
}
53+
54+
public string GetUpgradeModel(string oldModelName)
55+
{
56+
var modelUpgradeMapSettings = _services.GetRequiredService<ModelUpgradeMapSettings>();
57+
var mapping = modelUpgradeMapSettings.ModelUpgradeMap.FirstOrDefault(x => x.OldModel.Equals(oldModelName, StringComparison.OrdinalIgnoreCase));
58+
59+
if(mapping == null || !mapping.Enable)
60+
{
61+
return oldModelName;
62+
}
63+
64+
return mapping.NewModel;
65+
}
5366
}

0 commit comments

Comments
 (0)