From a5bf44a44ad84ca30ed3ad00ca42d2612c031e3f Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Mon, 29 Sep 2025 15:34:52 -0500 Subject: [PATCH] rename --- .../PythonInterpreterPlugin.cs | 37 ++++++++++++------- .../Settings/PythonInterpreterSettings.cs | 5 ++- .../Using.cs | 2 + .../util-code-python_programmer.json | 2 +- src/WebStarter/appsettings.json | 2 +- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/PythonInterpreterPlugin.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/PythonInterpreterPlugin.cs index ed55ae4c..14ae5dc2 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/PythonInterpreterPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/PythonInterpreterPlugin.cs @@ -1,6 +1,6 @@ -using BotSharp.Plugin.PythonInterpreter.Hooks; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using Python.Runtime; using System.IO; @@ -26,24 +26,33 @@ public class PythonInterpreterPlugin : IBotSharpAppPlugin public void Configure(IApplicationBuilder app) { - var settings = app.ApplicationServices.GetRequiredService(); + var sp = app.ApplicationServices; + var settings = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var pyLoc = settings.InstallLocation; - // For Python interpreter plugin - if (File.Exists(settings.DllLocation)) + try { - Runtime.PythonDLL = settings.DllLocation; - PythonEngine.Initialize(); - _pyState = PythonEngine.BeginAllowThreads(); + if (File.Exists(pyLoc)) + { + Runtime.PythonDLL = pyLoc; + PythonEngine.Initialize(); + _pyState = PythonEngine.BeginAllowThreads(); - var lifetime = app.ApplicationServices.GetRequiredService(); - lifetime.ApplicationStopping.Register(() => { - PythonEngine.EndAllowThreads(_pyState); - PythonEngine.Shutdown(); - }); + var lifetime = app.ApplicationServices.GetRequiredService(); + lifetime.ApplicationStopping.Register(() => { + PythonEngine.EndAllowThreads(_pyState); + PythonEngine.Shutdown(); + }); + } + else + { + logger.LogError($"Python dll not found at {pyLoc}"); + } } - else + catch (Exception ex) { - Serilog.Log.Error($"Python DLL found at {settings.DllLocation}"); + logger.LogError(ex, $"Error when loading python dll {pyLoc}"); } } } diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Settings/PythonInterpreterSettings.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Settings/PythonInterpreterSettings.cs index 7e380ba1..8fa79dc8 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Settings/PythonInterpreterSettings.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Settings/PythonInterpreterSettings.cs @@ -4,7 +4,10 @@ namespace BotSharp.Plugin.PythonInterpreter.Settings; public class PythonInterpreterSettings { - public string DllLocation { get; set; } + /// + /// Python installation path to .dll or .so + /// + public string InstallLocation { get; set; } public string PythonVersion { get; set; } public CodeGenerationSetting? CodeGeneration { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Using.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Using.cs index 84bac034..bf94142e 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Using.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Using.cs @@ -26,3 +26,5 @@ global using BotSharp.Core.Infrastructures; global using BotSharp.Plugin.PythonInterpreter.Enums; global using BotSharp.Plugin.PythonInterpreter.LlmContext; global using BotSharp.Plugin.PythonInterpreter.Settings; +global using BotSharp.Plugin.PythonInterpreter.Functions; +global using BotSharp.Plugin.PythonInterpreter.Hooks; diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-code-python_programmer.json b/src/Plugins/BotSharp.Plugin.PythonInterpreter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-code-python_programmer.json index c9aabc20..80064bc8 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-code-python_programmer.json +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-code-python_programmer.json @@ -1,5 +1,5 @@ { - "name": "util-code-python_interpreter", + "name": "util-code-python_programmer", "description": "If user's requirement can be fulfilled by python code, you can call this function to generate python code to execute.", "parameters": { "type": "object", diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index 65b78111..415662d0 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -566,7 +566,7 @@ }, "PythonInterpreter": { - "DllLocation": "C:/Users/xxx/AppData/Local/Programs/Python/Python313/python313.dll", + "InstallLocation": "C:/Users/xxx/AppData/Local/Programs/Python/Python313/python313.dll", "PythonVersion": "3.13", "CodeGeneration": { "LlmProvider": "openai",