Skip to content

Commit f2577c8

Browse files
authored
Merge pull request #1306 from adenchen123/master
model upgrade for hard code
2 parents 8b41765 + e286ca8 commit f2577c8

22 files changed

Lines changed: 80 additions & 26 deletions

File tree

src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ public static class Gpt4xModelConstants
1010
public const string GPT_4_1_Nano = "gpt-4.1-nano";
1111
public const string GPT_4o_Mini_Realtime_Preview = "gpt-4o-mini-realtime-preview";
1212
public const string GPT_4o_Realtime_Preview = "gpt-4o-realtime-preview";
13+
public const string GPT_4o_Mini_Search_Preview = "gpt-4o-mini-search-preview";
14+
public const string GPT_4o_Mini_Transcribe = "gpt-4o-mini-transcribe";
15+
public const string GPT_4o_Transcribe = "gpt-4o-transcribe";
16+
public const string GPT_4o_Mini_Tts = "gpt-4o-mini-tts";
17+
public const string GPT_4o_Search_Preview = "gpt-4o-search-preview";
1318
}

src/Infrastructure/BotSharp.Abstraction/Realtime/Models/ModelTurnDetection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public class ModelTurnDetection
1111

1212
public class AudioTranscription
1313
{
14-
public string Model { get; set; } = "gpt-4o-mini-transcribe";
14+
public string Model { get; set; } = Gpt4xModelConstants.GPT_4o_Mini_Transcribe;
1515
public string? Language { get; set; }
1616
}

