From a1a2a6f0d374bad4bdd013a1f485a1f06eb4754e Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Wed, 15 Oct 2025 19:33:15 -0500 Subject: [PATCH] rename namespace --- .../CodeInterpreter/ICodeInterpretService.cs | 11 -------- .../CodeProcessors/ICodeProcessor.cs | 12 +++++++++ .../Options}/CodeInterpretOptions.cs | 2 +- .../Responses/CodeInterpretResponse.cs} | 4 +-- ...ProcessOptions.cs => FileHandleOptions.cs} | 2 +- ...IFileLlmProcessor.cs => IFileProcessor.cs} | 4 +-- ...renceResponse.cs => FileHandleResponse.cs} | 2 +- .../Instructs/Options/CodeInstructOptions.cs | 2 +- .../Instructs/Options/FileInstructOptions.cs | 2 +- .../CodeScriptExecutor.cs | 6 ++--- .../Conversations/ConversationPlugin.cs | 4 +-- .../Services/InstructService.Execute.cs | 22 +++++++-------- .../PythonInterpreterPlugin.cs | 2 +- ...terpretService.cs => PyCodeInterpreter.cs} | 27 +++++++++---------- .../Using.cs | 7 ++--- 15 files changed, 53 insertions(+), 56 deletions(-) delete mode 100644 src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/ICodeInterpretService.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/CodeProcessors/ICodeProcessor.cs rename src/Infrastructure/BotSharp.Abstraction/{CodeInterpreter/Models => CodeProcessors/Options}/CodeInterpretOptions.cs (82%) rename src/Infrastructure/BotSharp.Abstraction/{CodeInterpreter/Models/CodeInterpretResult.cs => CodeProcessors/Responses/CodeInterpretResponse.cs} (61%) rename src/Infrastructure/BotSharp.Abstraction/Files/Options/{FileLlmProcessOptions.cs => FileHandleOptions.cs} (96%) rename src/Infrastructure/BotSharp.Abstraction/Files/Proccessors/{IFileLlmProcessor.cs => IFileProcessor.cs} (53%) rename src/Infrastructure/BotSharp.Abstraction/Files/Responses/{FileLlmInferenceResponse.cs => FileHandleResponse.cs} (83%) rename src/Infrastructure/BotSharp.Core/{CodeInterpreter => Coding}/CodeScriptExecutor.cs (76%) rename src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/{PyInterpretService.cs => PyCodeInterpreter.cs} (79%) diff --git a/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/ICodeInterpretService.cs b/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/ICodeInterpretService.cs deleted file mode 100644 index bdc10f5c..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/ICodeInterpretService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BotSharp.Abstraction.CodeInterpreter.Models; - -namespace BotSharp.Abstraction.CodeInterpreter; - -public interface ICodeInterpretService -{ - string Provider { get; } - - Task RunCode(string codeScript, CodeInterpretOptions? options = null) - => throw new NotImplementedException(); -} diff --git a/src/Infrastructure/BotSharp.Abstraction/CodeProcessors/ICodeProcessor.cs b/src/Infrastructure/BotSharp.Abstraction/CodeProcessors/ICodeProcessor.cs new file mode 100644 index 00000000..1fe083f0 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/CodeProcessors/ICodeProcessor.cs @@ -0,0 +1,12 @@ +using BotSharp.Abstraction.Coding.Options; +using BotSharp.Abstraction.Coding.Responses; + +namespace BotSharp.Abstraction.Coding; + +public interface ICodeProcessor +{ + string Provider { get; } + + Task RunAsync(string codeScript, CodeInterpretOptions? options = null) + => throw new NotImplementedException(); +} diff --git a/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretOptions.cs b/src/Infrastructure/BotSharp.Abstraction/CodeProcessors/Options/CodeInterpretOptions.cs similarity index 82% rename from src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretOptions.cs rename to src/Infrastructure/BotSharp.Abstraction/CodeProcessors/Options/CodeInterpretOptions.cs index 0e8953be..b563b03d 100644 --- a/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretOptions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/CodeProcessors/Options/CodeInterpretOptions.cs @@ -1,6 +1,6 @@ using System.Threading; -namespace BotSharp.Abstraction.CodeInterpreter.Models; +namespace BotSharp.Abstraction.Coding.Options; public class CodeInterpretOptions { diff --git a/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretResult.cs b/src/Infrastructure/BotSharp.Abstraction/CodeProcessors/Responses/CodeInterpretResponse.cs similarity index 61% rename from src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretResult.cs rename to src/Infrastructure/BotSharp.Abstraction/CodeProcessors/Responses/CodeInterpretResponse.cs index 2958cca8..a07c7a1f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretResult.cs +++ b/src/Infrastructure/BotSharp.Abstraction/CodeProcessors/Responses/CodeInterpretResponse.cs @@ -1,6 +1,6 @@ -namespace BotSharp.Abstraction.CodeInterpreter.Models; +namespace BotSharp.Abstraction.Coding.Responses; -public class CodeInterpretResult +public class CodeInterpretResponse { public string Result { get; set; } = string.Empty; public bool Success { get; set; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/Options/FileLlmProcessOptions.cs b/src/Infrastructure/BotSharp.Abstraction/Files/Options/FileHandleOptions.cs similarity index 96% rename from src/Infrastructure/BotSharp.Abstraction/Files/Options/FileLlmProcessOptions.cs rename to src/Infrastructure/BotSharp.Abstraction/Files/Options/FileHandleOptions.cs index eafae504..31a2ab46 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Files/Options/FileLlmProcessOptions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Files/Options/FileHandleOptions.cs @@ -1,6 +1,6 @@ namespace BotSharp.Abstraction.Files.Options; -public class FileLlmProcessOptions +public class FileHandleOptions { /// /// Llm provider diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/Proccessors/IFileLlmProcessor.cs b/src/Infrastructure/BotSharp.Abstraction/Files/Proccessors/IFileProcessor.cs similarity index 53% rename from src/Infrastructure/BotSharp.Abstraction/Files/Proccessors/IFileLlmProcessor.cs rename to src/Infrastructure/BotSharp.Abstraction/Files/Proccessors/IFileProcessor.cs index ebc05792..19ab437c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Files/Proccessors/IFileLlmProcessor.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Files/Proccessors/IFileProcessor.cs @@ -3,10 +3,10 @@ using BotSharp.Abstraction.Files.Responses; namespace BotSharp.Abstraction.Files.Proccessors; -public interface IFileLlmProcessor +public interface IFileProcessor { public string Provider { get; } - Task GetFileLlmInferenceAsync(Agent agent, string text, IEnumerable files, FileLlmProcessOptions? options = null) + Task HandleFilesAsync(Agent agent, string text, IEnumerable files, FileHandleOptions? options = null) => throw new NotImplementedException(); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/Responses/FileLlmInferenceResponse.cs b/src/Infrastructure/BotSharp.Abstraction/Files/Responses/FileHandleResponse.cs similarity index 83% rename from src/Infrastructure/BotSharp.Abstraction/Files/Responses/FileLlmInferenceResponse.cs rename to src/Infrastructure/BotSharp.Abstraction/Files/Responses/FileHandleResponse.cs index fa11b1f9..6957ed0f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Files/Responses/FileLlmInferenceResponse.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Files/Responses/FileHandleResponse.cs @@ -1,6 +1,6 @@ namespace BotSharp.Abstraction.Files.Responses; -public class FileLlmInferenceResponse +public class FileHandleResponse { public string Result { get; set; } = string.Empty; public bool Success { get; set; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Instructs/Options/CodeInstructOptions.cs b/src/Infrastructure/BotSharp.Abstraction/Instructs/Options/CodeInstructOptions.cs index e4081609..89684cfd 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Instructs/Options/CodeInstructOptions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Instructs/Options/CodeInstructOptions.cs @@ -2,7 +2,7 @@ namespace BotSharp.Abstraction.Instructs.Options; public class CodeInstructOptions { + public string? Processor { get; set; } public string? CodeScriptName { get; set; } - public string? CodeInterpretProvider { get; set; } public List? Arguments { get; set; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Instructs/Options/FileInstructOptions.cs b/src/Infrastructure/BotSharp.Abstraction/Instructs/Options/FileInstructOptions.cs index a4f3a858..bb575f49 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Instructs/Options/FileInstructOptions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Instructs/Options/FileInstructOptions.cs @@ -2,5 +2,5 @@ namespace BotSharp.Abstraction.Instructs.Options; public class FileInstructOptions { - public string? FileLlmProcessorProvider { get; set; } + public string? Processor { get; set; } } diff --git a/src/Infrastructure/BotSharp.Core/CodeInterpreter/CodeScriptExecutor.cs b/src/Infrastructure/BotSharp.Core/Coding/CodeScriptExecutor.cs similarity index 76% rename from src/Infrastructure/BotSharp.Core/CodeInterpreter/CodeScriptExecutor.cs rename to src/Infrastructure/BotSharp.Core/Coding/CodeScriptExecutor.cs index 0fea0fa1..bc38416d 100644 --- a/src/Infrastructure/BotSharp.Core/CodeInterpreter/CodeScriptExecutor.cs +++ b/src/Infrastructure/BotSharp.Core/Coding/CodeScriptExecutor.cs @@ -1,6 +1,4 @@ -using BotSharp.Abstraction.CodeInterpreter.Models; - -namespace BotSharp.Core.CodeInterpreter; +namespace BotSharp.Core.Coding; public class CodeScriptExecutor { @@ -13,7 +11,7 @@ public class CodeScriptExecutor _logger = logger; } - public async Task Execute(Func> func, CancellationToken cancellationToken = default) + public async Task ExecuteAsync(Func> func, CancellationToken cancellationToken = default) { await _semLock.WaitAsync(cancellationToken); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs b/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs index 798fe307..e1c44a9a 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs @@ -1,6 +1,5 @@ using BotSharp.Abstraction.Google.Settings; using BotSharp.Abstraction.Instructs; -using BotSharp.Abstraction.MessageHub; using BotSharp.Abstraction.MessageHub.Observers; using BotSharp.Abstraction.MessageHub.Services; using BotSharp.Abstraction.Messaging; @@ -8,7 +7,7 @@ using BotSharp.Abstraction.Planning; using BotSharp.Abstraction.Plugins.Models; using BotSharp.Abstraction.Settings; using BotSharp.Abstraction.Templating; -using BotSharp.Core.CodeInterpreter; +using BotSharp.Core.Coding; using BotSharp.Core.Instructs; using BotSharp.Core.MessageHub; using BotSharp.Core.MessageHub.Observers; @@ -18,7 +17,6 @@ using BotSharp.Core.Routing.Reasoning; using BotSharp.Core.Templating; using BotSharp.Core.Translation; using BotSharp.Core.WebSearch.Hooks; -using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; namespace BotSharp.Core.Conversations; diff --git a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs index 267f4633..a3db6db1 100644 --- a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs +++ b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs @@ -1,4 +1,4 @@ -using BotSharp.Abstraction.CodeInterpreter; +using BotSharp.Abstraction.Coding; using BotSharp.Abstraction.Files.Options; using BotSharp.Abstraction.Files.Proccessors; using BotSharp.Abstraction.Instructs; @@ -47,7 +47,7 @@ public partial class InstructService // Run code template - var codeResponse = await GetCodeResponse(agent, message, templateName, codeOptions); + var codeResponse = await RunCode(agent, message, templateName, codeOptions); if (codeResponse != null) { return codeResponse; @@ -105,16 +105,16 @@ public partial class InstructService prompt = message.Content; } - IFileLlmProcessor? fileProcessor = null; + IFileProcessor? fileProcessor = null; if (!files.IsNullOrEmpty() && fileOptions != null) { - fileProcessor = _services.GetServices() - .FirstOrDefault(x => x.Provider.IsEqualTo(fileOptions.FileLlmProcessorProvider)); + fileProcessor = _services.GetServices() + .FirstOrDefault(x => x.Provider.IsEqualTo(fileOptions.Processor)); } if (fileProcessor != null) { - var inference = await fileProcessor.GetFileLlmInferenceAsync(agent, prompt, files, new FileLlmProcessOptions + var fileResponse = await fileProcessor.HandleFilesAsync(agent, prompt, files, new FileHandleOptions { Provider = provider, Model = model, @@ -124,7 +124,7 @@ public partial class InstructService InvokeFrom = $"{nameof(InstructService)}.{nameof(Execute)}", Data = state.GetStates().ToDictionary(x => x.Key, x => (object)x.Value) }); - result = inference.Result.IfNullOrEmptyAs(string.Empty); + result = fileResponse.Result.IfNullOrEmptyAs(string.Empty); } else { @@ -160,7 +160,7 @@ public partial class InstructService /// /// /// - private async Task GetCodeResponse( + private async Task RunCode( Agent agent, RoleDialogModel message, string templateName, @@ -177,8 +177,8 @@ public partial class InstructService var state = _services.GetRequiredService(); var hooks = _services.GetHooks(agent.Id); - var codeProvider = codeOptions?.CodeInterpretProvider ?? "botsharp-py-interpreter"; - var codeInterpreter = _services.GetServices() + var codeProvider = codeOptions?.Processor ?? "botsharp-py-interpreter"; + var codeInterpreter = _services.GetServices() .FirstOrDefault(x => x.Provider.IsEqualTo(codeProvider)); if (codeInterpreter == null) @@ -248,7 +248,7 @@ public partial class InstructService } // Run code script - var result = await codeInterpreter.RunCode(context.CodeScript, options: new() + var result = await codeInterpreter.RunAsync(context.CodeScript, options: new() { ScriptName = scriptName, Arguments = context.Arguments diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/PythonInterpreterPlugin.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/PythonInterpreterPlugin.cs index bee046e5..a56a9e44 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/PythonInterpreterPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/PythonInterpreterPlugin.cs @@ -22,7 +22,7 @@ public class PythonInterpreterPlugin : IBotSharpAppPlugin services.AddSingleton(x => settings); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); } public void Configure(IApplicationBuilder app) diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyCodeInterpreter.cs similarity index 79% rename from src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs rename to src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyCodeInterpreter.cs index 46ed2e47..76bd6fe6 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyCodeInterpreter.cs @@ -1,4 +1,3 @@ -using BotSharp.Core.CodeInterpreter; using Microsoft.Extensions.Logging; using Python.Runtime; using System.Threading; @@ -6,15 +5,15 @@ using System.Threading.Tasks; namespace BotSharp.Plugin.PythonInterpreter.Services; -public class PyInterpretService : ICodeInterpretService +public class PyCodeInterpreter : ICodeProcessor { private readonly IServiceProvider _services; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly CodeScriptExecutor _executor; - public PyInterpretService( + public PyCodeInterpreter( IServiceProvider services, - ILogger logger, + ILogger logger, CodeScriptExecutor executor) { _services = services; @@ -24,11 +23,11 @@ public class PyInterpretService : ICodeInterpretService public string Provider => "botsharp-py-interpreter"; - public async Task RunCode(string codeScript, CodeInterpretOptions? options = null) + public async Task RunAsync(string codeScript, CodeInterpretOptions? options = null) { if (options?.UseMutex == true) { - return await _executor.Execute(async () => + return await _executor.ExecuteAsync(async () => { return InnerRunCode(codeScript, options); }, cancellationToken: options?.CancellationToken ?? CancellationToken.None); @@ -36,7 +35,7 @@ public class PyInterpretService : ICodeInterpretService return InnerRunCode(codeScript, options); } - private CodeInterpretResult InnerRunCode(string codeScript, CodeInterpretOptions? options = null) + private CodeInterpretResponse InnerRunCode(string codeScript, CodeInterpretOptions? options = null) { try { @@ -44,10 +43,10 @@ public class PyInterpretService : ICodeInterpretService } catch (Exception ex) { - var errorMsg = $"Error when executing inner python code in {nameof(PyInterpretService)}: {Provider}."; + var errorMsg = $"Error when executing inner python code in {nameof(PyCodeInterpreter)}: {Provider}."; _logger.LogError(ex, errorMsg); - return new CodeInterpretResult + return new CodeInterpretResponse { Success = false, ErrorMsg = errorMsg @@ -55,7 +54,7 @@ public class PyInterpretService : ICodeInterpretService } } - private CodeInterpretResult CoreRun(string codeScript, CodeInterpretOptions? options = null) + private CodeInterpretResponse CoreRun(string codeScript, CodeInterpretOptions? options = null) { using (Py.GIL()) { @@ -100,7 +99,7 @@ public class PyInterpretService : ICodeInterpretService // Get result var result = stringIO.getvalue()?.ToString() as string; - return new CodeInterpretResult + return new CodeInterpretResponse { Result = result?.TrimEnd('\r', '\n'), Success = true @@ -108,10 +107,10 @@ public class PyInterpretService : ICodeInterpretService } catch (Exception ex) { - var errorMsg = $"Error when executing core python code in {nameof(PyInterpretService)}: {Provider}. {ex.Message}"; + var errorMsg = $"Error when executing core python code in {nameof(PyCodeInterpreter)}: {Provider}. {ex.Message}"; _logger.LogError(ex, errorMsg); - return new CodeInterpretResult + return new CodeInterpretResponse { Success = false, ErrorMsg = errorMsg diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Using.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Using.cs index 11a023fe..bd2c943b 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Using.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Using.cs @@ -20,9 +20,10 @@ global using BotSharp.Abstraction.Messaging; global using BotSharp.Abstraction.Messaging.Models.RichContent; global using BotSharp.Abstraction.Messaging.Models.RichContent.Template; global using BotSharp.Abstraction.Routing; -global using BotSharp.Abstraction.CodeInterpreter.Models; -global using BotSharp.Abstraction.CodeInterpreter; - +global using BotSharp.Abstraction.Coding; +global using BotSharp.Abstraction.Coding.Options; +global using BotSharp.Abstraction.Coding.Responses; +global using BotSharp.Core.Coding; global using BotSharp.Core.Infrastructures; global using BotSharp.Plugin.PythonInterpreter.Enums;