Skip to content

Commit ebf3410

Browse files
authored
Merge pull request #1139 from iceljc/master
add chart handler setting
2 parents 5d875d0 + 2d9de9c commit ebf3410

File tree

6 files changed

+47
-5
lines changed

6 files changed

+47
-5
lines changed

src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace BotSharp.Abstraction.Utilities;
55

66
public static class StringExtensions
77
{
8-
public static string IfNullOrEmptyAs(this string? str, string defaultValue)
8+
public static string? IfNullOrEmptyAs(this string? str, string? defaultValue)
99
=> string.IsNullOrEmpty(str) ? defaultValue : str;
1010

1111
public static string SubstringMax(this string str, int maxLength)

src/Plugins/BotSharp.Plugin.ChartHandler/ChartHandlerPlugin.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ public class ChartHandlerPlugin : IBotSharpPlugin
1212

1313
public void RegisterDI(IServiceCollection services, IConfiguration config)
1414
{
15+
services.AddScoped(provider =>
16+
{
17+
var settingService = provider.GetRequiredService<ISettingService>();
18+
return settingService.Bind<ChartHandlerSettings>("ChartHandler");
19+
});
20+
1521
services.AddScoped<IAgentUtilityHook, ChartHandlerUtilityHook>();
1622
}
17-
1823
}

src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ private async Task<string> GetChatCompletion(Agent agent, List<RoleDialogModel>
6767
{
6868
try
6969
{
70-
var llmProviderService = _services.GetRequiredService<ILlmProviderService>();
71-
var completion = CompletionProvider.GetChatCompletion(_services, provider: "openai", model: "gpt-4.1");
70+
var (provider, model) = GetLlmProviderModel();
71+
var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model);
7272
var response = await completion.GetChatCompletions(agent, dialogs);
7373
return response.Content;
7474
}
@@ -79,4 +79,21 @@ private async Task<string> GetChatCompletion(Agent agent, List<RoleDialogModel>
7979
return error;
8080
}
8181
}
82+
83+
private (string, string) GetLlmProviderModel()
84+
{
85+
var provider = "openai";
86+
var model = "gpt-5";
87+
88+
var state = _services.GetRequiredService<IConversationStateService>();
89+
var settings = _services.GetRequiredService<ChartHandlerSettings>();
90+
provider = state.GetState("chart_plot_llm_provider")
91+
.IfNullOrEmptyAs(settings.ChartPlot?.LlmProvider)
92+
.IfNullOrEmptyAs(provider);
93+
model = state.GetState("chart_plot_llm_model")
94+
.IfNullOrEmptyAs(settings.ChartPlot?.LlmModel)
95+
.IfNullOrEmptyAs(model);
96+
97+
return (provider, model);
98+
}
8299
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace BotSharp.Plugin.ChartHandler.Settings;
2+
3+
public class ChartHandlerSettings
4+
{
5+
public ChartPlotSetting ChartPlot { get; set; }
6+
}
7+
8+
public class ChartPlotSetting
9+
{
10+
public string LlmProvider { get; set; }
11+
public string LlmModel { get; set; }
12+
}

src/Plugins/BotSharp.Plugin.ChartHandler/Using.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
global using BotSharp.Core.Infrastructures;
3030
global using BotSharp.Plugin.ChartHandler.Enums;
3131
global using BotSharp.Plugin.ChartHandler.LlmContext;
32-
global using BotSharp.Plugin.ChartHandler.Hooks;
32+
global using BotSharp.Plugin.ChartHandler.Hooks;
33+
global using BotSharp.Plugin.ChartHandler.Settings;

src/WebStarter/appsettings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@
317317
"Origin": ""
318318
},
319319

320+
"ChartHandler": {
321+
"ChartPlot": {
322+
"LlmProvider": "openai",
323+
"LlmModel": "gpt-5"
324+
}
325+
},
326+
320327
"SqlDriver": {
321328
"MySqlConnectionString": "",
322329
"SqlServerConnectionString": "",

0 commit comments

Comments
 (0)