localize setting
This commit is contained in:
parent
e529b36fab
commit
09c008f76f
|
|
@ -24,10 +24,6 @@ public static class BotSharpCoreExtensions
|
|||
{
|
||||
public static IServiceCollection AddBotSharpCore(this IServiceCollection services, IConfiguration config, Action<BotSharpOptions>? configOptions = null)
|
||||
{
|
||||
var interpreterSettings = new InterpreterSettings();
|
||||
config.Bind("Interpreter", interpreterSettings);
|
||||
services.AddSingleton(x => interpreterSettings);
|
||||
|
||||
services.AddSingleton<IDistributedLocker, DistributedLocker>();
|
||||
// Register template render
|
||||
services.AddSingleton<ITemplateRender, TemplateRender>();
|
||||
|
|
|
|||
|
|
@ -14,13 +14,16 @@ public class PyInterpretationFn : IFunctionCallback
|
|||
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly ILogger<PyInterpretationFn> _logger;
|
||||
private readonly PythonInterpreterSettings _settings;
|
||||
|
||||
public PyInterpretationFn(
|
||||
IServiceProvider services,
|
||||
ILogger<PyInterpretationFn> logger)
|
||||
ILogger<PyInterpretationFn> logger,
|
||||
PythonInterpreterSettings settings)
|
||||
{
|
||||
_services = services;
|
||||
_logger = logger;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public async Task<bool> Execute(RoleDialogModel message)
|
||||
|
|
@ -32,7 +35,7 @@ public class PyInterpretationFn : IFunctionCallback
|
|||
var args = JsonSerializer.Deserialize<LlmContextIn>(message.FunctionArgs);
|
||||
|
||||
var agent = await agentService.GetAgent(message.CurrentAgentId);
|
||||
var inst = GetPyCodeGenerationInstruction(message.CurrentAgentId);
|
||||
var inst = GetPyCodeInterpreterInstruction(message.CurrentAgentId);
|
||||
var innerAgent = new Agent
|
||||
{
|
||||
Id = agent.Id,
|
||||
|
|
@ -95,13 +98,13 @@ public class PyInterpretationFn : IFunctionCallback
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var error = $"Error when plotting chart. {ex.Message}";
|
||||
var error = $"Error when generating python code. {ex.Message}";
|
||||
_logger.LogWarning(ex, error);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetPyCodeGenerationInstruction(string agentId)
|
||||
private string GetPyCodeInterpreterInstruction(string agentId)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
|
|
@ -128,10 +131,10 @@ public class PyInterpretationFn : IFunctionCallback
|
|||
var model = "gpt-5";
|
||||
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
provider = state.GetState("py_generator_llm_provider")
|
||||
provider = state.GetState("py_intepreter_llm_provider")
|
||||
//.IfNullOrEmptyAs(_settings.ChartPlot?.LlmProvider)
|
||||
.IfNullOrEmptyAs(provider);
|
||||
model = state.GetState("py_generator_llm_model")
|
||||
model = state.GetState("py_intepreter_llm_model")
|
||||
//.IfNullOrEmptyAs(_settings.ChartPlot?.LlmModel)
|
||||
.IfNullOrEmptyAs(model);
|
||||
|
||||
|
|
@ -144,8 +147,8 @@ public class PyInterpretationFn : IFunctionCallback
|
|||
var reasoningEffortLevel = "minimal";
|
||||
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
maxOutputTokens = int.TryParse(state.GetState("py_generator_max_output_tokens"), out var tokens) ? tokens : maxOutputTokens;
|
||||
reasoningEffortLevel = state.GetState("py_generator_reasoning_effort_level").IfNullOrEmptyAs(reasoningEffortLevel);
|
||||
maxOutputTokens = int.TryParse(state.GetState("py_intepreter_max_output_tokens"), out var tokens) ? tokens : maxOutputTokens;
|
||||
reasoningEffortLevel = state.GetState("py_intepreter_reasoning_effort_level").IfNullOrEmptyAs(reasoningEffortLevel);
|
||||
|
||||
return new AgentLlmConfig
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
namespace BotSharp.Plugin.PythonInterpreter.Hooks;
|
||||
|
||||
public class InterpreterUtilityHook : IAgentUtilityHook
|
||||
public class PythonInterpreterUtilityHook : IAgentUtilityHook
|
||||
{
|
||||
private const string PY_INTERPRETER_FN = "util-code-python_interpreter";
|
||||
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
using BotSharp.Abstraction.Interpreters.Settings;
|
||||
using BotSharp.Abstraction.Settings;
|
||||
using BotSharp.Plugin.PythonInterpreter.Hooks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
|
@ -7,7 +6,7 @@ using System.IO;
|
|||
|
||||
namespace BotSharp.Plugin.PythonInterpreter;
|
||||
|
||||
public class InterpreterPlugin : IBotSharpAppPlugin
|
||||
public class PythonInterpreterPlugin : IBotSharpAppPlugin
|
||||
{
|
||||
public string Id => "23174e08-e866-4173-824a-cf1d97afa8d0";
|
||||
public string Name => "Python Interpreter";
|
||||
|
|
@ -19,26 +18,26 @@ public class InterpreterPlugin : IBotSharpAppPlugin
|
|||
services.AddSingleton(provider =>
|
||||
{
|
||||
var settingService = provider.GetRequiredService<ISettingService>();
|
||||
return settingService.Bind<InterpreterSettings>("Interpreter");
|
||||
return settingService.Bind<PythonInterpreterSettings>("PythonInterpreter");
|
||||
});
|
||||
|
||||
services.AddScoped<IAgentUtilityHook, InterpreterUtilityHook>();
|
||||
services.AddScoped<IAgentUtilityHook, PythonInterpreterUtilityHook>();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var settings = app.ApplicationServices.GetRequiredService<InterpreterSettings>();
|
||||
var settings = app.ApplicationServices.GetRequiredService<PythonInterpreterSettings>();
|
||||
|
||||
// For Python interpreter plugin
|
||||
if (File.Exists(settings.Python.PythonDLL))
|
||||
if (File.Exists(settings.DllLocation))
|
||||
{
|
||||
Runtime.PythonDLL = settings.Python.PythonDLL;
|
||||
Runtime.PythonDLL = settings.DllLocation;
|
||||
PythonEngine.Initialize();
|
||||
PythonEngine.BeginAllowThreads();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serilog.Log.Error("Python DLL found at {PythonDLL}", settings.Python.PythonDLL);
|
||||
Serilog.Log.Error("Python DLL found at {PythonDLL}", settings.DllLocation);
|
||||
}
|
||||
|
||||
// Shut down the Python engine
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
namespace BotSharp.Plugin.PythonInterpreter.Settings;
|
||||
|
||||
public class PythonInterpreterSettings
|
||||
{
|
||||
public string DllLocation { get; set; }
|
||||
}
|
||||
|
|
@ -16,10 +16,9 @@ global using BotSharp.Abstraction.Functions.Models;
|
|||
global using BotSharp.Abstraction.Repositories;
|
||||
global using BotSharp.Abstraction.Conversations.Models;
|
||||
global using BotSharp.Abstraction.Functions;
|
||||
global using BotSharp.Abstraction.Interpreters.Models;
|
||||
|
||||
|
||||
global using BotSharp.Core.Infrastructures;
|
||||
|
||||
global using BotSharp.Plugin.PythonInterpreter.Enums;
|
||||
global using BotSharp.Plugin.PythonInterpreter.LlmContext;
|
||||
global using BotSharp.Plugin.PythonInterpreter.Settings;
|
||||
|
|
|
|||
|
|
@ -564,10 +564,8 @@
|
|||
}
|
||||
},
|
||||
|
||||
"Interpreter": {
|
||||
"Python": {
|
||||
"PythonDLL": "C:/Users/xxx/AppData/Local/Programs/Python/Python311/python311.dll"
|
||||
}
|
||||
"PythonInterpreter": {
|
||||
"DllLocation": "C:/Users/xxx/AppData/Local/Programs/Python/Python313/python313.dll"
|
||||
},
|
||||
|
||||
"RealtimeModel": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue