add chart handler setting
This commit is contained in:
parent
5d875d075e
commit
d01c15b546
|
|
@ -5,7 +5,7 @@ namespace BotSharp.Abstraction.Utilities;
|
|||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static string IfNullOrEmptyAs(this string? str, string defaultValue)
|
||||
public static string? IfNullOrEmptyAs(this string? str, string? defaultValue)
|
||||
=> string.IsNullOrEmpty(str) ? defaultValue : str;
|
||||
|
||||
public static string SubstringMax(this string str, int maxLength)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,12 @@ public class ChartHandlerPlugin : IBotSharpPlugin
|
|||
|
||||
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
services.AddScoped(provider =>
|
||||
{
|
||||
var settingService = provider.GetRequiredService<ISettingService>();
|
||||
return settingService.Bind<ChartHandlerSettings>("ChartHandler");
|
||||
});
|
||||
|
||||
services.AddScoped<IAgentUtilityHook, ChartHandlerUtilityHook>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ public class PlotChartFn : IFunctionCallback
|
|||
{
|
||||
try
|
||||
{
|
||||
var llmProviderService = _services.GetRequiredService<ILlmProviderService>();
|
||||
var completion = CompletionProvider.GetChatCompletion(_services, provider: "openai", model: "gpt-4.1");
|
||||
var (provider, model) = GetLlmProviderModel();
|
||||
var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model);
|
||||
var response = await completion.GetChatCompletions(agent, dialogs);
|
||||
return response.Content;
|
||||
}
|
||||
|
|
@ -79,4 +79,21 @@ public class PlotChartFn : IFunctionCallback
|
|||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
private (string, string) GetLlmProviderModel()
|
||||
{
|
||||
var provider = "openai";
|
||||
var model = "gpt-5";
|
||||
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
var settings = _services.GetRequiredService<ChartHandlerSettings>();
|
||||
provider = state.GetState("chart_plot_llm_provider")
|
||||
.IfNullOrEmptyAs(settings.ChartPlot?.LlmProvider)
|
||||
.IfNullOrEmptyAs(provider);
|
||||
model = state.GetState("chart_plot_llm_model")
|
||||
.IfNullOrEmptyAs(settings.ChartPlot?.LlmModel)
|
||||
.IfNullOrEmptyAs(model);
|
||||
|
||||
return (provider, model);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
namespace BotSharp.Plugin.ChartHandler.Settings;
|
||||
|
||||
public class ChartHandlerSettings
|
||||
{
|
||||
public ChartPlotSetting ChartPlot { get; set; }
|
||||
}
|
||||
|
||||
public class ChartPlotSetting
|
||||
{
|
||||
public string LlmProvider { get; set; }
|
||||
public string LlmModel { get; set; }
|
||||
}
|
||||
|
|
@ -29,4 +29,5 @@ global using BotSharp.Abstraction.Options;
|
|||
global using BotSharp.Core.Infrastructures;
|
||||
global using BotSharp.Plugin.ChartHandler.Enums;
|
||||
global using BotSharp.Plugin.ChartHandler.LlmContext;
|
||||
global using BotSharp.Plugin.ChartHandler.Hooks;
|
||||
global using BotSharp.Plugin.ChartHandler.Hooks;
|
||||
global using BotSharp.Plugin.ChartHandler.Settings;
|
||||
|
|
@ -317,6 +317,13 @@
|
|||
"Origin": ""
|
||||
},
|
||||
|
||||
"ChartHandler": {
|
||||
"ChartPlot": {
|
||||
"LlmProvider": "",
|
||||
"LlmModel": ""
|
||||
}
|
||||
},
|
||||
|
||||
"SqlDriver": {
|
||||
"MySqlConnectionString": "",
|
||||
"SqlServerConnectionString": "",
|
||||
|
|
|
|||
Loading…
Reference in a new issue