From 333807ceb7396f8c8dcc093fca1a72cb2baa4883 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 8 Oct 2025 15:25:53 -0500 Subject: [PATCH] revert --- .../CodeInterpreter/Models/CodeInterpretOptions.cs | 1 + .../codes/src/demo.py | 9 +++++++-- .../Services/PyInterpretService.cs | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretOptions.cs b/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretOptions.cs index 2c4e0fc9..0e8953be 100644 --- a/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretOptions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretOptions.cs @@ -6,5 +6,6 @@ public class CodeInterpretOptions { public string? ScriptName { get; set; } public IEnumerable? Arguments { get; set; } + public bool UseMutex { get; set; } public CancellationToken? CancellationToken { get; set; } } diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/codes/src/demo.py b/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/codes/src/demo.py index 438a6a87..5b29f4b2 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/codes/src/demo.py +++ b/src/Infrastructure/BotSharp.Core/data/agents/01e2fc5c-2c89-4ec7-8470-7688608b496c/codes/src/demo.py @@ -1,12 +1,17 @@ import argparse +import json def main(): parser = argparse.ArgumentParser(description="Receive named arguments") parser.add_argument("--first_name", required=True, help="The first name") parser.add_argument("--last_name", required=True, help="The last name") - args = parser.parse_args() - print(f"Hello, {args.first_name} {args.last_name}!") + args, _ = parser.parse_known_args() + obj = { + "first_name": args.first_name, + "last_name":args.last_name + } + print(f"{json.dumps(obj)}") if __name__ == "__main__": main() \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs index f5688027..9041126b 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs @@ -1,6 +1,7 @@ using BotSharp.Core.CodeInterpreter; using Microsoft.Extensions.Logging; using Python.Runtime; +using System.Threading; using System.Threading.Tasks; namespace BotSharp.Plugin.PythonInterpreter.Services; @@ -25,6 +26,13 @@ public class PyInterpretService : ICodeInterpretService public async Task RunCode(string codeScript, CodeInterpretOptions? options = null) { + if (options?.UseMutex == true) + { + return await _executor.Execute(async () => + { + return InnerRunCode(codeScript, options); + }, cancellationToken: options?.CancellationToken ?? CancellationToken.None); + } return InnerRunCode(codeScript, options); }