From 13e9ef0067e94772bed854afa058fd88f55aab92 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Fri, 23 Aug 2024 10:15:58 -0500 Subject: [PATCH] fix python settings. --- .../Interpreters/Settings/InterpreterSettings.cs | 11 +++++++++++ .../BotSharp.Core/BotSharpCoreExtensions.cs | 7 +++++++ src/WebStarter/Program.cs | 10 +--------- src/WebStarter/appsettings.json | 6 ++++++ 4 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Interpreters/Settings/InterpreterSettings.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Interpreters/Settings/InterpreterSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Interpreters/Settings/InterpreterSettings.cs new file mode 100644 index 00000000..e6ea6cf3 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Interpreters/Settings/InterpreterSettings.cs @@ -0,0 +1,11 @@ +namespace BotSharp.Abstraction.Interpreters.Settings; + +public class InterpreterSettings +{ + public PythonInterpreterSetting Python { get; set; } +} + +public class PythonInterpreterSetting +{ + public string PythonDLL { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs b/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs index 61c45c58..c9cb8463 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs +++ b/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs @@ -6,6 +6,7 @@ using BotSharp.Abstraction.Settings; using BotSharp.Abstraction.Options; using BotSharp.Abstraction.Messaging.JsonConverters; using BotSharp.Abstraction.Users.Settings; +using BotSharp.Abstraction.Interpreters.Settings; namespace BotSharp.Core; @@ -13,6 +14,12 @@ public static class BotSharpCoreExtensions { public static IServiceCollection AddBotSharpCore(this IServiceCollection services, IConfiguration config, Action? configOptions = null) { + var interpreterSettings = new InterpreterSettings(); + config.Bind("Interpreter", interpreterSettings); + services.AddSingleton(x => interpreterSettings); + + services.AddSingleton(); + services.AddScoped(); services.AddScoped(); services.AddSingleton(); diff --git a/src/WebStarter/Program.cs b/src/WebStarter/Program.cs index a13d9d0f..e6daf9c1 100644 --- a/src/WebStarter/Program.cs +++ b/src/WebStarter/Program.cs @@ -4,7 +4,6 @@ using BotSharp.Logger; using BotSharp.Plugin.ChatHub; using Serilog; using BotSharp.Abstraction.Messaging.JsonConverters; -using Python.Runtime; var builder = WebApplication.CreateBuilder(args); @@ -42,11 +41,4 @@ app.UseBotSharp() .UseBotSharpOpenAPI(app.Environment) .UseBotSharpUI(); -Runtime.PythonDLL = @"C:\Users\xxx\AppData\Local\Programs\Python\Python311\python311.dll"; -PythonEngine.Initialize(); -PythonEngine.BeginAllowThreads(); - -app.Run(); - -// Shut down the Python engine -PythonEngine.Shutdown(); \ No newline at end of file +app.Run(); \ No newline at end of file diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index 68548aa5..2c634959 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -299,6 +299,12 @@ } }, + "Interpreter": { + "Python": { + "PythonDLL": "C:/Users/xxx/AppData/Local/Programs/Python/Python311/python311.dll" + } + }, + "PluginLoader": { "Assemblies": [ "BotSharp.Core",