src/Infrastructure/BotSharp.Abstraction/Realtime/Settings/RealtimeModelSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace BotSharp.Abstraction.Realtime.Settings;
55
public class RealtimeModelSettings
66
{
77
public string Provider { get; set; } = "openai";
8-
public string Model { get; set; } = "gpt-4o-mini-realtime-preview";
8+
public string Model { get; set; } = Gpt4xModelConstants.GPT_4o_Mini_Realtime_Preview;
99
public string[] Modalities { get; set; } = ["text", "audio"];
1010
public bool InterruptResponse { get; set; } = true;
1111
public string InputAudioFormat { get; set; } = "g711_ulaw";

src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using BotSharp.Abstraction.Realtime.Options;
77
using BotSharp.Abstraction.Realtime.Settings;
88
using BotSharp.Abstraction.Routing.Enums;
9+
using BotSharp.Abstraction.Settings;
910
using BotSharp.Core.Infrastructures;
1011

1112
namespace BotSharp.Core.Realtime.Services;
@@ -192,14 +193,15 @@ public RealtimeHubConnection SetHubConnection(string conversationId)
192193
{
193194
var provider = agent?.LlmConfig?.Realtime?.Provider;
194195
var model = agent?.LlmConfig?.Realtime?.Model;
196+
var settingService = _services.GetRequiredService<ISettingService>();
195197

196198
if (!string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(model))
197199
{
198200
return (provider, model);
199201
}
200202

201203
provider = _settings.Provider;
202-
model = _settings.Model;
204+
model = settingService.GetUpgradeModel(_settings.Model);
203205

204206
if (!string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(model))
205207
{

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BotSharp.Abstraction.Conversations.Enums;
22
using BotSharp.Abstraction.MLTasks;
33
using BotSharp.Abstraction.Models;
4+
using BotSharp.Abstraction.Settings;
45
using BotSharp.Abstraction.Templating;
56

67
namespace BotSharp.Core.Conversations.Services;
@@ -62,8 +63,10 @@ private async Task<string> Summarize(Agent agent, string prompt)
6263
string? model;
6364

6465
var providerService = _services.GetRequiredService<ILlmProviderService>();
66+
var settingService = _services.GetRequiredService<ISettingService>();
6567
var modelSettings = providerService.GetProviderModels(provider);
66-
var modelSetting = modelSettings.FirstOrDefault(x => x.Name.IsEqualTo("gpt4-turbo") || x.Name.IsEqualTo("gpt-4o"));
68+
var defaultModel = settingService.GetUpgradeModel(Gpt4xModelConstants.GPT_4o);
69+
var modelSetting = modelSettings.FirstOrDefault(x => x.Name.IsEqualTo(defaultModel));
6770

6871
if (modelSetting != null)
6972
{

src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using BotSharp.Abstraction.Instructs;
22
using BotSharp.Abstraction.Instructs.Models;
33
using BotSharp.Abstraction.Instructs.Options;
4+
using BotSharp.Abstraction.Models;
5+
using BotSharp.Abstraction.Settings;
46
using System.IO;
57

68
namespace BotSharp.Core.Files.Services;
@@ -9,11 +11,12 @@ public partial class FileInstructService
911
{
1012
public async Task<string> ReadImages(string text, IEnumerable<InstructFileModel> images, InstructOptions? options = null)
1113
{
14+
var settingService = _services.GetRequiredService<ISettingService>();
1215
var innerAgentId = options?.AgentId ?? Guid.Empty.ToString();
1316
var instruction = await RenderAgentTemplate(innerAgentId, options?.TemplateName, options?.Data);
1417
text = RenderText(text, options?.Data);
1518

16-
var completion = CompletionProvider.GetChatCompletion(_services, provider: options?.Provider ?? "openai", model: options?.Model ?? "gpt-4o", multiModal: true);
19+
var completion = CompletionProvider.GetChatCompletion(_services, provider: options?.Provider ?? "openai", model: options?.Model ?? settingService.GetUpgradeModel(Gpt4xModelConstants.GPT_4o), multiModal: true);
1720
var message = await completion.GetChatCompletions(new Agent()
1821
{
1922
Id = innerAgentId,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using BotSharp.Abstraction.MLTasks;
22
using BotSharp.Abstraction.MLTasks.Settings;
3+
using BotSharp.Abstraction.Models;
4+
using BotSharp.Abstraction.Settings;
35

46
namespace BotSharp.Core.Infrastructures;
57

@@ -140,6 +142,7 @@ public static IAudioTranscription GetAudioTranscriber(
140142
string? provider = null,
141143
string? model = null)
142144
{
145+
var settingService = services.GetRequiredService<ISettingService>();
143146
var completions = services.GetServices<IAudioTranscription>();
144147
var completer = completions.FirstOrDefault(x => x.Provider == (provider ?? "openai"));
145148
if (completer == null)
@@ -149,7 +152,7 @@ public static IAudioTranscription GetAudioTranscriber(
149152
return default!;
150153
}
151154

152-
completer.SetModelName(model ?? "gpt-4o-mini-transcribe");
155+
completer.SetModelName(model ?? settingService.GetUpgradeModel(Gpt4xModelConstants.GPT_4o_Mini_Transcribe));
153156
return completer;
154157
}
155158

@@ -158,6 +161,7 @@ public static IAudioSynthesis GetAudioSynthesizer(
158161
string? provider = null,
159162
string? model = null)
160163
{
164+
var settingService = services.GetRequiredService<ISettingService>();
161165
var completions = services.GetServices<IAudioSynthesis>();
162166
var completer = completions.FirstOrDefault(x => x.Provider == (provider ?? "openai"));
163167
if (completer == null)
@@ -167,7 +171,7 @@ public static IAudioSynthesis GetAudioSynthesizer(
167171
return default!;
168172
}
169173

170-
completer.SetModelName(model ?? "gpt-4o-mini-tts");
174+
completer.SetModelName(model ?? settingService.GetUpgradeModel(Gpt4xModelConstants.GPT_4o_Mini_Tts));
171175
return completer;
172176
}
173177

src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using BotSharp.Abstraction.Instructs.Options;
2+
using BotSharp.Abstraction.Models;
23
using BotSharp.Abstraction.Options;
4+
using BotSharp.Abstraction.Settings;
35
using BotSharp.Abstraction.Templating;
46
using System.Collections;
57
using System.Reflection;
@@ -86,9 +88,10 @@ private string BuildInstruction(string instruction, Dictionary<string, object> d
8688

8789
private async Task<RoleDialogModel> GetAiResponse(string text, Agent agent, InstructOptions? options)
8890
{
91+
var settingService = _services.GetRequiredService<ISettingService>();
8992
var dialogs = await BuildDialogs(text, options);
9093
var provider = options?.Provider ?? agent?.LlmConfig?.Provider ?? "openai";
91-
var model = options?.Model ?? agent?.LlmConfig?.Model ?? "gpt-4o";
94+
var model = options?.Model ?? agent?.LlmConfig?.Model ?? settingService.GetUpgradeModel(Gpt4xModelConstants.GPT_4o);
9295
var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model);
9396
return await completion.GetChatCompletions(agent, dialogs);
9497
}

src/Infrastructure/BotSharp.Core/Shared/JsonRepairService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using BotSharp.Abstraction.Models;
2+
using BotSharp.Abstraction.Settings;
13
using BotSharp.Abstraction.Shared;
24
using BotSharp.Abstraction.Shared.Options;
35
using BotSharp.Abstraction.Templating;
@@ -93,12 +95,13 @@ private async Task<string> RepairByLLMAsync(string malformedJson, JsonRepairOpti
9395
var data = options?.Data ?? new Dictionary<string, object>();
9496
data["input"] = malformedJson;
9597
var prompt = render.Render(template, data);
98+
var settingService = _services.GetRequiredService<ISettingService>();
9699

97100
try
98101
{
99102
var completion = CompletionProvider.GetChatCompletion(_services,
100103
provider: options?.Provider ?? agent?.LlmConfig?.Provider ?? "openai",
101-
model: options?.Model ?? agent?.LlmConfig?.Model ?? "gpt-4o-mini");
104+
model: options?.Model ?? agent?.LlmConfig?.Model ?? settingService.GetUpgradeModel(Gpt4xModelConstants.GPT_4o_Mini));
102105

103106
var innerAgent = new Agent
104107
{

src/Infrastructure/BotSharp.Core/WebSearch/Functions/WebIntelligentSearchFn.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using BotSharp.Abstraction.Functions;
22
using BotSharp.Abstraction.MLTasks;
3+
using BotSharp.Abstraction.Models;
4+
using BotSharp.Abstraction.Settings;
35

46
namespace BotSharp.Core.WebSearch.Functions;
57

@@ -70,7 +72,8 @@ private async Task<string> GetChatCompletion(Agent agent, List<RoleDialogModel>
7072
{
7173
var state = _services.GetRequiredService<IConversationStateService>();
7274
var llmProviderService = _services.GetRequiredService<ILlmProviderService>();
73-
75+
var settingService = _services.GetRequiredService<ISettingService>();
76+
7477
var provider = state.GetState("web_search_llm_provider");
7578
var model = state.GetState("web_search_llm_model");
7679

@@ -80,7 +83,7 @@ private async Task<string> GetChatCompletion(Agent agent, List<RoleDialogModel>
8083
}
8184

8285
provider = "openai";
83-
model = "gpt-4o-mini-search-preview";
86+
model = settingService.GetUpgradeModel(Gpt4xModelConstants.GPT_4o_Mini_Search_Preview);
8487

8588
var models = llmProviderService.GetProviderModels(provider);
8689
var foundModel = models.FirstOrDefault(x => x.WebSearch?.IsDefault == true)

0 commit comments

Comments
 (0)